Skip to content

Commit

Permalink
chore(2.1.0): 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chooin committed Mar 23, 2022
1 parent f89ebc0 commit 148286e
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 31 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ export default function App() {

```js
import {
useLoad,
useMount,
useShow,
useHide,
useUnload,
useUnmount,
useResize,
} from 'react-native-lifecycle';

export default function Page() {
// Called when the page load
useLoad(() => {});
// Called when the component is mounted
useMount(() => {});

// Called when the page is displayed or in the application from background to foreground
useShow(() => {});

// Called when the page is hidden or in the application from foreground to background
useHide(() => {});

// Called when the page is unloaded
useUnload(() => {});
// Called when the component is unmounted
useUnmount(() => {});

// Called after the page window resize
useResize(() => {});
Expand Down
12 changes: 6 additions & 6 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ export default function App() {

```js
import {
useLoad,
useMount,
useShow,
useHide,
useUnload,
useUnmount,
useResize,
} from 'react-native-lifecycle';

export default function Page() {
// 页面创建时执行
useLoad(() => {});
// 组件创建时执行
useMount(() => {});

// 页面出现在前台时执行
useShow(() => {});

// 页面从前台变为后台时执行
useHide(() => {});

// 页面销毁时执行
useUnload(() => {});
// 组件销毁时执行
useUnmount(() => {});

// 页面尺寸变化时执行
useResize(() => {});
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-lifecycle",
"version": "2.0.4",
"version": "2.1.0",
"description": "React Native Lifecycle",
"main": "dist/index.js",
"repository": "[email protected]:chooin/react-native-lifecycle.git",
Expand All @@ -17,11 +17,12 @@
"husky": "^7.0.2",
"prettier": "^2.4.1",
"pretty-quick": "^3.1.1",
"typescript": "^4.4.3"
"typescript": "^4.4.3",
"zx": "^6.0.7"
},
"scripts": {
"prepare": "husky install",
"build": "tsc"
"build": "scripts/build.mjs"
},
"files": [
"dist",
Expand Down
4 changes: 4 additions & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env zx

await $`tsc`;
await $`api-extractor run`;
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { useLoad } from './useLoad';
import { useMount } from './useMount';
import { useShow } from './useShow';
import { useHide } from './useHide';
import { useUnload } from './useUnload';
import { useUnmount } from './useUnmount';
import { useResize } from './useResize';
import { useAppActive } from './useAppActive';
import { useAppInactive } from './useAppInactive';

export {
useAppActive,
useAppInactive,
useLoad,
useMount,
useShow,
useHide,
useUnload,
useUnmount,
useResize,
useAppActive,
useAppInactive,
};
4 changes: 2 additions & 2 deletions src/useHide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useRef } from 'react';
import {
AppState,
AppStateStatus,
EmitterSubscription,
NativeEventSubscription,
Platform,
} from 'react-native';
import { useNavigation } from '@react-navigation/native';
Expand All @@ -13,7 +13,7 @@ import { useNavigation } from '@react-navigation/native';
*/
export function useHide(fn: () => void): void {
const navigation = useNavigation();
const AppStateRef = useRef<EmitterSubscription | null>(null);
const AppStateRef = useRef<NativeEventSubscription | null>(null);

const onChange = (state: AppStateStatus) => {
if (
Expand Down
4 changes: 2 additions & 2 deletions src/useLoad.ts → src/useMount.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useEffect } from 'react';

/**
* Called when the page load
* Called when the component is mounted
* @public
*/
export function useLoad(fn: () => void): void {
export function useMount(fn: () => void): void {
useEffect(() => {
fn();
}, []);
Expand Down
4 changes: 2 additions & 2 deletions src/useShow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useRef } from 'react';
import {
AppState,
AppStateStatus,
EmitterSubscription,
NativeEventSubscription,
Platform,
} from 'react-native';
import { useNavigation } from '@react-navigation/native';
Expand All @@ -13,7 +13,7 @@ import { useNavigation } from '@react-navigation/native';
*/
export function useShow(fn: () => void): void {
const navigation = useNavigation();
const AppStateRef = useRef<EmitterSubscription | null>(null);
const AppStateRef = useRef<NativeEventSubscription | null>(null);
const isAppStateChangeRef = useRef(false);

const onChange = (state: AppStateStatus) => {
Expand Down
4 changes: 2 additions & 2 deletions src/useUnload.ts → src/useUnmount.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useEffect } from 'react';

/**
* Called when the page is unloaded
* Called when the component is unmounted
* @public
*/
export function useUnload(fn: () => void): void {
export function useUnmount(fn: () => void): void {
useEffect(() => {
return () => {
fn();
Expand Down
Loading

0 comments on commit 148286e

Please sign in to comment.