每当我的应用程序打开一个模态并且尝试使用useState更新变量时,模态都会单独打开和关闭,在我的模态中有一个Switch,当我更改值时,它必须更改一个变量,但是碰巧这个变量我需要使用useState进行更改。
我的代码
const OverLay = ()=> {
return(
<Overlay animated={true}
animationType={"fade"}
statusBarTranslucent={true}
isVisible={over}
hardwareAccelerated={true}
onBackdropPress={()=>setOver(false)}
overlayStyle={{width:"80%",padding:20}}>
<Text style={{fontWeight:"bold", alignSelf:"center", fontSize:20, marginBottom:20}}>A impressão digital</Text>
<Text style={{fontSize:17}}>A impressão digital permite-te saltar o PIN e desbloquer o App com a tua impressão digital. A impressão digital só funciona caso
o teu smartphone suporte ou configuraste.
</Text>
<Switch
trackColor={{ false: "#ddd", true: Cores.primary }}
style={{alignSelf:"center", marginTop:10,marginBottom:20}}
thumbColor={isEnabled ? Cores.primary : "#ddd"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={isEnabled}
/>
<Button
title="Fechar"
onPress={()=>{
setOver(false);
}}
buttonStyle={{borderColor:Cores.primary}}
titleStyle={{color:Cores.primary}}
type="outline"
/>
</Overlay>
);
}