![](/img/trans.png)
[英]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.