Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
chooin committed Sep 23, 2021
1 parent 4c9b595 commit d6c104b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pretty-quick --staged
./node_modules/.bin/pretty-quick --staged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/use-app-active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}, []);
};
4 changes: 2 additions & 2 deletions src/hooks/use-app-inactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}, []);
};
12 changes: 6 additions & 6 deletions src/hooks/use-hide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
};
4 changes: 2 additions & 2 deletions src/hooks/use-resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}, []);
};
12 changes: 6 additions & 6 deletions src/hooks/use-show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,31 @@ 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 {
fn();
}
});

return unsubscribe;
return subscribe;
}, [navigation]);
};

0 comments on commit d6c104b

Please sign in to comment.