Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda