-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guide on extending React for iOS #114
Comments
👍 If the bridge and view registration could be described in the docs directory that would be really useful. I'm doing some rudimentary opengl tests and some guidance would help. May also be useful to #34. |
We definitely need some docs about how the bridge works - there is definitely some dark magic going on in there. A simple example/tutorial with a walk through of what actually happens under the covers would be awesome (internally and for the community). We'll definitely wrote something, hopefully soon.
|
The one thing i'll say, @sahrens is that the idea of RCT_CUSTOM_VIEW_PROPERTY as a macro for managers to do things on views seems a little strange to me. :-\ Maybe i'm too accustomed to being able to execute methods directly on views. @joewood , here's how i've been able to get things to work (hard to know if this is a hack or not). Keep a keen eye on the usage of RCT_CUSTOM_VIEW_PROPERTY VIEW header:
VIEW program:
VIEW MANAGER header:
VIEW MANAGER program:
JavaScript view definition:
VIEW JavaScript imp (truncated)l:
|
The idea in React is that views are immutable, and updated only by modifying state, which triggers a re-render of the view. There are numerous ways to circumvent this for stuff like animation, but really that's a hack and not in the spirit of the API, which is why we don't simply expose methods on views, as we do on view managers. @jaygarcia Instead of calling your property "doDraw" (implying an action), why not call it "bufferData", and set it in the render function of your RCEzPlotGlView.js? The actual native implementation of the property would be the same, but you would update it by triggering a re-render of the view instead of by directly manipulating the property. |
@nicklockwood Thanks for the feedback. Would you say that a view Manager is synonymous to a "controller"? I ask because it kinda feels that way :) This was more of an experimental pass and I agree that the name was off and it's been changed. I wasn't happy with the performance of the JavaScript <> ObjC calling 'draw' every 20ms or so. the CPU utilization was way high, so I decided to go to a threaded model where each Oscilloscope has its own thread. I just now need to inject mutex locks in some places because there are a few runloops, iOS, react, audio engine... ;). Oh the joy! Btw, do you have any feedback on the following pattern? It feels really dirty to have to descend into properties like this to get a reference to a view. :(
|
@jaygarcia yes, a ViewManager is very much a view controller. I considered changing the naming convention to "Controller", but that already has a meaning in iOS and in some cases we're implementing iOS-style ViewControllers as well, so it would have led to name collisions. Also, unlike iOS view controllers, ViewManagers are effectively singletons, with a single ViewManager instance responsible for all of the views that it creates. Views can easily delegate back to their ViewManager, but it's (deliberately) harder for ViewManagers to call methods directly on the views they create, because they don't retain references to them. Digging through the whole view hierarchy manually to find a component to call setProps shouldn't be necessary, but I'm not the right person to say what the current recommended approach is for finding a JS component in the hierarchy. Since setProps takes a reactID, I think you'd probably want to make a note of the reactID for the component in questions and then put the setDoDraw() method somewhere more convenient, rather than on the component itself. But I'm not sure about that. Maybe @sahrens can help? |
Set a |
@frantic dude!! Thanks =D |
I've spent a few hours diving through the source in both the JavaScript side and ObjC side and things are still unclear.
What I'd like to do is extend the basic View class, where I can inject an implementation of EZAudioPlot (Open GL version) in addition to a custom-compiled (soon to be open sourced) iOS wrapped implementation of LibGME.
The goal of this is to demonstrate the extensibility of React Native, going well above and beyond native Cocoa Touch components. The demo application will play chip tunes from popular game systems, powered by LibGME, a wrapper for many popular game system sound emulators.
I did something similar a few years back with Sencha Touch & PhoneGap for the Mod scene; See the following URL and fast forward to 23:18 https://vimeo.com/75277828 if you're interested.
The prototype for this is working perfectly in iOS ObjC Proper: http://screencast.com/t/I28k5OD94
Any guidance for this would be much appreciated.
The text was updated successfully, but these errors were encountered: