React-native-camera: Toggling torch works only when remote debug is ON (android 7.0)

Created on 22 Jan 2019  路  3Comments  路  Source: react-native-camera/react-native-camera

Toggling torch on/off won't work without remote debugging on.
Happens with Android (7.0)
Not tested with iOS yet

//  ...
import {RNCamera} from 'react-native-camera'

class Capture extends Component {
  constructor(props){
    super(props)
    this.toggleTorch = this.toggleTorch.bind(this)
    this.state = {
      torchON: false
    }
  }

  toggleTorch(){
    if(this.camera){
      this.setState({torchON: !this.state.torchON})
    }
  }

  render(){
    console.log(this.camera) // <--- solved by removing/comment out this line (edited)
    return(
      <View style={localStyle.container}>
        <RNCamera
          ref={ camera => this.camera = camera }
          style={localStyle.preview}
          captureAudio={false}
          flashMode={this.state.torchON ? RNCamera.Constants.FlashMode.torch: RNCamera.Constants.FlashMode.off}
          permissionDialogTitle={'Permission to use camera'}
          permissionDialogMessage={'We need your permission to use your camera phone'}
        />
        <View style={localStyle.bottom}>
          <TouchableOpacity onPress={this.toggleTorch} style={localStyle.switch}>
             <Text style={{ fontSize: 14 }}>Torch {this.state.torchON ? "ON" : "OFF"}</Text>
          </TouchableOpacity>
        </View>
      </View>
    )
  }
}

const localStyle = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'black'
  },
  preview: {
    flex: 1,
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
  bottom:{
    justifyContent: 'center',
  },
  switch: {
    flex: 0,
    backgroundColor: '#fff',
    borderRadius: 5,
    padding: 15,
    paddingHorizontal: 20,
    alignSelf: 'center',
    margin: 20,
  }
})
Android Bug Help Wanted Missing Template

Most helpful comment

Issue solved.
I feel so stupid to put console.log(this.camera) inside the render function.
I forgot to remove/comment it out causing the app to stuck.
My bad my bad...

All 3 comments

@aiibe Are you interested in solving this issue?

@n1ru4l I'd like to but I don't even know where to begin inspecting from.

Issue solved.
I feel so stupid to put console.log(this.camera) inside the render function.
I forgot to remove/comment it out causing the app to stuck.
My bad my bad...

Was this page helpful?
0 / 5 - 0 ratings