gpt4 book ai didi

android - React Native 中 XML 中的 Platform.OS

转载 作者:搜寻专家 更新时间:2023-11-01 08:33:11 25 4
gpt4 key购买 nike

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

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

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com