【发布时间】:2021-05-07 20:37:10
【问题描述】:
我使用 Android 9 并且 React Native(expo) 的 textAlign 'justify' 应该可以工作,并且在大多数情况下都可以。但是我发现了一个不太容易重现的奇怪行为,但在某些情况下 textAlign 'justify' 引入了不需要的换行符。
在符合预期的代码下方:
import React from 'react';
import { StyleSheet, Text, SafeAreaView, Dimensions } from 'react-native';
export default function App() {
return (
<SafeAreaView>
<Text style={styles.normal_text}>blablablabla super interesting and fun character to play since she can use a lot of different cards for her build, and sometimes adapt her hand to the scenario. However, because she needs careful planning, she’s the </Text>
<Text style={styles.normal_text}>Lorem Ipsum</Text>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
normal_text: {
fontSize: 25,
textAlign: 'justify',
width:Dimensions.get('window').width - 24,
},
});
结果:
下面是一个非常相似的代码,但文本中的一个小改动会有所不同:
import React from 'react';
import { StyleSheet, Text, SafeAreaView, Dimensions } from 'react-native';
export default function App() {
return (
<SafeAreaView>
<Text style={styles.normal_text}>blablabla super interesting and fun character to play since she can use a lot of different cards for her build, and sometimes adapt her hand to the scenario. However, because she needs careful planning, she’s the </Text>
<Text style={styles.normal_text}>Lorem Ipsum</Text>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
normal_text: {
fontSize: 25,
textAlign: 'justify',
width:Dimensions.get('window').width - 24,
},
});
结果:
我只在第二种情况下删除了一个“bla”,它不再按预期工作。
有什么想法吗?
谢谢你!
【问题讨论】:
标签: react-native text text-align justify