import AsyncStorage from '@react-native-async-storage/async-storage';
// or whatever
const key = "hasPassed"
export const hasPassed = async () => {
return AsyncStorage.getItem(key).then(result => result != null ? JSON.parse(result) : undefined).catch(e => console.log(e))
}
export const setHasPassed = async (newPassed) => {
return AsyncStorage.setItem(key, JSON.stringify({hasPassed: newPassed})).catch(e => console.log(e))
}
// or whatever name it is
const MainScreen = () => {
const [showpass, setshowpass] = useState();
useEffect(() => {
const getState = async () => {
const result = await hasPassed()
setshowpass(result ? result.hasPassed : false)
}
getState()
}, [])
// since it is async
if (showpass === undefined) {
return null
}
return (
<View style={styles.body}>
<Modal
transparent={false}
visible={showpass}
animationType='slide'
hardwareAccelerated
>
<View style={styles.body}>
<Text style={styles.toptext}>Congratulations!</Text>
<Text style={styles.toptext}>Worked great in Turkishya!</Text>
<Text style={styles.topptext}>
And mastered the skill 'Alphabets'
</Text>
</View>
</Modal>
<View>
);
}
if(count<5) {
// Alert.alert('pass','pass');
// showing passing screen in the form of a modal
setHasPassed(true).then(() => setshowpass(true))
}