Skip to content

Commit 2a3bcee

Browse files
authored
fix: KeyboardExtender width on iPad in split mode (#1113)
## 📜 Description Use `window` size instead of `screen`. ## 💡 Motivation and Context Originally I added code in #948 (used subscription on `screen` instead of `window`). In #957 I realized that new approach has downsides and started to use `layoutSubviews` method instead of subscription to events that apple provides (and I kept using `screen` size as main source of truth). However on iPad in multi-task/stage-manager mode screen size may not reflect a real window size (because if window is floating it can be much smaller than the screen). So in this PR I'm refining solutions made in #948 and #957. We still need to use `window` as main source of truth and we need to read it in `layoutSubviews` because new dimensions may not be available in events that we receive from notification center. I tested repo provided in #948 and #957 and with new code they still seem to work well: |948|957| |----|----| |<video src="https://github.com/user-attachments/assets/80755323-dad0-49ef-8cde-916e1f3c525a">|<video src="https://github.com/user-attachments/assets/72b7b9e9-f385-45df-824e-c392f60f1af7">| Closes #1045 ## 📢 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 - read `window` dimensions instead of `screen`; ### iOS - use `self.window` instead of `UIScreen.main`; ## 🤔 How Has This Been Tested? Tested manually on iPad 11 Pro (m4, 16GB, iOS 18.5). ## 📸 Screenshots (if appropriate): |Before|After| |-------|-----| |<img width="1668" height="2420" alt="image" src="https://github.com/user-attachments/assets/d5ffe241-285a-44f5-869a-ac399308d281" />|<img width="1668" height="2420" alt="image" src="https://github.com/user-attachments/assets/59e73c7d-0618-4140-bec7-4547d9d29a2a" />| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent 77b3af5 commit 2a3bcee

File tree

8 files changed

+48
-14
lines changed

8 files changed

+48
-14
lines changed

.github/workflows/verify-ios.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565

6666
- uses: maxim-lobanov/setup-xcode@v1
6767
with:
68-
xcode-version: "16.2"
68+
xcode-version: "16.3"
6969

7070
- name: Install xcpretty
7171
run: gem install xcpretty

FabricExample/ios/KeyboardControllerFabricExample.xcodeproj/project.pbxproj

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,14 @@
241241
inputFileListPaths = (
242242
"${PODS_ROOT}/Target Support Files/Pods-KeyboardControllerFabricExample/Pods-KeyboardControllerFabricExample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
243243
);
244+
inputPaths = (
245+
);
244246
name = "[CP] Embed Pods Frameworks";
245247
outputFileListPaths = (
246248
"${PODS_ROOT}/Target Support Files/Pods-KeyboardControllerFabricExample/Pods-KeyboardControllerFabricExample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
247249
);
250+
outputPaths = (
251+
);
248252
runOnlyForDeploymentPostprocessing = 0;
249253
shellPath = /bin/sh;
250254
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-KeyboardControllerFabricExample/Pods-KeyboardControllerFabricExample-frameworks.sh\"\n";
@@ -280,10 +284,14 @@
280284
inputFileListPaths = (
281285
"${PODS_ROOT}/Target Support Files/Pods-KeyboardControllerFabricExample/Pods-KeyboardControllerFabricExample-resources-${CONFIGURATION}-input-files.xcfilelist",
282286
);
287+
inputPaths = (
288+
);
283289
name = "[CP] Copy Pods Resources";
284290
outputFileListPaths = (
285291
"${PODS_ROOT}/Target Support Files/Pods-KeyboardControllerFabricExample/Pods-KeyboardControllerFabricExample-resources-${CONFIGURATION}-output-files.xcfilelist",
286292
);
293+
outputPaths = (
294+
);
287295
runOnlyForDeploymentPostprocessing = 0;
288296
shellPath = /bin/sh;
289297
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-KeyboardControllerFabricExample/Pods-KeyboardControllerFabricExample-resources.sh\"\n";
@@ -408,8 +416,11 @@
408416
);
409417
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
410418
PRODUCT_NAME = KeyboardControllerFabricExample;
419+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
420+
SUPPORTS_MACCATALYST = NO;
411421
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
412422
SWIFT_VERSION = 5.0;
423+
TARGETED_DEVICE_FAMILY = "1,2";
413424
VERSIONING_SYSTEM = "apple-generic";
414425
};
415426
name = Debug;
@@ -435,7 +446,10 @@
435446
);
436447
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
437448
PRODUCT_NAME = KeyboardControllerFabricExample;
449+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
450+
SUPPORTS_MACCATALYST = NO;
438451
SWIFT_VERSION = 5.0;
452+
TARGETED_DEVICE_FAMILY = "1,2";
439453
VERSIONING_SYSTEM = "apple-generic";
440454
};
441455
name = Release;
@@ -517,10 +531,7 @@
517531
"-DFOLLY_USE_LIBCPP=1",
518532
"-DRN_FABRIC_ENABLED",
519533
);
520-
OTHER_LDFLAGS = (
521-
"$(inherited)",
522-
" ",
523-
);
534+
OTHER_LDFLAGS = "$(inherited) ";
524535
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
525536
SDKROOT = iphoneos;
526537
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
@@ -600,10 +611,7 @@
600611
"-DFOLLY_USE_LIBCPP=1",
601612
"-DRN_FABRIC_ENABLED",
602613
);
603-
OTHER_LDFLAGS = (
604-
"$(inherited)",
605-
" ",
606-
);
614+
OTHER_LDFLAGS = "$(inherited) ";
607615
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
608616
SDKROOT = iphoneos;
609617
USE_HERMES = true;

