Skip to content
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

Modernize Keyboard subscription, RN v0.65+ #244

Merged
merged 1 commit into from
Oct 14, 2021

Conversation

wildseansy
Copy link

@wildseansy wildseansy commented Aug 20, 2021

Summary

React Native 0.65 seems to not support Keyboard.removeListener anymore. Technically it's deprecated, but if you run

console.log(Keyboard.removeListener);

...it produces undefined

Test Plan

What's required for testing (prerequisites)?

  • Call useKeyboard within a component that gets destroyed, on React Native v0.65

What are the steps to reproduce (after prerequisites)?

  • Run on React Native v0.65, call useKeyboard within a component that then is destroyed via re-render

Compatibility

OS Implemented
iOS
Android
Web

@gp3gp3gp3
Copy link

This change is true of all hooks in this library

@wildseansy
Copy link
Author

wildseansy commented Aug 24, 2021

@gp3gp3gp3 - yes, the other hooks similarly need updates, but they're not as urgent. They are following proper deprecation rules, whereas Keyboard.removeListener seems to have been removed completely, possibly by accident

console.log(Keyboard.removeListener);

..produces undefined (as event emitter now exposes removeListeners)

As far as I have seen, other hooks are still are supported in 0.65 as the API yet been hard-deprecated (although it may emit warnings. Example: useDimensions uses

  Dimensions.addEventListener(...);
  Dimensions.removeEventListener(...);

These functions still exist in react-native@0.65.2.

Relevant:
react-native-community/releases#245 (comment)

This change is true of all hooks in this library

@matinzd
Copy link

matinzd commented Oct 8, 2021

I think it's time to merge this pr on master.

Comment on lines +61 to +63
for (const subscription of subscriptions) {
subscription.remove()
}
Copy link
Author

@wildseansy wildseansy Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matinzd - I used to use forEach more, now I follow unicorn lint pretty religiously for standards:
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-for-each.md

Happy to make the change though if you prefer forEach

@wojciechkrol
Copy link

Hello devs,

Can you merge these changes and release new version of the library?

Copy link
Member

@LinusU LinusU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@LinusU LinusU added the patch Increment the patch version when merged label Oct 14, 2021
@LinusU LinusU merged commit d953b48 into react-native-community:master Oct 14, 2021
@matinzd
Copy link

matinzd commented Oct 14, 2021

When are you going to release a new version?

@LinusU
Copy link
Member

LinusU commented Oct 14, 2021

I thought it was going to release automatically since I added the patch label but that seems to be broken 😢

@LinusU
Copy link
Member

LinusU commented Oct 14, 2021

@pvinis was it you who set up automatic releasing? Or am I just forgetting how it works? 😅

@pvinis
Copy link
Member

pvinis commented Oct 14, 2021

i think so too 🤔. let me take a look now.

@pvinis
Copy link
Member

pvinis commented Oct 14, 2021

🚀 PR was released in v2.6.1 🚀

@pvinis pvinis added the released This issue/pull request has been released. label Oct 14, 2021
@pvinis
Copy link
Member

pvinis commented Oct 14, 2021

ok i did a manual release, i hope that worked well. i will try an automatic one to see whats up.

@pvinis
Copy link
Member

pvinis commented Oct 14, 2021

something is up.. it might need some reconfiguration for automatic releases 🤔

@matinzd
Copy link

matinzd commented Oct 14, 2021

ok i did a manual release, i hope that worked well. i will try an automatic one to see whats up.

It is still not on npm. Last release is for about year ago!

@KrisLau
Copy link

KrisLau commented Nov 11, 2021

Still getting the error for useKeyboard on react-native: 0.66.3 and @react-native-community/hooks: v2.8.0

EventEmitter.removeListener('keyboardWillShow', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by `EventEmitter.addListener`. 

@retyui
Copy link
Contributor

retyui commented Nov 11, 2021

@KrisLau

New fix: #279

@KrisLau
Copy link

KrisLau commented Nov 11, 2021

@retyui Thank you I'll upgrade as soon as it gets released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Increment the patch version when merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants