【问题标题】:Display a screen only once in react native在本机反应中仅显示一次屏幕
【发布时间】:2020-09-25 22:37:39
【问题描述】:
我有一个使用 react-native-swiper 制作的屏幕,我在其中介绍了应用程序的工作原理,但我只想在用户第一次打开应用程序时显示此屏幕。
我该怎么做?
【问题讨论】:
标签:
react-native
react-native-swiper
【解决方案1】:
您可以将布尔值存储在本地存储中,甚至可以使用 expo SecureStore 包存储在安全存储中。然后在应用启动时检查商店中的该值。
import * as SecureStore from 'expo-secure-store';
const app = ()=>{
useEffect(()=>{
const getStoredValue = async ()=> {
const introduction = await SecureStore.getItemAsync("introduction");
//use this variable to determine if you want to run the introduction.
//if introduction doesn't exist in the secure store create one
if (introduction === null ) {
try {
SecureStore.setItemAsync("Introduction", true);
}
catch (ex) {}
}
getStoredValue();
},[]);
}