模板版本:v0.2.2
react-native-responsive-fontsize
[Github 地址](https://github.com/heyman333/react-native-responsive-fontSize)
| 三方库版本 | 支持RN版本 |
|---|---|
| 0.5.1 | 0.72/0.77 |
安装与使用
进入到工程目录并输入以下命令:
npm
npm install react-native-responsive-fontsize@0.5.1
yarn
yarn add react-native-responsive-fontsize@0.5.1
下面的代码展示了这个库的基本使用场景:
import { RFPercentage, RFValue } from "react-native-responsive-fontsize";
import { View, Text, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
welcome: {
fontSize: RFValue(24, 580),
textAlign: "center",
margin: 10,
},
instructions: {
textAlign: "center",
margin: 10,
fontSize: RFPercentage(5),
},
});
const App = () => {
return (
<View style={{ height: '100%', width: '100%', backgroundColor: '#ffffff',marginTop:50}}>
<View style={{ height: 200 }}>
<Text>fontSize used RFValue(24, 580):</Text>
<Text style={styles.welcome}>Hello World1</Text>
</View>
<View style={{ height: 200 }}>
<Text>fontSize used RFPercentage(5):</Text>
<Text style={styles.instructions}>Hello World2</Text>
</View>
</View>
)
}
export default App;
约束与限制
兼容性
本文档内容基于以下版本验证通过:
- RNOH:0.72.27; SDK:HarmonyOS-NEXT-DB1 5.0.0.25; IDE:DevEco Studio 5.0.3.400SP7; ROM:3.0.0.25;
- RNOH:0.72.33; SDK:OpenHarmony 5.0.0.71(API Version 12 Release); IDE:DevEco Studio 5.0.3.900; ROM:NEXT.0.0.71;
- RNOH:0.77.18; SDK:HarmonyOS 6.0.0.47 (API Version 20); IDE:DevEco Studio 6.0.0.858; ROM:6.0.0.107;
静态方法
"Platform"列表示该属性在原三方库上支持的平台。
"HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|---|---|---|---|---|---|
| RFPercentage | 字体大小按设备高度(横屏模式下为宽度)的百分比计算。 |
function | no | Android/iOS | yes |
| RFValue | 字体大小基于标准屏幕高度和传入的值计算 | function | no | Android/iOS | yes |
RFPercentage参数
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|---|---|---|---|---|---|
| percent | 字体大小 | number | yes | Android/iOS | yes |
RFValue参数
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|---|---|---|---|---|---|
| value | 字体大小 | number | yes | Android/iOS | yes |
| standardScreenHeight | 标准屏幕高度 | number | no | Android/iOS | yes |
遗留问题
其他
开源协议
本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。