Steps to access Flashlight in React Native app
To turn the flashlight on/off on the mobile device react native provides a plugin called react-native-torch.
Installation:
npm install --save react-native-torch react-native link react-native-torch
iOS
1. npm install react-native-torch –save
2. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project’s name]
3. Go to node_modules ➜ react-native-torch and add RCTTorch.xcodeproj
4. Expand the RCTTorch.xcodeproj ➜ Products folder
5. In XCode, in the project navigator, select your project. Add libRCTTorch.a to your project’s Build Phases ➜ Link Binary With Libraries
6. Click RCTTorch.xcodeproj in the project navigator and go the Build Settings tab. Make sure ‘All’ is toggled on (instead of ‘Basic’). In the Search Paths section, look for Header Search Paths and make sure it contains both $(SRCROOT)/../../react-native/React and $(SRCROOT)/../../../React – mark both as recursive.
Usage:
import Torch from 'react-native-torch'; Torch.switchState(true); // Turn ON Torch.switchState(false); // Turn OFF
You can call this switchState function on any button press.