在React Native中,Text组件会根据文本的长度自动换行。如何在自动换行后保持所需的缩进?
React Native的文本缩进
这个问题回答了如何使用文本组件创建缩进,但不像user3191334询问的那样解决多行缩进。
例如,如果我们使用单行缩进
<Text>{'t'}Hello, my name is John.</Text>
手机屏幕上的输出可以是:
Hello, my name is
John.
我想让它的输出是:
Hello, my name is
John.
在文本样式中添加paddingLeft
属性。下面是一个例子
<Text style={{paddingLeft:100}}>this is just and example </Text>
可以使用/n作为换行符
<Text>
Hi{'n'}
this is a test message.
</Text>
React native会解析你在{' some text '}中输入的任何内容。在您的示例中,您可以这样使用它:
<Text>
{`Hello, my name is
John.`}
</Text>