diff --git a/.husky/pre-commit b/.husky/pre-commit index 9ad483a..91edfd4 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -pretty-quick --staged +./node_modules/.bin/pretty-quick --staged diff --git a/README.md b/README.md index 05a35bd..9087071 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ yarn add @react-navigation/native # >= 5.7.0 or >= 6.0.0 | package name | version | react-native version | | ---------------------- | ------- | -------------------- | | react-native-lifecycle | 2.0.0+ | 0.65.0+ | -| react-native-lifecycle | 1.0.0+ | 0.59.0+ | +| react-native-lifecycle | 1.2.4+ | 0.59.0+ | ### Usage diff --git a/src/hooks/use-app-active.ts b/src/hooks/use-app-active.ts index 75dd74a..55fc0c9 100644 --- a/src/hooks/use-app-active.ts +++ b/src/hooks/use-app-active.ts @@ -13,8 +13,8 @@ export default (fn: () => void): void => { }; useEffect(() => { - const unsubscribe = AppState.addEventListener('change', onChange); + const subscribe = AppState.addEventListener('change', onChange); - return () => unsubscribe.remove(); + return () => subscribe.remove(); }, []); }; diff --git a/src/hooks/use-app-inactive.ts b/src/hooks/use-app-inactive.ts index 7200413..43c71b8 100644 --- a/src/hooks/use-app-inactive.ts +++ b/src/hooks/use-app-inactive.ts @@ -19,8 +19,8 @@ export default (fn: () => void): void => { }; useEffect(() => { - const unsubscribe = AppState.addEventListener('change', onChange); + const subscribe = AppState.addEventListener('change', onChange); - return () => unsubscribe.remove(); + return () => subscribe.remove(); }, []); }; diff --git a/src/hooks/use-hide.ts b/src/hooks/use-hide.ts index f463ce9..ca7e40c 100644 --- a/src/hooks/use-hide.ts +++ b/src/hooks/use-hide.ts @@ -29,25 +29,25 @@ export default (fn: () => void): void => { }; useEffect(() => { - const unsubscribe = navigation.addListener('focus', () => { + const subscribe = navigation.addListener('focus', () => { AppStateRef.current = AppState.addEventListener('change', onChange); }); - return unsubscribe; + return subscribe; }, [navigation]); useEffect(() => { - const unsubscribe = navigation.addListener('blur', () => { + const subscribe = navigation.addListener('blur', () => { AppStateRef.current?.remove?.(); }); - return unsubscribe; + return subscribe; }, [navigation]); // ? 页面从前台变为后台时执行 useEffect(() => { - const unsubscribe = navigation.addListener('blur', fn); + const subscribe = navigation.addListener('blur', fn); - return unsubscribe; + return subscribe; }, [navigation]); }; diff --git a/src/hooks/use-resize.ts b/src/hooks/use-resize.ts index 148b2c4..dc7a21b 100644 --- a/src/hooks/use-resize.ts +++ b/src/hooks/use-resize.ts @@ -11,8 +11,8 @@ export default (fn: () => void): void => { }; useEffect(() => { - const unsubscribe = Dimensions.addEventListener('change', onChange); + const subscribe = Dimensions.addEventListener('change', onChange); - return () => unsubscribe.remove(); + return () => subscribe.remove(); }, []); }; diff --git a/src/hooks/use-show.ts b/src/hooks/use-show.ts index 93daae2..1973300 100644 --- a/src/hooks/use-show.ts +++ b/src/hooks/use-show.ts @@ -35,24 +35,24 @@ export default (fn: () => void): void => { }; useEffect(() => { - const unsubscribe = navigation.addListener('focus', () => { + const subscribe = navigation.addListener('focus', () => { AppStateRef.current = AppState.addEventListener('change', onChange); }); - return unsubscribe; + return subscribe; }, [navigation]); useEffect(() => { - const unsubscribe = navigation.addListener('blur', () => { + const subscribe = navigation.addListener('blur', () => { AppStateRef.current?.remove?.(); }); - return unsubscribe; + return subscribe; }, [navigation]); // ? 页面出现在前台时执行 useEffect(() => { - const unsubscribe = navigation.addListener('focus', () => { + const subscribe = navigation.addListener('focus', () => { if (isAppStateChangeRef.current) { isAppStateChangeRef.current = false; } else { @@ -60,6 +60,6 @@ export default (fn: () => void): void => { } }); - return unsubscribe; + return subscribe; }, [navigation]); };