android - 将 ReactNative 用于 UI,但仍将 native API 用于其他用途

标签 android ios react-native react-native-ios

我尝试开发我的应用程序,该应用程序仅将 ReactNative 用于 UI,但仍将(在 Android 中) Activity/fragment/服务类用于业务逻辑。 iOS 也是一样,业务逻辑仍然使用 Controller 等。

但是当我在 Google 和 Youtube 上搜索时,我找到的所有教程都只讲述了如何制作只有 UI 东西、纯 ReactNative 代码的应用程序。我的问题是:

  1. 是否可以仅使用 ReactNative 制作 UI 但仍继续使用原生 API,例如我的移动项目中的 Activity/Fragment/Service (Android)、Controller (iOS)?

  2. 如果可能,怎么做?有什么好的教程(Android 和 iOS)?

最佳答案

根据 this article ,我不建议对所有内容(Activity/Fragment/Service..)使用原生模块

The performance bottleneck often occurs when we move from one realm (native or javascript) to the other. In order to architect performant React Native apps, we must keep passes over the bridge to a minimum.

有兴趣了解,this is how bridging works

有没有可能做你想做的事?是的。 但是,如果您要拥有 Activity 、服务和业务逻辑,那么您最好在 native 中全部完成。

根据您的应用需求,react-native 是否适合您。如果您的应用高度依赖硬件(蓝牙、加速度计等),需要高帧率性能(如游戏)或与其他应用(内容提供商)大量交互,或者设备系统(如警报管理器),那么我不建议使用它。否则,这是一个了不起的选择。

关于android - 将 ReactNative 用于 UI,但仍将 native API 用于其他用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45069003/

相关文章:

css - 在 React Native 中创建背景

javascript - 期望 reducer 是一个函数

javascript - native react : how to make two images fade to each other?

java - Canvas.rotate 调用导致绘制的项目消失?

ios - 在模拟器上运行时,WatchConnectivity 未在 iOS 端激活

ios - 如何让我的视频背景继续使用 swift 播放?

ios - NSOperation 和 NSURLConnection

android - 动态设置 LinearLayout 的宽度?

java - Android 上下文菜单未出现

android - 深度链接不会在 Android 中自动打开