一款用于react-native监听app[AppState]前后台的自定义Hooks开源插件

react-native-watch-appstate

React Native appState hook is a custom react hook, built to handle iOS or Android or Harmony appState in your react component

自定义 appState hooks 适用于三端android/ios/harmony

_ AppState 可以告诉您应用程序是在前台还是后台,并在状态改变时通知您。 _

rn 官方地址 appState https://reactnative.dev/docs/appstate

安装

yarn add react-native-watch-appstate

OR

npm install react-native-watch-appstate


Example

javascript 复制代码
import React from "react";
import { Text, View } from "react-native";
import useAppState from "react-native-appstate-hook";

export default function App() {
  const appState = useAppState({
    onChange: (newAppState) =>
      console.warn("App state changed to ", newAppState),
    onForeground: () => console.warn("App went to Foreground"),
    onBackground: () => console.warn("App went to background"),
  });

  return (
    <View
      style={{
        textAlign: "center",
        backgroundColor: "white",
        flex: 1,
        justifyContent: "center",
      }}
    >
      <Text>App State is: {appState}</Text>
    </View>
  );
}
相关推荐
haishikeji696_6 小时前
多部门协同无人机管理系统架构设计|飞控管理平台、无人机巡检平台标准化开发方案
开源·无人机·低空经济·无人机管理系统·无人机飞控平台·一网统飞
GitCode官方10 小时前
openPangu-2.0-Pro 模型及技术报告正式开源上线 AtomGit AI
人工智能·华为·开源·harmonyos·atomgit
sbjdhjd10 小时前
安全初级 | Upload 文件上传漏洞实操
android·经验分享·安全·网络安全·开源·php·apache
Kevinten1011 小时前
OpenOctopus:领域原生 AI 家庭助手系统,Summon 功能将实体转化为智能 Agent
人工智能·ai·开源·开发工具·智能体
看昭奚恤哭12 小时前
基于 RuoYi-Vue-Pro 定制了一个后台管理系统 magic-admin , 开源出来!
前端·vue.js·开源
冬奇Lab1 天前
每日一个开源项目(第171篇):Harness Handbook - 给 AI Agent 的 Harness 代码库生成一本可导航的行为手册
人工智能·开源·资讯
仙宇觉尘1 天前
一款基于 .NET 开源美观、功能丰富的串口调试工具
开源·.net
iMountTai1 天前
DeepSeek-V4-Flash 接入 Codex(Windows 版)
开源
张彦峰ZYF1 天前
全球开源大模型生态-从开放权重到开放智能系统:发展、进展、主力模型成就与方向分析
人工智能·开源·llm·agent
GitCode官方1 天前
G-Star 精选开源项目推荐|第二十二期
开源