React Native App Development Company in USA | Page 4
);
}
}
const styles = StylesSheet.create ({
container : {
flex :1,
justifyContent : ‘center’,
alignItems : ‘center’,
backgroundColor : ‘#F5FCFF’,
},
});
})
COPY
Now open Xcode console to ascertain the logs and that we can see that Swift turnOn method is named from JavaScript
code. (As we've done logging within the method)
Step 2 - Understanding GCD Queue and fixing the warning:
Now let's fix the warning shown at rock bottom of the simulator and in browser console:
To understand it better let's understand about all the thread React Native runs:
Main thread: where UIKit work
Shadow queue: where the layout happens
JavaScript thread: where your JS code is really running
Every native module has its own GCD Queue except it determines otherwise. Now since this Native module will run on a
special thread and our main thread depends thereon , it's showing this warning. And to form this code to run on
MainQueue, open Bulb.swift and add this function.
@objc
static func requiresMainQueueSetup() -> Bool {
return true
}
COPY
You can explicitly mention return false to run this during a separate threat.
Step 3 - Accessing a variable in JavaScript from Swift and Callbacks
add the Bulb Status(ON or OFF) value to our React screen. to try to do so we'll add the getStatus function to Bulb.swift