android - React Native 中 XML 内的 Platform.OS

标签 android xml react-native cross-platform

我刚刚开始研究 React Native,并且有一个组件,当我在 Android 上时,我需要在其中添加一些特定的 XML...我找到了 Platform Specific Code但我找不到在 XML 中执行此操作的示例...

我想做类似于下面的事情,当它在 Android 上时,我添加一些额外的 View ...我知道我可以通过执行 .android.js 扩展名来为 Android 创建一个单独的文件,但因为它是一个UI 上的细微差别,我更愿意将所有内容保留在同一个文件中...

<View style={styles.rowContainer}>
 Platform.select({
  android: {
   <Text>Test</Text>
  }
 }),
 <Button style={styles.notificationsItem}>Push Notifications</Button>
 <View style={styles.rightContainer}>
  <Image style={styles.thumbNotifications} source={notifications_checked} />
 </View>

那么有谁知道我如何像上面那样在 XML 之间使用 Platform.OS ?

最佳答案

看看这个代码示例,它非常简单:

class TestComponent extends Component {
  render() {
    return (
      <View>
        {Platform.select({
          android: <Text>Test</Text>
        )}
      </View>
    );
  }
}

关于android - React Native 中 XML 内的 Platform.OS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39035971/

相关文章:

android - 如何在 Kotlin 中获取 7 天前到今天的日期?

android - 如何在从通知调用的 Activity 中按回时留在应用程序中?

android - 如何知道最近的iBeacon

java - 当应用程序来自后台时更改菜单图标(在 onResume() 方法中)

Axios for REST api GET 中的 HTTP 失败

React-native Watchman 不再工作

android - 使用 AppCompat v22 时缺少 ActionBarDrawerToggle 图标

c# - 使用与序列匹配两次的正则表达式从 xml 中删除空元素

java - 通用列表上的 XStream 异常

javascript - React-Native:警告:无法对未安装的组件执行 React 状态更新