2016-08-19 12 views
1

我剛開始使用React Native並有一個組件,當我在Android上時需要添加一些特定的XML ...我找到了Platform Specific Code但我無法找到在XML中做這個的一個例子...React Native中的XML中的Platform.OS

我想做類似於下面的事情,在Android中添加一些額外的視圖...我知道我可以通過做一個單獨的文件在.android.js擴展,但因爲它是在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> 

因此,沒有人知道我會怎麼用平臺.OS之間的XML如上?

回答

2

看看這段代碼示例,這是非常簡單的:

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

當你想要把JS代碼JSX,放碼{}。 like:

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