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

feat: dismiss keyboard #306

Merged
merged 4 commits into from
Dec 23, 2023
Merged

feat: dismiss keyboard #306

merged 4 commits into from
Dec 23, 2023

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Dec 22, 2023

📜 Description

Added KeyboardController.dismiss method.

💡 Motivation and Context

Actually there is quite a lot of motivation behind such functionality. Let's go one-by one

1️⃣ Community request

In Algolia I constantly see that people are looking for dismiss method.

One week ago Two weeks ago One month ago
image image image

2️⃣ react-native flaws implementation

react-native implementation is based on the next code:

class Keyboard {
  // ...
  dismiss(): void {
    dismissKeyboard();
  }
  // ...
}

function dismissKeyboard() {
  TextInputState.blurTextInput(TextInputState.currentlyFocusedInput());
}

Where currentlyFocusedInput is set in:

function focusInput(textField: ?ComponentRef): void {
  if (currentlyFocusedInputRef !== textField && textField != null) {
    currentlyFocusedInputRef = textField;
  }
}

And the usage of this function:

const _onFocus = (event: FocusEvent) => {
  TextInputState.focusInput(inputRef.current);
  if (props.onFocus) {
    props.onFocus(event);
  }
};

So theoretically if you use TextInput component that is not based on the implementation from react-native core (i. e. you decided to write your own component), then Keyboard.dismiss most likely will not work 😓

3️⃣ Standalone module

I'm going to continue the development of this library and in the future I may need to rely on the presence/implementation of my own methods.

For example I'm thinking about Toolbar component implementation (the component above the keyboard with prev/next/done buttons). In my opinion it'll be strange when this component will fully depend on the methods from this package AND on a single function from react-native Keyboard module 🤔

So I think it's better to have own equivalent.

📢 Changelog

Docs

  • re-write docs about existing setInputMode/setDefaultMode;
  • added documentation about dismiss method;

JS

  • added dismiss in specs, types;
  • added mock and unit-test;

iOS

  • used with resignFirstResponder selector to dismiss a keyboard (source);
  • added dismiss method to KeyboardController;

Android

  • used hideSoftInputFromWindow to close a keyboard (source);
  • added dismiss method to KeyboardController;

🤔 How Has This Been Tested?

Tested manually on:

  • Pixel 3a (Android 13, emulator);
  • iPhone 15 Pro (iOS 17.2 simulator);

📸 Screenshots (if appropriate):

Android iOS
Screen.Recording.2023-12-23.at.00.33.43.mov
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2023-12-23.at.00.32.22.mp4

📝 Checklist

  • CI successfully passed

@kirillzyusko kirillzyusko added the feature request 👀 Request new functionality of the library label Dec 22, 2023
@kirillzyusko kirillzyusko self-assigned this Dec 22, 2023
Copy link
Contributor

github-actions bot commented Dec 22, 2023

📊 Package size report

Current size Target Size Difference
99758 bytes 99386 bytes 372 bytes 📈

Copy link
Contributor

github-actions bot commented Dec 22, 2023

PR Preview Action v1.4.6
🚀 Deployed preview to https://kirillzyusko.github.io/react-native-keyboard-controller/pr-preview/pr-306/
on branch gh-pages at 2023-12-23 13:29 UTC

Copy link

argos-ci bot commented Dec 22, 2023

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No change detected - Dec 23, 2023, 1:30 PM

@kirillzyusko kirillzyusko marked this pull request as ready for review December 22, 2023 23:45
@kirillzyusko kirillzyusko added documentation Improvements or additions to documentation enhancement New feature or request and removed feature request 👀 Request new functionality of the library labels Dec 22, 2023
@kirillzyusko kirillzyusko merged commit 1651da4 into main Dec 23, 2023
23 checks passed
@kirillzyusko kirillzyusko deleted the feat/keyboard-dismiss branch December 23, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant