Skip to content

Commit 27c34d9

Browse files
committed
fix: attaching KeyboardTrackingView
1 parent 6aa917b commit 27c34d9

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

ios/observers/movement/KeyboardTrackingView.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import UIKit
1111
* A compatibility view that resolves to `KeyboardView` on iOS < 26
1212
* and uses `keyboardLayoutGuide` on iOS 26+.
1313
*/
14-
final class KeyboardTrackingView: UIView {
14+
final public class KeyboardTrackingView: UIView {
1515
private var keyboardView: UIView? { KeyboardViewLocator.shared.resolve() }
1616
private var keyboardHeight = 0.0
1717
private weak var currentAttachedView: UIView?
@@ -56,22 +56,16 @@ final class KeyboardTrackingView: UIView {
5656
name: UIResponder.keyboardDidShowNotification,
5757
object: nil
5858
)
59-
NotificationCenter.default.addObserver(
60-
self,
61-
selector: #selector(attachToTopmostView),
62-
name: UIApplication.didBecomeActiveNotification,
63-
object: nil
64-
)
6559
}
6660

67-
override func willMove(toWindow newWindow: UIWindow?) {
61+
public override func willMove(toWindow newWindow: UIWindow?) {
6862
// When the view is being removed from the window, we need to re-attach it
6963
if newWindow == nil, !isAttaching {
7064
attachToTopmostView()
7165
}
7266
}
7367

74-
@objc private func attachToTopmostView() {
68+
@objc public func attachToTopmostView() {
7569
guard let topView = UIApplication.topViewController()?.view else { return }
7670

7771
if currentAttachedView === topView { return }

ios/observers/movement/observer/KeyboardMovementObserver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class KeyboardMovementObserver: NSObject {
1818
var onRequestAnimation: () -> Void
1919
var onCancelAnimation: () -> Void
2020
// progress tracker
21-
var keyboardTrackingView = KeyboardTrackingView()
21+
@objc public var keyboardTrackingView = KeyboardTrackingView()
2222
var animation: KeyboardAnimation?
2323

2424
var prevKeyboardPosition = 0.0

ios/views/KeyboardControllerView.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ - (void)willMoveToSuperview:(UIView *)newSuperview
259259
}
260260
}
261261

262+
- (void)didMoveToWindow
263+
{
264+
[super didMoveToWindow];
265+
if (self.window) {
266+
[keyboardObserver.keyboardTrackingView attachToTopmostView];
267+
}
268+
}
269+
262270
- (void)mount
263271
{
264272
[inputObserver mount];

ios/views/KeyboardControllerViewManager.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ class KeyboardControllerView: UIView {
8484
mount()
8585
}
8686
}
87+
88+
override func didMoveToWindow() {
89+
super.didMoveToWindow()
90+
if window != nil {
91+
keyboardObserver?.keyboardTrackingView.attachToTopmostView()
92+
}
93+
}
94+
8795

8896
override func layoutSubviews() {
8997
super.layoutSubviews()

0 commit comments

Comments
 (0)