2018-12-18 实现TextInput子类的问题

我尝试写了写TextInput的子类,来统一修改字体,但是改变不了props.style里的fontSize,记录下,先看每个TextInput单独设置写。

import {TextInput} from 'react-native';


export default class AppTextInput extends TextInput {

    constructor(props) {
        super(props);
    }

    hasTriggleFontSizeChange = false;

    realFontSize = 12;

    componentWillMount() {


        var tempStyle = this.props.style;

        if (!this.hasTriggleFontSizeChange) {
            this.hasTriggleFontSizeChange = true;

            var tempFontSize = 6;

            if (tempStyle.hasOwnProperty('fontSize')) {
                tempFontSize = tempStyle['fontSize'];
            }

            tempFontSize = 12;

            var newStyle = {fontSize: tempFontSize};

            let styles = this.props.style;

            styles = {...styles, fontSize: tempFontSize};
            //styles.fontSize = tempFontSize;//= {...styles, newStyle};

            this.setNativeProps({style:newStyle});
            this.props.style = styles//{...this.props.style, fontSize: tempFontSize};
        }

    }

    render() {
        return super.render();
    }


}
···
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容