在本机反应中仅显示一次屏幕

问题描述

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

我该怎么做?

解决方法

您可以使用expo SecureStore软件包将bool值存储在本地存储中,甚至可以存储在安全存储中。然后在应用启动时检查商店中的值。

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...