import React from 'react';
import { Text, View } from 'react-native';
import MeasureText from 'react-native-measure-text';
export default class App extends React.Component {
render() {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<MeasureText
text={"测试文本"}
fontSize={16}
fontFamily={'Arial'}
onMeasure={(width, height) => {
console.log('文本宽度:', width);
console.log('文本高度:', height);
}}
/>
</View>
);
}
}
这段代码演示了如何在React Native应用中使用react-native-measure-text
插件来测量文本的宽度和高度。开发者可以根据测量结果调整文本显示或布局。