Reputation: 5498
I'm looking at using react-native components across mobile platforms (iOS and Android). The only approach I've seen for adding a react-native component to an Android app is to create an activity that extends ReactActivity
.
Is there any way of adding/using react-native components at a lower level of granularity, such as a View
?
Upvotes: 5
Views: 1127
Reputation: 5498
It is not necessary to extend the ReactActivity
class. But: If you don't, your activity must do certain things that ReactActivity
would otherwise do for you. In particular, you must forward some life-cycle events to the ReactInstanceManager
:
onPause
, forward to reactInstanceManager.onHostPause
;onResume
, forward to reactInstanceManager.onHostResume
;onDestroy
, forward to reactInstanceManager.onHostDestroy
, and unmount your react application....and so on. See the source code for ReactActivity
and (in particular) ReactActivityDelegate
(which does most of the heavy lifting) for details.
(Never mind ReactFragmentActivity
, which has been deprecated.)
Upvotes: 1