我刚刚开始研究 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/