文本不会在React Native组件中自动换行

时间:2019-02-08 11:56:54

标签: react-native react-native-flatlist react-native-stylesheet

所以我使用的是Flatlist,使用数组中的数据,并在屏幕上显示了它。 这就是我要说的。

enter image description here

我希望我的输出像红色框中显示的那样。

这是我的代码。

<R> R retryForResult( Supplier<R> functionToCall, Function<R,Boolean> resultValidationFunction, long maxTimeMs, Iterable<Long> retryDelays );  

1 个答案:

答案 0 :(得分:2)

从代码中删除平面列表:

用以下代码替换渲染方法:

     constructor(props) {
        super(props)
        this.state = {
            data: [{ law_practice_description: 'Administration  Administration' },
            { law_practice_description: 'Administration  Agency Prctice' },
            { law_practice_description: 'Administration  hearing and  appeals' },
            { law_practice_description: 'Administration  Administration' },
            { law_practice_description: 'Administration  Agency Prctice' },
            { law_practice_description: 'Administration  hearing and  appeals' },
            { law_practice_description: 'Administration  Administration' },
            { law_practice_description: 'Administration  Agency Prctice' },
            { law_practice_description: 'Administration  hearing and  appeals' }],
        };
    }

     render() {
        let str = ''
        this.state.data.map((item, index) => {
             if (index == 0) {
                str = item.law_practice_description
             } else {
                str = str + ', ' + item.law_practice_description
             }
        })
        return (
            <View style={{ flex: 1 }} >
                <Text style={styles.titleTxt}>Administrative Law</Text>
                <Text style={{ fontSize: 16, color: 'black', }}>
                    {str}
                </Text>
            </ View>
        );
    }