aksonov
aksonov

Reputation: 853

Using React Native within existing iOS app for some views only

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)?

Upvotes: 5

Views: 1214

Answers (2)

aksonov
aksonov

Reputation: 853

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

Upvotes: 2

Sean Kinsey
Sean Kinsey

Reputation: 38046

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.

Upvotes: 2

Related Questions