项目作者: chooin

项目描述 :
React Native Lifecycle
高级语言: TypeScript
项目地址: git://github.com/chooin/react-native-lifecycle.git
创建时间: 2020-08-14T01:43:08Z
项目社区:https://github.com/chooin/react-native-lifecycle

开源协议:MIT License

下载


React Native Lifecycle

GitHub license
Latest Version on NPM
npm
build status

简体中文

Install

  1. yarn add react-native-lifecycle

Peer Dependencies

  1. yarn add @react-navigation/native # >= 5.7.0 or >= 6.0.0

Support

package name version react-native version
react-native-lifecycle 2.0.0+ 0.65.0+
react-native-lifecycle 1.2.4+ 0.59.0+

Usage

Example

Global Hooks
  1. import { useAppActive, useAppInactive } from 'react-native-lifecycle';
  2. export default function App() {
  3. // Called when the application switches from the background to the foreground
  4. useAppActive(() => {});
  5. // Called when the application switches from the foreground to background
  6. useAppInactive(() => {});
  7. }
Page/Screen Hooks
  1. import {
  2. useMount,
  3. useShow,
  4. useHide,
  5. useUnmount,
  6. useResize,
  7. } from 'react-native-lifecycle';
  8. export default function Page() {
  9. // Called when the page or component is mounted
  10. useMount(() => {});
  11. // Called when the page is displayed, or when the application switches from the background to the foreground
  12. useShow(() => {});
  13. // Called when the page is hidden, or when the application switches from the foreground to the background
  14. useHide(() => {});
  15. // Called when the page or component is unmounted
  16. useUnmount(() => {});
  17. // Called after the page window resize
  18. useResize(() => {});
  19. }