我已经在react native上创建了一个应用。它只有2个活动,现在我想将它们集成到我现有的android应用中(Native android app).
我知道,React-native并不提供生成.arr
文件或native code
的功能。为此,我们需要使用Electrode Native
。
我的问题是:还有其他方法可以从react-native代码生成本地(iOS / android)代码吗?是否存在其他工具?如果可以,Electrode native
还提供哪些其他功能来考虑呢?
React Native提供了一个模块,用于检测运行应用程序的平台。您可以使用检测逻辑来实现特定于平台的代码。仅当组件的一小部分特定于平台时,请使用此选项。
import {Platform, StyleSheet} from 'react-native';
const styles = StyleSheet.create({
height: Platform.OS === 'ios' ? 200 : 100,
});
Platform.OS在iOS上运行时将是ios,在Android上运行时将是android。
还有一个Platform.select方法,给定一个包含Platform.OS作为键的对象,它返回您当前正在运行的平台的值。
import {Platform, StyleSheet} from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
...Platform.select({
ios: {
backgroundColor: 'red',
},
android: {
backgroundColor: 'blue',
},
}),
},
});
[这将导致容器在两个平台上都具有flex:1,在iOS上为红色背景色,在Android上为蓝色背景色。
由于它接受任何值,因此您也可以使用它来返回特定于平台的组件,如下所示:
const Component = Platform.select({
ios: () => require('ComponentIOS'),
android: () => require('ComponentAndroid'),
})();
<Component />;
检测Android版本在Android上,“平台”模块还可用于检测运行该应用的Android平台的版本:
import {Platform} from 'react-native';
if (Platform.Version === 25) {
console.log('Running on Nougat!');
}
检测iOS版本在iOS上,版本是-[UIDevice systemVersion]的结果,这是操作系统当前版本的字符串。系统版本的示例是“ 10.3”。例如,要在iOS上检测主要版本号:
import {Platform} from 'react-native';
const majorVersionIOS = parseInt(Platform.Version, 10);
if (majorVersionIOS <= 9) {
console.log('Work around a change in behavior');
}
要回答what other features Electrode native offers to make one consider it?
上的问题
[在将多个不同的React Native组件开发,集成和重用到现有的移动应用程序中时,开发人员面临明显的挑战。
Electrode Native通过提供一个开放源代码平台来应对这些挑战,从而减少了React Native开发人员和移动应用程序开发人员之间的摩擦。使用Electrode Native平台解决方案,开发人员可以充分利用自己的知识,而无需大幅度更改其工作流以适应其移动应用程序中多个React Native组件的集成]
Electrode Native使移动应用程序开发人员可以轻松地将单个React Native组件集成到其现有的移动应用程序中,而无需更改其基础结构,也无需处理或安装任何基于JavaScript的工具-甚至不需要Electrode Native本身!
最重要的是:使用Electrode Native,开发人员可以专注于功能和构建他们的应用程序,而不会遇到重用或集成问题的麻烦。
在此处阅读有关Why electrode native的更多信息。