RN根据产品要求,需要实现用户设置字体大小来展示前端页面;

1.定义一个font.js

const appSize = {
 themes1: { font12: 12, font14: 14, font24: 24, },
themes2: { font12: 22, font14: 24, font24: 34, },
themes3: { font12: 32, font14: 44, font24: 54, },
} export default appSize; 

2.在需要用到的页面引用

import themes from "../common/font";

3.设置字体大小时存入stroage里面,并在componentWillMount中判断;例如:(我采用了本地存储的方法,大家可以采用自己定义的方法)

const fontType = new DataRepository().fetchLocalRepository('sizeFont');
fontType.then(res=> {
  if (res) {
    this.setState({ fontThemes: res })
  }
})

4.用的时候直接用

<Text style = {[styles.listText,
              {fontSize: themes[this.state.fontThemes]['font12']}
]} >
{info.item.title}
</Text>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。