首页 > 解决方案 > 如何使嵌套文本,第二个文本不换行?

问题描述

https://facebook.github.io/react-native/docs/text#docsNav 官方文档中嵌套文本的描述,但我想要另一个效果

<Text>
  <Text>First part and </Text>
  <Text>second part</Text>
</Text>

// Text container: the text will be inline if the space allowed it
// |First part and second part|

// otherwise, the text will flow as if it was one
// |First part |
// |and second |
// |part       |

我希望“第二部分”不要包装,例如:

// |First part |
// |and        |
// |second part|
// or
// |First part and       |
// |second part          |

不是这个:</p>

// |First part and second p|
// |art                    |

不希望“第二部分”被截断。谢谢!

标签: react-nativetext

解决方案


您可以尝试这样不要使用嵌套文本<Text>{'First part and\nsecond part'}</Text>


推荐阅读