Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

293
Vistas
react-native-torch is not working properly

I am trying to use react-native-torch with react native. I took this code and put it into my project. I have also installed react-native-torch with npm install --save react-native-torch. My App.js looks like this (sorry for using code snippet, I wasn't able to achieve propriate formating with this formating):

 import React, { Component } from 'react';
 import {
   AppRegistry,
   Button,
   NativeModules,
   StyleSheet,
   Text,
   View
 } from 'react-native';
 import Torch from 'react-native-torch';
 
 export default class TorchDemo extends Component {
   constructor(props) {
     super(props);
 
     this.state = {
       isTorchOn: false,
     };
   }
 
   _handlePress() {
     const { isTorchOn } = this.state;
     Torch.switchState(!isTorchOn);
     this.setState({ isTorchOn: !isTorchOn });
   }
 
   render() {
     return (
       <View style={styles.container}>
         <Text style={styles.welcome}>
           RCTTorch Demo
         </Text>
         <Button
           onPress={this._handlePress.bind(this)}
           title="Toggle Torch"
         />
       </View>
     );
   }
 }
 
 const styles = StyleSheet.create({
   container: {
     flex: 1,
     justifyContent: 'center',
     alignItems: 'center',
     backgroundColor: '#F5FCFF',
   },
   welcome: {
     fontSize: 20,
     textAlign: 'center',
     margin: 10,
   },
   instructions: {
     textAlign: 'center',
     color: '#333333',
     marginBottom: 5,
   },
 });
 
 AppRegistry.registerComponent('TorchDemo', () => TorchDemo);

Everything runs as it should, but when I tap the toogle torch button, I am getting this warning and the flashlight will not turn on:

expo error

I have tried many forms of their demo codes, but the problem was always with Torch.switchState. Does anyone knows how to fix this issue?
Thank you very much for any help.
Jan

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Did you try building the app again as this module requires linking? If not, you need to run the React Native app again.

For android run: npx react-native run-android

For ios run: npx react-native run-ios

about 4 years ago · Juan Pablo Isaza Denunciar

0

It looks like you're using a managed workflow, it won't work through Expo Go. You need to use a development client for native code to work. Create it with EAS.

  1. Install the expo-dev-client library expo install expo-dev-client
  2. Create an eas.json eas build:configure
  3. Build client and install on device/emulator eas build -p android --profile development
  4. Use expo start --dev-client instead of 'expo start'

Docs: https://docs.expo.dev/development/getting-started/

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda