react-native-community / hooks

React Native APIs turned into React Hooks for use in functional React components
ISC License
3.47k stars 199 forks source link

refactor: improve useKeyboard cross-platform compatibility #401

Open sabuhiteymurov opened 1 year ago

sabuhiteymurov commented 1 year ago

Summary

This pull request enhances the useKeyboard hook in the react-native-community/hooks library to improve cross-platform compatibility for keyboard events. Currently, the hook supports both keyboardWillShow and keyboardWillHide events on iOS, but for Android, it uses keyboardDidShow and keyboardDidHide events. To ensure consistent behavior across platforms, this update introduces conditional event listeners based on the platform.

The motivation behind this change is to provide a consistent and reliable experience for handling keyboard events in a cross-platform React Native application. By utilizing the appropriate keyboard events based on the platform, this enhancement aims to improve the overall user experience and streamline the development process.

Test Plan

What's required for testing (prerequisites)?

What are the steps to reproduce (after prerequisites)?

  1. Import and use the useKeyboard hook in a React Native component.
  2. Test the component on both iOS and Android devices or simulators.
  3. Observe the behavior of the keyboardShown, coordinates, and keyboardHeight values when the keyboard is shown and hidden.

Compatibility

OS Implemented
iOS
Android
Web

Checklist