Skip to content

fix: don't report a zero-height keyboardWillShow as an open keyboard on iOS - #1677

Merged
kirillzyusko merged 5 commits into
kirillzyusko:mainfrom
seantanys:fix/ios-zero-height-keyboard-progress
Oct 14, 2026
Merged

kirillzyusko merged 5 commits into
kirillzyusko:mainfrom
seantanys:fix/ios-zero-height-keyboard-progress

Conversation

@seantanys

@seantanys seantanys commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

Don't report a zero-height keyboardWillShow as a fully open keyboard on iOS.

💡 Motivation and Context

Closes #1676.

On a foldable iPhone, rotating with the keyboard closed makes iOS post keyboardWillShow with a zero-height frame. keyboardWillAppear always sent onKeyboardMoveStart with progress: 1, so the event was height: 0, progress: 1. The onKeyboardMoveEnd that follows already reports height: 0, progress: 0, but on iOS the provider only applies the start event, so progress stayed at 1 and KeyboardStickyView used its opened offset until the next real keyboard show/hide.

The fix derives progress from the frame height in keyboardWillAppear, so the start event agrees with the end event. I kept it on the native side so the iOS animation stays driven by the one-shot onKeyboardMoveStart write: a real keyboard (height > 0) still reports 1, so nothing changes for normal show/hide.

Repro screen (from the issue)
import React, { useState } from "react";
import { Button, StyleSheet, Text, TextInput, View } from "react-native";
import {
  KeyboardController,
  KeyboardStickyView,
  useReanimatedKeyboardAnimation,
} from "react-native-keyboard-controller";
import { runOnJS, useAnimatedReaction } from "react-native-reanimated";
import { SafeAreaView } from "react-native-safe-area-context";

// Lifted above a 50pt bar while the keyboard is closed, like a chat composer above a tab bar
const offset = { closed: -50, opened: 0 };
const edges = ["top"] as const;
const dismiss = () => KeyboardController.dismiss();

export default function KeyboardStickyViewRotation() {
  const { height, progress } = useReanimatedKeyboardAnimation();
  const [values, setValues] = useState({ height: 0, progress: 0 });

  useAnimatedReaction(
    () => ({ height: height.value, progress: progress.value }),
    (current) => {
      runOnJS(setValues)(current);
    },
  );

  return (
    <SafeAreaView edges={edges} style={styles.container}>
      <Text style={styles.label} testID="keyboard_values">
        {`height: ${values.height.toFixed(
          0,
        )}\nprogress: ${values.progress.toFixed(2)}`}
      </Text>
      <Text style={styles.hint}>
        Keep the keyboard closed and rotate the device. The input should stay
        above the grey bar.
      </Text>
      <View style={styles.dismiss}>
        <Button
          testID="dismiss_keyboard"
          title="Dismiss keyboard"
          onPress={dismiss}
        />
      </View>
      {/* rendered under the input, so a dropped input stays visible and tappable on top of it */}
      <View style={styles.bar} />
      <KeyboardStickyView offset={offset} style={styles.sticky}>
        <TextInput
          placeholder="Message"
          placeholderTextColor="#8E8E93"
          style={styles.input}
          testID="sticky_input"
        />
      </KeyboardStickyView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "flex-end",
  },
  label: {
    position: "absolute",
    top: 80,
    left: 16,
    fontSize: 20,
  },
  hint: {
    position: "absolute",
    top: 150,
    left: 16,
    right: 16,
    color: "#8E8E93",
  },
  dismiss: {
    position: "absolute",
    top: 200,
    left: 16,
  },
  sticky: {
    position: "absolute",
    left: 0,
    right: 0,
    bottom: 0,
  },
  input: {
    height: 50,
    marginHorizontal: 16,
    paddingHorizontal: 12,
    borderRadius: 12,
    backgroundColor: "#E5E5EA",
  },
  bar: {
    height: 50,
    backgroundColor: "#8E8E93",
  },
});

📢 Changelog

iOS

  • report progress: 0 in onKeyboardMoveStart when keyboardWillShow carries a zero-height keyboard frame

🤔 How Has This Been Tested?

FabricExample Debug builds with Xcode 27, with the repro screen above:

  • iPhone Duo simulator (iOS 27.1), unfolded: on main, rotating with the keyboard closed leaves progress: 1.00 and drops the input; with this change it stays 0.00. Checked with "Simulate Hardware Keyboard" on and off
  • iPhone Duo with the fix: keyboard open/close, rotating with the keyboard open and back, and three more rotation round trips: values and position stay correct
  • iPhone 17 Pro simulator (iOS 26.2): same checks with the fix, no change in behaviour (this device never reproduced it)
  • iPhone 18 Pro simulator (iOS 27.0): does not reproduce on main
  • the same change also fixes the issue in a production Expo app on 1.22.4

yarn typescript and yarn lint pass. I couldn't run SwiftLint locally.

I didn't add a native unit test: KeyboardMovementObserver isn't compiled into the native test target on main. #1668 adds that wiring and a KeyboardMovementObserverTests.swift, so I'm happy to add a case for this once it lands.

📸 Screenshots (if appropriate):

iPhone Duo (iOS 27.1): before (left, main) / after (right)

duo-before-after.mp4

iPhone 17 Pro (iOS 26.2): after, no change in behaviour

pro-after.mp4

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko self-assigned this Oct 13, 2026
@kirillzyusko kirillzyusko added 🐛 bug Something isn't working 🍎 iOS iOS specific core 🧱 Something related to the core of this library (scope is limited to keyboard movement tracking) labels Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

📊 Package size report

Current size Target Size Difference
346499 bytes 346444 bytes 55 bytes 📈

@kirillzyusko kirillzyusko left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks good, let's address these two comments and we can merge it!

@kirillzyusko

Copy link
Copy Markdown
Owner

Thanks @seantanys

Changes look good. I hope that keyboardHeight = 0 on rotation will not introduce the crash from #178 🤞

Your changes anyway look good, so I'll merge them! Thank you for your contribution!

@github-actions

Copy link
Copy Markdown
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working core 🧱 Something related to the core of this library (scope is limited to keyboard movement tracking) 🍎 iOS iOS specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] progress stays at 1 with height 0 after rotating a foldable with the keyboard closed

2 participants