Skip to content

Instantly share code, notes, and snippets.

@WoonHaKim
Created November 14, 2021 11:44
Show Gist options
  • Save WoonHaKim/5a169987d82cf72cd58c2c952cacf068 to your computer and use it in GitHub Desktop.
Save WoonHaKim/5a169987d82cf72cd58c2c952cacf068 to your computer and use it in GitHub Desktop.
Call instance methods safely in RN
// 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