Skip to content

Commit 8eda19e

Browse files
committed
feat: native rounded keyboard detection
1 parent 7855994 commit 8eda19e

8 files changed

Lines changed: 33 additions & 8 deletions

File tree

android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class KeyboardControllerModule(
1111

1212
override fun getName(): String = KeyboardControllerModuleImpl.NAME
1313

14+
override fun getConstants(): MutableMap<String, Any> = mutableMapOf("keyboardBorderRadius" to 0)
15+
1416
override fun setInputMode(mode: Double) {
1517
module.setInputMode(mode.toInt())
1618
}

android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class KeyboardControllerModule(
1313

1414
override fun getName(): String = KeyboardControllerModuleImpl.NAME
1515

16+
override fun getConstants(): MutableMap<String, Any> = mutableMapOf("keyboardBorderRadius" to 0)
17+
1618
@ReactMethod
1719
fun setInputMode(mode: Int) {
1820
module.setInputMode(mode)

ios/KeyboardControllerModule.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ + (BOOL)requiresMainQueueSetup
5353
return NO;
5454
}
5555

56+
- (NSDictionary *)constantsToExport
57+
{
58+
return @{
59+
@"keyboardBorderRadius" : @([KeyboardExtenderContainerView keyboardBorderRadius]),
60+
};
61+
}
62+
5663
#ifdef RCT_NEW_ARCH_ENABLED
5764
- (void)setDefaultMode
5865
#else

ios/views/KeyboardExtenderContainerView.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@ import UIKit
99

1010
@objc
1111
public class KeyboardExtenderContainerView: NSObject {
12-
@objc public static func create(frame: CGRect, contentView: UIView) -> UIView {
12+
private static func usesModernKeyboard() -> Bool {
1313
#if canImport(UIKit.UIGlassEffect)
1414
if #available(iOS 26.0, *) {
1515
let requiresCompat = Bundle.main.object(forInfoDictionaryKey: "UIDesignRequiresCompatibility") as? Bool ?? false
16-
if !requiresCompat {
17-
return ModernContainerView(frame: frame, contentView: contentView)
18-
}
16+
return !requiresCompat
1917
}
2018
#endif
19+
return false
20+
}
21+
22+
@objc public static func keyboardBorderRadius() -> CGFloat {
23+
return usesModernKeyboard() ? 30 : 0
24+
}
2125

26+
@objc public static func create(frame: CGRect, contentView: UIView) -> UIView {
27+
if usesModernKeyboard() {
28+
if #available(iOS 26.0, *) {
29+
return ModernContainerView(frame: frame, contentView: contentView)
30+
}
31+
}
2232
return LegacyContainerView(frame: frame, contentView: contentView)
2333
}
2434
}

src/bindings.native.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export const KeyboardControllerNative = (
3636
)
3737
) as KeyboardControllerNativeModule;
3838

39+
export const keyboardBorderRadius: number =
40+
RCTKeyboardController?.getConstants()?.keyboardBorderRadius ?? 0;
41+
3942
const KEYBOARD_CONTROLLER_NAMESPACE = "KeyboardController::";
4043
const eventEmitter = new NativeEventEmitter(KeyboardControllerNative);
4144

src/bindings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import type { EmitterSubscription } from "react-native";
1717

1818
const NOOP = () => {};
1919

20+
export const keyboardBorderRadius: number = 0;
21+
2022
export const KeyboardControllerNative: KeyboardControllerNativeModule = {
2123
setDefaultMode: NOOP,
2224
setInputMode: NOOP,

src/components/KeyboardToolbar/constants.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Platform } from "react-native";
1+
import { keyboardBorderRadius } from "../../bindings";
22

33
import type { HEX } from "./types";
44

@@ -10,6 +10,5 @@ export const TEST_ID_KEYBOARD_TOOLBAR_DONE = `${TEST_ID_KEYBOARD_TOOLBAR}.done`;
1010

1111
export const KEYBOARD_TOOLBAR_HEIGHT = 42;
1212
export const DEFAULT_OPACITY: HEX = "FF";
13-
export const KEYBOARD_HAS_ROUNDED_CORNERS =
14-
Platform.OS === "ios" && parseInt(Platform.Version, 10) >= 26;
13+
export const KEYBOARD_HAS_ROUNDED_CORNERS = keyboardBorderRadius > 0;
1514
export const OPENED_OFFSET = KEYBOARD_HAS_ROUNDED_CORNERS ? -11 : 0;

src/specs/NativeKeyboardController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TurboModuleRegistry } from "react-native";
33
import type { TurboModule } from "react-native";
44

55
export interface Spec extends TurboModule {
6-
readonly getConstants: () => {};
6+
readonly getConstants: () => { keyboardBorderRadius: number };
77

88
// methods
99
setInputMode(mode: number): void;

0 commit comments

Comments
 (0)