React Native JSI library for communicate between js and native code via jsi skipping the react-native bridge which improve performance and skips data serialization/deserialization.
#add to package.json
"react-native-jsi-bridge":"sergeymild/react-native-jsi-bridge#0.5.2"
# after that make yarn install
# and npx pod-install
on js side just import import { JsiBridge } from 'react-native-jsi-bridge'
and subscribe on events which will be fired from native code.
import { JsiBridge } from 'react-native-jsi-bridge';
// for subscribe
JsiBridge.on('eventNameInJsCode', (data: string) => {
})
// for unsubscribe
JsiBridge.off('eventNameInJsCode')
For send event to native code
// send event to native code
JsiBridge.emit('eventNameInNativeCode', JSON.stringify({user: "withNamr"}))
On native side (Java/Kotlin)
// for subscribe
JsiBridge.on('eventNameInNativeCode', someObjectSerializedToString -> {
})
// for unsubscribe
JsiBridge.off('eventNameInNativeCode')
// send event to js code
JsiBridge.emit('eventNameInJsCode', someObjectSerializedToString)
On native side
#import "JsiBridgeEmitter.h"
// for subscribe
[[JsiBridgeEmitter shared] on:@"eventNameInNativeCode" with:^(NSString *data) {
// some logic
}];
// for unsubscribe
[[JsiBridgeEmitter shared] off:@"eventNameInNativeCode"];
// send event to js code
[[JsiBridgeEmitter shared] emit:@"eventNameInJsCode" with:@"someObjectSerializedToString"];
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT