css - 如何连续放置内容并防止 react native 溢出?

标签 css react-native flexbox

我有一个如下所示的表格 View 行。

<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
  <Text>{user.fullName}</Text>
  <Button/>
</View>

在上面的渲染中,名称固定在左侧,按钮固定在右侧。

-----------------------------------
 User's Full Name           Button
-----------------------------------

当用户的全名足够短时一切都很好。

但是,当用户名很长时。 这是它的样子。

-----------------------------------
 User's Very Very Long Full Name         Button
-----------------------------------

现在,行内容超出了行的宽度,按钮超出了屏幕并变得不可见。

我要的是这个

-----------------------------------
 User's Very Very Long...   Button
-----------------------------------

如何使用 flexbox 模型实现这一点?

如何使 name 增长并填充可用宽度,但不超过?

请注意,Button 可以根据本地状态增大或缩小。

此外,在 react-native 上是否有等同于 text-overflow: ellipsis 的东西?

最佳答案

您可以在文本上设置 flex:1 以相对于剩余的 flex 元素(此处为按钮)增长。 Button 上没有设置 flex,它会占用它需要的空间。参见 numberOfLines文档。您可以将其设置为 1 以使文本变成椭圆形

<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
  <Text numberOfLines={1} style={{flex:1}}>{user.fullName}</Text>
  <Button/>
</View>

关于css - 如何连续放置内容并防止 react native 溢出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36808083/

相关文章:

javascript - 定义一个常量而不是将这个文字复制 3 次 sonar

css - 多个高度框都在顶部

html - 行与行之间的 Flexbox 空间

jquery - 使用 jquery 刷新 div 溢出滚动高度?

reactjs - react 原生相机胶卷 .heic 文件

xcode - 从 v0.61.5 手动升级到 v0.63.3 后如何修复 'ReactCommon/CallInvoker.h file not found'

html - Flexbox 对齐内容 : Right not applying

javascript - 使选项卡正确对齐

html - 如何在此跨度内垂直居中文本

css - 保持点击悬停效果