React Native App Development Company in USA | Page 7

Rebuild the code and run the app, you'll see the Bulb Status value and once you click on activate then it'll show Bulb is ON Do remember to rebuild the code rather than refresh, as we changed Native Code. Section 2 — Native Bridge in Android In this section, we'll make an equivalent Javascript code which we return for iOS to figure with Android. At this point we'll create a Bulb class in Java and expose an equivalent function turnOn, TurnOff and getStatus to Javascript. Open Android Studio and click on Open an existing Android Studio project then select the android folder inside our LightApp. Once all gradle dependency is downloaded, create a Java Class Bulb.java as shown: And update the subsequent code in Bulb.java: Import com.facebook.react.bridge.Callback; Import com.facebook.react.bridge.ReactApplicationContext; Import com.facebook.react.bridge.ReactContextBaseJavaModule; Import com.facebook.react.bridge.ReactMethod; 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”); }