react-native - react native 空白 : nowrap width for absolutely positioned Text node

标签 react-native

在 HTML/CSS 中,如果您希望绝对定位的元素比其父元素扩展得更宽以将其所有文本放在一行中,您可以使用 white-space: no-wrap

.parent {
  position: relative;
  width: 100px;
}
// text content of this node is wider than 100px
.child {
  position: absolute;
  white-space: nowrap;
}

子元素将增长到足以容纳一行中的所有文本。 Text 没有办法做到这一点React Native 中的组件。您必须指定一个固定的数字宽度,否则 Text 组件将在父宽度处最大化。有办法吗?

最佳答案

发现答案很简单。

可以使用 <Text> 指定文本换行组件的内置接口(interface) numberOfLines , 而不是 CSS。

<Text numberOfLines={1}>Foobar</Text>

可以找到这方面的文档 here .

关于react-native - react native 空白 : nowrap width for absolutely positioned Text node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46698137/

相关文章:

javascript - Mongodb 位置运算符不起作用

javascript - 如何将图像定义为背景? ( react native )

reactjs - React-Native支持React 16吗?

javascript - TypeError : e. _panGestureHandler.current.setNativeProps 不是函数

reactjs - 为什么组件中的 React Native 函数没有 "function"关键字?

react-native - node_modules/expo/AppEntry.js : Transformer. 变换不是函数

java - npm run android commad 给出找不到符号错误

reactjs - 如何使用 recompose 的 toClass HOC 向功能组件添加引用?

react-native - 如何在 react-native 中将 ByteArray 转换为 Image?

javascript - 使用 React Native 和 Redux 的动画状态管理