【发布时间】:2018-06-08 01:48:08
【问题描述】:
我正在尝试在 react native 中产生一种效果,即给定特定的文本数组,它会换行,同时它会垂直增加大小,为接下来的单词创建一个新行:
const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;
const styles = StyleSheet.create({
container: {
flex: 0.3,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
alignSelf: 'center',
},
wordsContent: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap'
},
txt: {
flex: 1,
flexDirection: 'row',
alignSelf: 'center',
width
}
});
export default class App extends Component<Props> {
render() {
const words = ['asdfasdf', 'asdf asdf', 'qwerqwer', 'qwer qwer', 'qwerwwe', 's332', '123123', 'sdfasdf'];
return (
<View style={styles.container}>
<View style={styles.wordsContent}>
<Text style={styles.welcome}>
Words:
</Text>
{
words.map((w, i) =>
<Text style={styles.txt} key={i}>
{w}
</Text>
)
}
</View>
</View>
);
}
}
我想继续向数组中添加单词,这些单词应该放在下一行。请注意,数组中的“单词”可以有空格。
【问题讨论】:
标签: javascript reactjs react-native flexbox