dsibiski / react-native-hybrid-app-examples

A collection of examples for using React Native in an existing iOS application
MIT License
228 stars 33 forks source link

Create advanced example using an Obj-C category #3

Open dsibiski opened 9 years ago

dsibiski commented 9 years ago

Try making the "Native Modal With RN Navigation" example using a category like the following example:

https://github.com/alinz/react-native-webview-bridge/blob/master/WebViewBridge/RCTWebViewManager%2BWebViewManager.m

chirag04 commented 9 years ago

Also, at times composition could help extend a RN component. Not sure if this applies to Native Modal with RN Nav example.

Both these techniques(category, composition) are used here: 1) [composition] github.com/chirag04/react-native-tooltip 2) [category] https://github.com/chirag04/tooltip

dsibiski commented 9 years ago

@chirag04 Thanks! I've looked at your tooltip project many times before as it has some very interesting solutions.

Essentially, the example referred to here is when you have an Obj-C view that loads a RCTBridge or RCTRootView. Sometimes you may want to expose methods from that base view to RN as a bridge module. However, when you create the bridge, JS has access to a different instance than Obj-C, since the bridge instantiates all bridge modules at load. This prevents you from being able to call methods on the view actually visible from JS. (I hope that isn't too confusing! hah)

I've discovered a couple different ways to do this, and an Obj-C category was suggested as one of them.