Skip to content

Commit 918254a

Browse files
authored
refactor: guard KeyboardLayoutGuide path through config (instead of direct checks) (#1517)
## 📜 Description Make configuration for `KeyboardTrackingView`. ## 💡 Motivation and Context In `1.22.x` I want to re-write the algorithm for tracking keyboard (yes, again) and switch back to legacy path (it looks like I found a better way of managing things and I can deliver better experience than `KeyboardLayoutGuide`). But at the same time I don't want to drop the current code with `KeyboardLayoutGuide`. So I decided to hide it under feature flag. If users discover regressions - they can just toggle feature flag and restore old behavior. Also in future if my method stops to work again I can also toggle feature flag and use modern path (when `KeyboardLayoutGuide` will be stable). To achieve this I added `KeyboardControllerConfiguration` with `usesKeyboardLayoutGuideTracking` field. And repalced corresponding `#available(iOS 26.0, *)` condition to `usesKeyboardLayoutGuideTracking` field. Such code helps us: - reduce code fragmentation; - control things from one place; - simplify the codebase and maintenance in the future. While refactoring it I also realised that we don't need to attach invisible `KeyboardLayoutGuide` on older iOS versions so I also guarded this code with `usesKeyboardLayoutGuideTracking` flag. ## 📢 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 --> ### iOS - added `KeyboardControllerConfiguration` file; - guard `KeyboardLayoutGuide` code under `usesKeyboardLayoutGuideTracking` flag; ## 🤔 How Has This Been Tested? Tested via e2e test. ## 📸 Screenshots (if appropriate): <img width="777" height="313" alt="Screenshot 2026-06-26 at 17 51 28" src="https://github.com/user-attachments/assets/d1f24f3d-509f-4dfa-a914-a9413ca84b25" /> ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent 83e622e commit 918254a

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// KeyboardControllerConfiguration.swift
3+
// Pods
4+
//
5+
// Created by Kiryl Ziusko on 25/06/2026.
6+
//
7+
8+
enum KeyboardControllerConfiguration {
9+
static var usesKeyboardLayoutGuideTracking: Bool {
10+
if #available(iOS 26.0, *) {
11+
return true
12+
}
13+
14+
return false
15+
}
16+
}

ios/observers/movement/KeyboardTrackingView.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import UIKit
99

1010
/**
11-
* A compatibility view that resolves to `KeyboardView` on iOS < 26
12-
* and uses `keyboardLayoutGuide` on iOS 26+.
11+
* A compatibility view that resolves to `KeyboardView` for the legacy path
12+
* and uses `keyboardLayoutGuide` for configured iOS 26+ behavior.
1313
*/
1414
public final class KeyboardTrackingView: UIView {
1515
private var keyboardView: UIView? {
@@ -69,6 +69,8 @@ public final class KeyboardTrackingView: UIView {
6969
}
7070

7171
@objc public func attachToTopmostView(toWindow window: UIWindow? = nil) {
72+
guard KeyboardControllerConfiguration.usesKeyboardLayoutGuideTracking else { return }
73+
7274
var topViewController = window?.rootViewController
7375
if let rootVC = topViewController, let topView = rootVC.view, topView.window != nil {
7476
// ok, attach
@@ -120,7 +122,7 @@ public final class KeyboardTrackingView: UIView {
120122
}
121123

122124
@objc var view: UIView? {
123-
if #available(iOS 26.0, *) {
125+
if KeyboardControllerConfiguration.usesKeyboardLayoutGuideTracking {
124126
return self
125127
} else {
126128
return keyboardView
@@ -135,7 +137,7 @@ public final class KeyboardTrackingView: UIView {
135137
let keyboardPosition = keyboardWindowH - keyboardFrameY
136138

137139
// for `keyboardLayoutGuide` case we can just read keyboard position directly - no interpolation needed
138-
if #available(iOS 26.0, *) {
140+
if KeyboardControllerConfiguration.usesKeyboardLayoutGuideTracking {
139141
if keyboardPosition > keyboardHeight {
140142
return Self.invalidPosition
141143
}

0 commit comments

Comments
 (0)