level 2
不需要判断平台,因为react native运行的时候会根据以下规则进行差异化加载:
1、可以使用文件夹层名对两个平台的组件进行区分,例如:
公用的:/common/components/
android的:/android/components/
ios的:/ios/components/
2、可以使用文件名进行区分,例如:
BigButtonIOS.js
BigButtonAndroid.js
3、类似于2,如:
BigButton.ios.js
BigButton.android.js
推荐使用3的方式,把两文件放在同一目录下,即可根据访问平台自动加载对应的js文件。
官方文档说明:http://facebook.github.io/react-native/docs/platform-specific-code.html#content
2015年12月31日 06点12分