FabricExample/ios/KeyboardControllerFabricExample/Info.plist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,16 @@
4343
</array>
4444
<key>UISupportedInterfaceOrientations</key>
4545
<array>
46+
<string>UIInterfaceOrientationLandscapeLeft</string>
47+
<string>UIInterfaceOrientationLandscapeRight</string>
4648
<string>UIInterfaceOrientationPortrait</string>
49+
</array>
50+
<key>UISupportedInterfaceOrientations~ipad</key>
51+
<array>
4752
<string>UIInterfaceOrientationLandscapeLeft</string>
4853
<string>UIInterfaceOrientationLandscapeRight</string>
54+
<string>UIInterfaceOrientationPortrait</string>
55+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
4956
</array>
5057
<key>UIViewControllerBasedStatusBarAppearance</key>
5158
<false/>

example/ios/KeyboardControllerExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,11 @@
564564
);
565565
PRODUCT_BUNDLE_IDENTIFIER = com.example.reactnativekeyboardcontroller;
566566
PRODUCT_NAME = KeyboardControllerExample;
567+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
568+
SUPPORTS_MACCATALYST = NO;
567569
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
568570
SWIFT_VERSION = 5.0;
571+
TARGETED_DEVICE_FAMILY = "1,2";
569572
VERSIONING_SYSTEM = "apple-generic";
570573
};
571574
name = Debug;
@@ -588,7 +591,10 @@
588591
);
589592
PRODUCT_BUNDLE_IDENTIFIER = com.example.reactnativekeyboardcontroller;
590593
PRODUCT_NAME = KeyboardControllerExample;
594+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
595+
SUPPORTS_MACCATALYST = NO;
591596
SWIFT_VERSION = 5.0;
597+
TARGETED_DEVICE_FAMILY = "1,2";
592598
VERSIONING_SYSTEM = "apple-generic";
593599
};
594600
name = Release;

example/ios/KeyboardControllerExample/Info.plist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,16 @@
4343
</array>
4444
<key>UISupportedInterfaceOrientations</key>
4545
<array>
46+
<string>UIInterfaceOrientationLandscapeLeft</string>
47+
<string>UIInterfaceOrientationLandscapeRight</string>
4648
<string>UIInterfaceOrientationPortrait</string>
49+
</array>
50+
<key>UISupportedInterfaceOrientations~ipad</key>
51+
<array>
4752
<string>UIInterfaceOrientationLandscapeLeft</string>
4853
<string>UIInterfaceOrientationLandscapeRight</string>
54+
<string>UIInterfaceOrientationPortrait</string>
55+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
4956
</array>
5057
<key>UIViewControllerBasedStatusBarAppearance</key>
5158
<false/>

ios/views/KeyboardControllerView.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ - (void)layoutSubviews
217217
{
218218
[super layoutSubviews];
219219

220-
CGSize screenSize = [UIScreen mainScreen].bounds.size;
220+
UIWindow *window = self.window;
221+
if (!window) {
222+
return;
223+
}
224+
225+
CGSize screenSize = window.bounds.size;
221226
if (CGSizeEqualToSize(screenSize, _lastScreenSize)) {
222227
return;
223228
}

ios/views/KeyboardControllerViewManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class KeyboardControllerView: UIView {
8888
override func layoutSubviews() {
8989
super.layoutSubviews()
9090

91-
let screenSize = UIScreen.main.bounds.size
91+
guard let window = window else { return }
92+
let screenSize = window.bounds.size
9293

9394
if lastScreenSize == screenSize {
9495
return

src/hooks/useWindowDimensions/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { WindowDimensionsEvents } from "../../bindings";
55

66
import type { WindowDimensionsEventData } from "../../types";
77

8-
const screen = Dimensions.get("screen");
8+
const window = Dimensions.get("window");
99

1010
let initialDimensions: WindowDimensionsEventData = {
11-
width: screen.width,
12-
height: screen.height,
11+
width: window.width,
12+
height: window.height,
1313
};
1414

1515
WindowDimensionsEvents.addListener("windowDidResize", (e) => {

0 commit comments

Comments
 (0)