Using React Native within existing iOS app for some views only

1.1k views Asked by At

Is it possible to use React Native only for one view within the project?

I've successfully added React view for particular iOS app screen (using instructions from "Integration with existing iOS project" docs), but i don't know how to get data from that screen and call other (objective-c) code. For example I want to replace old storyboard-based Search Form to React view and then call storyboard-based screens when user clicks "Search".

Or it is intended to make all views in React and convert existing non-React views into 'native' components (very huge work for big apps)?

2

There are 2 answers

3
Sean Kinsey On BEST ANSWER

This is easily accomplished via the Native Module concept which is described here - https://facebook.github.io/react-native/docs/nativemodulesios.html

You can export obj-c methods to JS via a single call.

0
aksonov On

I've solved my issue in following way:

  1. Create Native Module wrapper around NSNotificationCenter, so javascript code could publish iOS events.

  2. Subscribe for that event within ReactController-wrapper around React-Native code.

  3. Raise event when user clicked «Search» (when we need to give control back to objective-c) with needed data to pass as dictionary.

  4. Catch event, process data, open other controllers/etc