Created
November 14, 2021 11:44
-
-
Save WoonHaKim/5a169987d82cf72cd58c2c952cacf068 to your computer and use it in GitHub Desktop.
Call instance methods safely in RN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C MACROs are not available in swift, so this format is prefered to use in Obj-C | |
RCT_EXPORT_METHOD(methodFoo:(NSNumber * __nonnull)reactTag //... whatever){ | |
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, | |
NSDictionary<NSNumber *, SomeView *> *viewRegistry) { | |
SomeView *view = viewRegistry[reactTag]; | |
if (![view isKindOfClass:[IvsPublisherView class]]) { | |
RCTLogError(@"Invalid view returned from registry, expecting SomeView, got: %@", view); | |
} | |
// Assumption: SomeView has @interface with -(whatever) methodFoo {} | |
[view methodFoo //...:whatever]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment