【问题标题】:Display a screen only once in react native在本机反应中仅显示一次屏幕
【发布时间】:2020-09-25 22:37:39
【问题描述】:

我有一个使用 react-native-swiper 制作的屏幕,我在其中介绍了应用程序的工作原理,但我只想在用户第一次打开应用程序时显示此屏幕。

我该怎么做?

【问题讨论】:

  • 这个网站不是为了“我该怎么做”?您需要研究自己的解决方案并展示您的工作。如果它没有按预期工作,请询问如何修复它。 stackoverflow.com/help/how-to-ask

标签: 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();
    },[]);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多