Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Toggling torch works only when remote debug is ON (android 7.0) #2061

Closed
aiibe opened this issue Jan 22, 2019 · 3 comments
Closed

Toggling torch works only when remote debug is ON (android 7.0) #2061

aiibe opened this issue Jan 22, 2019 · 3 comments

Comments

@aiibe
Copy link

aiibe commented Jan 22, 2019

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,
  }
})
@n1ru4l
Copy link
Collaborator

n1ru4l commented Jan 22, 2019

@aiibe Are you interested in solving this issue?

@aiibe
Copy link
Author

aiibe commented Jan 22, 2019

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

@aiibe
Copy link
Author

aiibe commented Jan 22, 2019

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...

@aiibe aiibe closed this as completed Jan 22, 2019
@react-native-camera react-native-camera locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants