
[英]I am trying to change this React class component into a Functional Component
[英]i am trying to change flash mode on expo camera but nothing seems to work (react native: functional compnents)
我正在尝试更改 expo 相机上的 flash 模式,但它不起作用,我找不到任何文档,这是一些代码片段:-我用于 ZA39401275D1B300AA789FB22AEA4 模式的钩子:
const [flash, setFlash] = useState(Camera.Constants.FlashMode.off);
- 这是我正在使用的 function:
<TouchableWithoutFeedback style={styles.flash}
onPress={() => {
setFlash(
flash === Camera.Constants.FlashMode.off
? Camera.Constants.FlashMode.torch
: Camera.Constants.FlashMode.off);
}}>
<MaterialCommunityIcons
style={styles.flash}
name="flash"
color={"#9c1937"}
size={50}
/>
</TouchableWithoutFeedback>
我无法使用此更改 flash 模式(默认:关闭),但是使用完全相同的方式更改前后摄像头,所以请帮助,(我正在使用功能组件)。
将以下内容添加到您的相机组件中。
<Camera
flashMode={flash}
/>
这是在expo-camera
上切换 flash 的基本代码。
<Camera
type={this.state.type}
style={{flex: 1,}}
ref={(ref) => { this.camera = ref }}
flashMode={this.state.flashMode? Camera.Constants.FlashMode.torch : Camera.Constants.FlashMode.off}
>
<View>
<TouchableOpacity onPress={() => this.setState({flashMode: !this.state.flashMode})}>
<FontAwesome
name="flash"
size={40}
color={"#fff"}
/>
</TouchableOpacity>
</View>
</Camera>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.