Skip to content

Commit 5b65344

Browse files
authored
fix: pending dismiss if keyboard wasn't shown in app yet (#857)
## 📜 Description Specify `isClosed=true` by default. ## 💡 Motivation and Context By default when app starts the keyboard is closed. So `isClosed` should be `true` 🙂 Code that I used for testing: ```tsx import { StyleSheet, Alert, TextInput, TouchableOpacity, Text } from 'react-native'; import { KeyboardAwareScrollView, KeyboardController, KeyboardProvider, } from 'react-native-keyboard-controller'; export default function HomeScreen() { return ( <KeyboardProvider> <KeyboardAwareScrollView bounces={false} keyboardDismissMode="interactive" keyboardShouldPersistTaps="handled" style={styles.container} > <TextInput editable style={styles.input} /> <TouchableOpacity onPress={() => KeyboardController.dismiss().then(() => Alert.alert('Dismissed'))}> <Text>Press me to dismiss</Text> </TouchableOpacity> </KeyboardAwareScrollView> </KeyboardProvider> ); } const styles = StyleSheet.create({ input: { borderBottomColor: 'black', borderBottomWidth: 1, }, container: { flex: 1, paddingTop: 100, backgroundColor: "white", }, }); ``` > One interesting thing that I discovered is that on Android 9 e2e tests stopped to work. Turned out I had to set `adjustResize` mode to make app working well (on Android 9 `WindowInsetsCallbackCompat` events are not triggered if we are in `adjustPan`). Initially I wanted to fix it by replacing `KeyboardEvents` -> `Keyboard`, but then I realized, that `Keyboard` events may not be synchronized with animation on Android, so decided just add `useResizeMode` hook in example app to make e2e tests green again. But I'll keep in mind this fact. Closes #854 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### JS - set `isClosed=true` instead of `isClosed=false` as default value; ## 🤔 How Has This Been Tested? Tested in reproduction example and via e2e tests. ## 📸 Screenshots (if appropriate): |Before|After| |-------|-----| |<video src="https://github.com/user-attachments/assets/6a1fa7dc-87ac-4eff-810f-b99a5ab5f95c">|<video src="https://github.com/user-attachments/assets/2ccd11c7-57d2-4e34-890b-1e27163e7f16">| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent 7c33c6f commit 5b65344

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

FabricExample/src/screens/Examples/Close/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { useRef, useState } from "react";
22
import { Button, StyleSheet, TextInput, View } from "react-native";
3-
import { KeyboardController } from "react-native-keyboard-controller";
3+
import {
4+
KeyboardController,
5+
useResizeMode,
6+
} from "react-native-keyboard-controller";
47

58
function CloseScreen() {
9+
useResizeMode();
10+
611
const ref = useRef<TextInput>(null);
712
const [keepFocus, setKeepFocus] = useState(false);
813

example/src/screens/Examples/Close/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { useRef, useState } from "react";
22
import { Button, StyleSheet, TextInput, View } from "react-native";
3-
import { KeyboardController } from "react-native-keyboard-controller";
3+
import {
4+
KeyboardController,
5+
useResizeMode,
6+
} from "react-native-keyboard-controller";
47

58
function CloseScreen() {
9+
useResizeMode();
10+
611
const ref = useRef<TextInput>(null);
712
const [keepFocus, setKeepFocus] = useState(false);
813

src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
KeyboardEventData,
77
} from "./types";
88

9-
let isClosed = false;
9+
let isClosed = true;
1010
let lastEvent: KeyboardEventData | null = null;
1111

1212
KeyboardEvents.addListener("keyboardDidHide", (e) => {

0 commit comments

Comments
 (0)