facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.43k stars 24.25k forks source link

Extending components from the ObjC side #3444

Closed jaygarcia closed 8 years ago

jaygarcia commented 8 years ago

Hi all,

I've been troubled by this since January and I need the community's help. From what I can tell, to "extend" a component from the ObjC side -> JavaScript, a lot of source code needs to be duplicated.

For example: To “Extend" RCT Map (add the ability to read current annotations in view), i need to dup the source for RCTMap(View), RCTMapManager and the JavaScript source, then make my changes across the board. Some reasons include private methods on the Manager classes, the Macros exposing properties on the views, RCT_CUSTOM_VIEW_PROPERTY using class names, and the JavaScript wrapper registering class names via strings.

Am I way off target here? Can anyone forward me an example of extending a "leaf" component? (Map, TabBar, TabBarItem, etc..)

Many thanks. :)

chris-erickson commented 8 years ago

Hey @jaygarcia! I'd like to be able to do this as well. Some RN components have some functionality that would be useful to piggyback off of in the native code, rather than duplicating that functionality.

jaygarcia commented 8 years ago

Extending components is difficult because many "leaf" classes are not configured to be extended easily. The biggest issues i've found is that the macros that i have fallen in love with need to be copied wherever used. The javascript definition for leaf level nodes need to be copied entirely from what i can tell, further increasing to application weight.

I'd really love for someone else to weigh in on this pattern.

jaygarcia commented 8 years ago

Closing this issue.