GeekyAnts / GeekyAnts/NativeBase
BackHandler Fix.
- Dominant language
- TypeScript
- Stars
- 20.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used [patch-package](https://github.com/ds300/patch-package) to patch `native-base@3.4.28` for the project I'm working on.
Here is the diff that solved my problem:
```diff
diff --git a/node_modules/native-base/src/hooks/useKeyboardDismissable.ts b/node_modules/native-base/src/hooks/useKeyboardDismissable.ts
index f3cfa44..8074119 100644
--- a/node_modules/native-base/src/hooks/useKeyboardDismissable.ts
+++ b/node_modules/native-base/src/hooks/useKeyboardDismissable.ts
@@ -42,18 +42,18 @@ export const useKeyboardDismissable = ({ enabled, callback }: IParams) => {
useBackHandler({ enabled, callback });
};
+
export function useBackHandler({ enabled, callback }: IParams) {
useEffect(() => {
- let backHandler = () => {
+ if (!enabled) return;
+
+ const backHandler = () => {
callback();
return true;
};
- if (enabled) {
- BackHandler.addEventListener('hardwareBackPress', backHandler);
- } else {
- BackHandler.removeEventListener('hardwareBackPress', backHandler);
- }
- return () =>
- BackHandler.removeEventListener('hardwareBackPress', backHandler);
+
+ const subscription = BackHandler.addEventListener('hardwareBackPress', backHandler);
+
+ return () => subscription.remove();
}, [enabled, callback]);
}
```
This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).
Contributor guide
Research direction
Start in src/hooks/useKeyboardDismissable.ts and inspect useBackHandler and its hardwareBackPress listener lifecycle. Compare the reported behavior with the supplied diff and verify that the listener is registered and cleaned up correctly; done means the BackHandler problem is fixed without regressions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, typescript
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100