-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix][useKeyboard] Adapt unsubscription for new EventEmitter API #279
[Fix][useKeyboard] Adapt unsubscription for new EventEmitter API #279
Conversation
@@ -50,17 +50,17 @@ export function useKeyboard() { | |||
] | |||
|
|||
return () => { | |||
if (Keyboard.removeListener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check work until the RN team decided to restore this method: facebook/react-native@035718b
Restore deprecated event listener removal methods in order to minimize breaking changes for the next release. The methods will work, but they will not report a warning via
console.error
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support versions <= 0.64
if (subscriptions[0]?.remove) {
subscriptions.forEach((subscription) => subscription.remove())
} else {
Keyboard.removeListener('keyboardWillShow', handleKeyboardWillShow)
Keyboard.removeListener('keyboardDidShow', handleKeyboardDidShow)
Keyboard.removeListener('keyboardWillHide', handleKeyboardWillHide)
Keyboard.removeListener('keyboardDidHide', handleKeyboardDidHide)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked 0.60.x , 0.61.x, 0.62.x RN versions
and in these versions addEventListner returned subscription with remove method
src/useKeyboard.ts
Outdated
@@ -50,17 +50,17 @@ export function useKeyboard() { | |||
] | |||
|
|||
return () => { | |||
if (Keyboard.removeListener) { | |||
if (typeof subscriptions?.[0]?.remove === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subscriptions[0]
always exists here.
if (typeof subscriptions?.[0]?.remove === 'function') { | |
if (typeof subscriptions[0].remove === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recheck it on latest versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you right RN [0.59.x...0.6x.x] always return EmitterSubscription with remove method, so this if
block don't make sense anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat, just one small nit
13355e0
to
37566c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing! 🎉
🚀 PR was released in |
Just to be clear, v2.8.1 won't support |
Oh yay! thanks for checking
…On Sat, Nov 13, 2021 at 2:44 AM David NRB ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/useKeyboard.ts
<#279 (comment)>
:
> @@ -50,17 +50,17 @@ export function useKeyboard() {
]
return () => {
- if (Keyboard.removeListener) {
I checked 0.60.x , 0.61.x, 0.62.x RN versions
and in these versions addEventListner returned subscription with remove
method
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#279 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABLNQJORDEF4RYYHZ7T63DULY6QHANCNFSM5H3KRAYQ>
.
|
Summary
Issue: #268 (comment)
Test Plan
What's required for testing (prerequisites)?
0.65
What are the steps to reproduce (after prerequisites)?
Compatibility
Checklist
README.md