我在Simulate display: inline in React Native年前try 过这个解决方案,但没有成功.

我想做和HTML一样的事情

第一行很短,所以看起来没问题,但是第二行的内容太长了,在进入下一行之前,它会填满所有的空间.

但我的输出看起来像...

<View style={styles.contentView}>
    <Text style={styles.username}>{s_username}</Text>
    <Text style={styles.content}>{s_content}</Text>
</View>

contentView: {
    paddingLeft: 10,
    flex: 1,
    flexDirection:'row',
    flexWrap:'wrap'
},
username: {
    fontWeight: 'bold'
},
content: {

}, 

推荐答案

React Native支持nested Text components,您必须使用它来获得所需的结果.例如,第二个文本组件应该嵌套在第二个文本组件中,如下所示:

<View style={styles.contentView}>
    <Text>
        <Text style={styles.username}
              onPress={() => {/*SOME FUNCTION*/} >
           {s_username}
        </Text>
        <Text style={styles.content}>{s_content}</Text>
    </Text>
</View>

React-native相关问答推荐

如何在Reaction本地日历中 Select 年份?

在 react native 平面列表中动态定位弹出窗口

react-native 根据状态隐藏显示按钮

useState 函数似乎阻止了 Animated.timing 事件?

什么时候适合在 React 中使用构造函数?

Soundcloud API /stream 端点给出 401 错误

因 JVM 堆空间耗尽而导致守护进程到期?

使用 resizeMode = contain时的图像对齐

如何在 React Native 中访问原生 UI 组件的实例方法

React Native:无法点击调试菜单

如何渲染多行文本组件,行间有白色间隙

如何使用功能组件向 ref 公开功能?

如何使 React Native Animated.View 可点击?

将 react-native 元素Bundle 为 iOS 框架或 (.aar) Android 库

[React-Native][Jest]SyntaxError: Unexpected token import

在 FlatList 上使用 React Native 搜索过滤器

JSON 解析错误:无法识别的令牌'<'

react-native构建错误:package android.support.annotation does not exist

Gradlew bundleRelease 不会在 react-native 中生成发布 apk

React Native + Redux 基本认证