Created
May 19, 2023 09:20
-
-
Save troZee/a611537cb41e7ccec47b35ddb5faaaea to your computer and use it in GitHub Desktop.
Calling a JS method from a native module using JSI in the React Native
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
// JS | |
BatchedBridge.registerCallableModule('JavaScriptVisibleToJava', { | |
alert: () => { | |
console.log('JavaScriptVisibleToJava'); | |
}, | |
}); | |
//iOS | |
[self.bridge enqueueJSCall:@"JavaScriptVisibleToJava" method:@"alert" args:@[] completion:NULL]; | |
//Android | |
CatalystInstance catalystInstance = ((ReactContext)getContext()).getCatalystInstance(); | |
WritableNativeArray params = new WritableNativeArray(); | |
catalystInstance.callFunction("JavaScriptVisibleToJava", "alert", params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment