How to Create Bridge in React Native for iOS and Android?
React Native is developed in such a way that we will create a bridge between the language and therefore the JavaScript code. A “bridge” is nothing but how to line up communication between native platform and React Native.
React Native is developed in such a way that we will create a bridge between the language and therefore the JavaScript code. A “bridge” is nothing but how to line up communication between native platform and React Native.
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Public class Bulb extends ReactContextBaseJavaModule {
Private static Boolean inOn = false;
Public Bulb (ReactApplicationContext reactContext) {
Super (reactContext);
}
@ReactMethod
Public void getStatus (
Callback successCallback){
successCallback.invoke ( null,isOn);
}
@ReactMethod
Public void turnOn (){
isOn = true ;
system.out.println(“Bulb is turn On ”);
}
@ ReactMethod
Public void turnOff (){
isOn = false;
system.out.println(“Bulb is turn OFF”);
}
@Override
public string getName (){
Return : ‘Bulb’;
}
}
We have created a Bulb Java class which is rooted from ReactContextBaseJavaModule. ReactContextBaseJavaModule
requires that a function called getName is usually implemented. The aim of this method is to return the string name of
the Native Module which represents this class in JavaScript. So here we'll call this Bulb in order that we will access it
through React.NativeModules.Bulb in JavaScript. rather than Bulb, we will have a special name also.