typescript - 如何使用 asyncStorage 使用 typescript 在 expo 上构建应用程序介绍滑块
问题描述
我正在使用 react-native-app-intro-slider 来显示我使用 typescript 在 expo 上构建的应用程序的入门。我希望滑块仅在启动期间首次显示,但似乎遇到了问题。
我对打字稿很陌生,但我环顾四周,所有的解决方案似乎都是使用 asyncStorage 进行本机反应。
不确定我是否在这里做。
import AsyncStorage from '@react-native-community/async-storage'
const data = [{...}, {...}, {...}]
AsyncStorage.setItem('showIntro', 'true')
function App() {
{ (AsyncStorage.getItem('showIntro') === 'true') ? (
<AppIntroSlider
renderItem={renderItem}
data={data}
onDone={onDone}/>
) : (
<ShowApp />
)
}
}
解决方案
我想onDone
一旦你的滑块完成就会被调用。您可以将函数传递给onDone
处理程序并将其设置screen
为 false。
import AsyncStorage from '@react-native-community/async-storage'
const data = [{...}, {...}, {...}]
const getScreen = async () => {
return await AsyncStorage.getItem('showIntro');
}
function App() {
const [showIntro, updateShowIntro] = React.useState(getScreen());
const onDone = () => {
AsyncStorage.setItem('showIntro', false).then(()=>{});
updateShowIntro(false);
}
return (
{ showIntro ? (
<AppIntroSlider
renderItem={renderItem}
data={data}
onDone={onDone}/>
) : (
<ShowApp />
)
}
);
}
推荐阅读
- javascript - 在 Firefox 上调用 unhandledrejection 处理程序,但在 Chrome 上没有?
- azure - 如何使用 ICSharpCode.SharpZipLib.Zip 压缩 blob
- .net-core - NamedPipeClientStream - 服务器断开连接时的通知
- r - 用于显示/隐藏行组的数据表按钮
- asp.net-web-api - InvalidOperationException:未指定 authenticationScheme,也未找到 DefaultChallengeScheme。(.net 核心 5)
- visual-studio-code - VSCode:悬停文档未显示完整的功能文档
- primefaces - 在哪里可以找到 Primefaces 3.4.1 捆绑包(开发包)?
- c++ - 从 MySQL 结果集中检索字符串列
- c# - 如何将firebase推送通知发送到ios应用程序
- swift - CoreData 一对多关系。NSSet 归属问题