TypeScript
fix(mobile): iPad composer drops when the keyboard floats or minimizes (#31251)
Julius Marminge3478e56b0bd1
diff --git a/patches/[email protected] b/patches/[email protected]index 3f307d3202c..4c13280a6ed 100644--- a/patches/[email protected]+++ b/patches/[email protected]@@ -1,3 +1,90 @@+diff --git a/ios/observers/movement/observer/KeyboardMovementObserver+Lifecycle.swift b/ios/observers/movement/observer/KeyboardMovementObserver+Lifecycle.swift+index cdbd633..41a72bc 100644+--- a/ios/observers/movement/observer/KeyboardMovementObserver+Lifecycle.swift++++ b/ios/observers/movement/observer/KeyboardMovementObserver+Lifecycle.swift+@@ -25,6 +25,12 @@ public extension KeyboardMovementObserver {+ name: UIResponder.keyboardWillShowNotification,+ object: nil+ )++ NotificationCenter.default.addObserver(++ self,++ selector: #selector(keyboardWillChangeFrame),++ name: UIResponder.keyboardWillChangeFrameNotification,++ object: nil++ )+ }++ @objc func unmount() {+diff --git a/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift b/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift+index 545a5b2..fbdc984 100644+--- a/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift++++ b/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift+@@ -8,6 +8,12 @@+ extension KeyboardMovementObserver {+ @objc func keyboardWillAppear(_ notification: Notification) {+ guard !UIResponder.isKeyboardPreloading else { return }++ floatingHideTask?.cancel()++++ if isFloatingKeyboard(notification) {++ hideIfKeyboardShown(notification)++ return++ }++ let (duration, frame) = notification.keyboardMetaData()+ if let keyboardFrame = frame {+@@ -36,8 +42,40 @@ extension KeyboardMovementObserver {+ }+ }+++ @objc func keyboardWillChangeFrame(_ notification: Notification) {++ guard !UIResponder.isKeyboardPreloading, isFloatingKeyboard(notification) else { return }++ // runs after a willShow/willHide posted with this notification, which cancel it, so hide events fire once++ floatingHideTask?.cancel()++ let task = DispatchWorkItem { [weak self] in++ self?.hideIfKeyboardShown(notification)++ }++ floatingHideTask = task++ DispatchQueue.main.async(execute: task)++ }++++ // iPadOS floating and minimized keyboards are narrower than the screen or end above the app's bottom, so++ // they cover no app content; UIKit switches to them without willHide, so they must count as hidden.++ private func isFloatingKeyboard(_ notification: Notification) -> Bool {++ guard let frame = notification.keyboardMetaData().1?.cgRectValue, !frame.isEmpty else { return false }++ let screen = (notification.object as? UIScreen ?? UIScreen.main).bounds++ // in Slide Over a docked keyboard ends at the app window's bottom, above the screen's++ let windowBottom = UIApplication.shared.activeWindow.map {++ $0.convert($0.bounds, to: $0.screen.coordinateSpace).maxY++ } ?? screen.height++ let dockedBottom = min(screen.height, windowBottom)++ return frame.width.rounded() < screen.width.rounded() || frame.maxY.rounded() < dockedBottom.rounded()++ }++++ private func hideIfKeyboardShown(_ notification: Notification) {++ let targetHeight = self.notification?.keyboardMetaData().1?.cgRectValue.height ?? 0++ if targetHeight > 0 {++ keyboardWillDisappear(notification)++ }++ }+++ @objc func keyboardWillDisappear(_ notification: Notification) {+ guard !UIResponder.isKeyboardPreloading else { return }++ floatingHideTask?.cancel()+ let (duration, _) = notification.keyboardMetaData()+ tag = UIResponder.current.reactViewTag+ self.notification = notification+diff --git a/ios/observers/movement/observer/KeyboardMovementObserver.swift b/ios/observers/movement/observer/KeyboardMovementObserver.swift+index ae97d61..2ea1d2d 100644+--- a/ios/observers/movement/observer/KeyboardMovementObserver.swift++++ b/ios/observers/movement/observer/KeyboardMovementObserver.swift+@@ -37,6 +37,7 @@ public class KeyboardMovementObserver: NSObject {+ // manual did events+ var notification: Notification?+ var keyboardDidTask: DispatchWorkItem?++ var floatingHideTask: DispatchWorkItem?++ @objc public init(+ handler: @escaping (NSString, NSNumber, NSNumber, NSNumber, NSNumber) -> Void,diff --git a/lib/commonjs/components/KeyboardChatScrollView/index.js b/lib/commonjs/components/KeyboardChatScrollView/index.jsindex 0b78ff3..98b3b6c 100644--- a/lib/commonjs/components/KeyboardChatScrollView/index.jsdiff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex cba3664e0b4..d295823f9bd 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -384,7 +384,7 @@ patchedDependencies:[email protected]: f1e680afec85f650699ea756f91f469844ec4c976f4f168492a45c6b3f67d651[email protected]: abe20e1d1c23549297cbbc818e14fe479b41455930d9663135d6b40fe359b626[email protected]: 4aa038d541c7ddcc8f1437eb3e7b4f769f61de78e7f91b53f9805dfca608474d- [email protected]: 6eb6c847ac693b636ec97c83575acd44b77e92ad0d2c776de0cb4e78e8fb9d4f+ [email protected]: 3fa3d03e203a23165a439c4cddf5372ccd53acf337389793211be64dcdafccef[email protected]: 6f52854210f61bef499850ebd498229a111bc34ec5b2a4925e644f2f48f42760[email protected]: 95ee26e5fcab5f50bc4b4c47b3f7e6278a0b20850205efb9f6ee7e70a22d2b59[email protected]: 81caa279ec3dc1f81209062133b66e8f824e13f106cca57f1fa732a72c2ab378@@ -745,7 +745,7 @@ importers:version: 0.2.2(patch_hash=4aa038d541c7ddcc8f1437eb3e7b4f769f61de78e7f91b53f9805dfca608474d)([email protected](@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected]))([email protected])react-native-keyboard-controller:specifier: 1.22.8- version: 1.22.8(patch_hash=6eb6c847ac693b636ec97c83575acd44b77e92ad0d2c776de0cb4e78e8fb9d4f)(e2a826d844fe10cdcbda558127861778)+ version: 1.22.8(patch_hash=3fa3d03e203a23165a439c4cddf5372ccd53acf337389793211be64dcdafccef)(e2a826d844fe10cdcbda558127861778)react-native-nitro-modules:specifier: 0.37.1version: 0.37.1([email protected](@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected]))([email protected])@@ -21272,7 +21272,7 @@ snapshots:react: 19.3.0react-native: 0.88.0(@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected])- [email protected](patch_hash=6eb6c847ac693b636ec97c83575acd44b77e92ad0d2c776de0cb4e78e8fb9d4f)(e2a826d844fe10cdcbda558127861778):+ [email protected](patch_hash=3fa3d03e203a23165a439c4cddf5372ccd53acf337389793211be64dcdafccef)(e2a826d844fe10cdcbda558127861778):dependencies:react: 19.3.0react-native: 0.88.0(@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected])