Здравствуйте, я пытался исправить это всеми возможными способами, которые все еще не могут найти проблему, проблема появляется, только когда приложение переходит на другой экран после того, как обнаруживает, что пользователь уже видел экран в первый раз время, я думал, потому что, когда я ухожу, состояние все еще не обновляется? любая помощь приветствуется.
function UserScreen({navigation}) {
useEffect(() => {
checkIfFisrtTime()
}, [])
const [name, setname] = useState(undefined)
const [altura, setaltura] = useState(undefined)
const [peso, setpeso] = useState(undefined)
const [hombre, sethombre] = useState(false)
const [mujer, setmujer] = useState(false)
const [error, seterror] = useState(undefined)
const [loading, setloading] = useState(true)
const [first, setfirst] = useState()
async function checkIfFisrtTime() {
const value = await AsyncStorage.getItem("firstLogging")
setfirst(value)
setloading(false)
}
function check() {
console.log(first)
console.log(loading)
}
if (loading==true && first ==undefined || first==null && loading===true || first=="false" && loading===true || first===undefined && loading ===false) {
return (<ActivityIndicator></ActivityIndicator>)
}
if(first==="false" && loading === false ){
return navigation.navigate("Mainflow")
}
if ( first==null && loading===false ) {
return (
<View style={{ top: height * 0.1, flexDirection: "column", justifyContent: "space-between", height: height * 0.6 }}>
<Text style={{ textAlign: "center", fontWeight: "bold" }}>{i18n.t("Information")}</Text>
<CheckBox
left
title={i18n.t("Male")}
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={hombre}
onPress={() => { sethombre(true), setmujer(false) }}
containerStyle={{ width: width * 0.5, alignSelf: "center", borderRadius: 15 }}
icon
/>
<CheckBox
left
title={i18n.t("Female")}
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={mujer}
onPress={() => { setmujer(true), sethombre(false) }}
containerStyle={{ width: width * 0.5, alignSelf: "center", borderRadius: 15 }}
/>
<Input
placeholder={i18n.t("Age")}
errorStyle={{ color: 'red' }}
errorMessage={undefined}
onChangeText={(name) => { setname(name.replace(/[- #*;,.<>\{\}\[\]\\\/]/gi, '')) }}
value={name}
keyboardType="numeric"
maxLength={2}
containerStyle={{ width: width * 0.5, alignSelf: "center" }}
leftIcon={
<MaterialCommunityIcons name="vanish" size={24}></MaterialCommunityIcons>
}
/>
<Input
placeholder={i18n.t("Height")}
errorStyle={{ color: 'red' }}
errorMessage={undefined}
onChangeText={(altura) => { setaltura(altura.replace(/[- #*;,.<>\{\}\[\]\\\/]/gi, '')) }}
value={altura}
keyboardType="numeric"
maxLength={3}
containerStyle={{ width: width * 0.5, alignSelf: "center" }}
leftIcon={
<MaterialCommunityIcons name="arrow-split-horizontal" size={24}></MaterialCommunityIcons>
}
/>
<Input
placeholder={i18n.t("Weight")}
errorStyle={{ color: 'red' }}
onChangeText={(namee) => { setpeso(namee.replace(/[- #*;,.<>\{\}\[\]\\\/]/gi, '')) }}
value={peso}
keyboardType="numeric"
maxLength={3}
containerStyle={{ width: width * 0.5, alignSelf: "center" }}
leftIcon={
<MaterialCommunityIcons name="scale-bathroom" size={24}></MaterialCommunityIcons>
}
errorMessage={error}
/>
<Button title={i18n.t("Continue")} containerStyle={{ width: width * 0.4, alignSelf: "center" }} raised onPress={()=>{ValidateIfundefined()}}>
</Button>
<Button title="boton" onPress={()=>{check()}}></Button>
</View>
)
async function ValidateIfundefined() {
if (name==undefined && altura==undefined && peso==undefined && hombre==false && mujer==false) {
//seterror("Please make sure everything is ok")
}
if (altura==undefined || peso==undefined || altura==undefined || hombre==false && mujer == false) {
//seterror("Please fill everything")
}
if (name!=undefined && altura!=undefined && peso!=undefined && mujer!=false && hombre==false) {
await AsyncStorage.setItem("firstLogging","false")
navigation.navigate("Mainflow")
}
if (name!=undefined && altura!=undefined && peso!=undefined && hombre!=false && mujer==false) {
await AsyncStorage.setItem("firstLogging","false")
navigation.navigate("Mainflow")
}
}
}
}