From b1462329d33e31b21460fb1a672fadd0555a1fe0 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Sun, 17 Nov 2024 16:38:14 +0100 Subject: [PATCH 1/2] feat: detect react-native-edge-to-edge --- packages/react-native-avoid-softinput/package.json | 3 +++ .../src/AvoidSoftInput.ts | 10 +++++++++- yarn.lock | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/react-native-avoid-softinput/package.json b/packages/react-native-avoid-softinput/package.json index 2c39853..f3a21f6 100644 --- a/packages/react-native-avoid-softinput/package.json +++ b/packages/react-native-avoid-softinput/package.json @@ -55,6 +55,9 @@ "build-library": "bob build", "release-library": "release-it" }, + "dependencies": { + "react-native-is-edge-to-edge": "^1.1.6" + }, "devDependencies": { "@release-it/conventional-changelog": "8.0.2", "@types/react": "18.3.12", diff --git a/packages/react-native-avoid-softinput/src/AvoidSoftInput.ts b/packages/react-native-avoid-softinput/src/AvoidSoftInput.ts index c2b8315..47ba636 100644 --- a/packages/react-native-avoid-softinput/src/AvoidSoftInput.ts +++ b/packages/react-native-avoid-softinput/src/AvoidSoftInput.ts @@ -1,9 +1,12 @@ import type { EmitterSubscription } from 'react-native'; import { NativeEventEmitter, Platform } from 'react-native'; +import { controlEdgeToEdgeValues, isEdgeToEdge } from 'react-native-is-edge-to-edge'; import module from './AvoidSoftInputModule'; import type { SoftInputAppliedOffsetEventData, SoftInputEasing, SoftInputEventData } from './types'; +const EDGE_TO_EDGE = isEdgeToEdge(); + const eventEmitter = new NativeEventEmitter(Platform.OS !== 'ios' ? undefined : module); /** @@ -51,7 +54,12 @@ function setShouldMimicIOSBehavior(shouldMimic: boolean) { return; } - module.setShouldMimicIOSBehavior(shouldMimic); + if (__DEV__) { + // Will print "setShouldMimicIOSBehavior value is ignored when using react-native-edge-to-edge" + controlEdgeToEdgeValues({ setShouldMimicIOSBehavior: shouldMimic }); + } + + module.setShouldMimicIOSBehavior(EDGE_TO_EDGE || shouldMimic); } /** diff --git a/yarn.lock b/yarn.lock index dd97c82..01bedad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13100,6 +13100,7 @@ __metadata: react: "npm:18.3.1" react-native: "npm:0.76.0" react-native-builder-bob: "npm:0.30.2" + react-native-is-edge-to-edge: "npm:^1.1.6" release-it: "npm:17.6.0" typescript: "npm:5.0.4" peerDependencies: @@ -13155,6 +13156,16 @@ __metadata: languageName: node linkType: hard +"react-native-is-edge-to-edge@npm:^1.1.6": + version: 1.1.6 + resolution: "react-native-is-edge-to-edge@npm:1.1.6" + peerDependencies: + react: ">=18.2.0" + react-native: ">=0.73.0" + checksum: 10/4e07c1e34c01c8d50fd7c1d0460db06f6f0515197405230386a8ffb950cb724b10743af032310d1384df0a90059bfb8992ba2d93344ce86315315f0493feccc2 + languageName: node + linkType: hard + "react-native-reanimated@npm:3.16.1": version: 3.16.1 resolution: "react-native-reanimated@npm:3.16.1" From 10adbcb9eff79323dd62bb453fef99f6debc8fb3 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Sun, 17 Nov 2024 16:46:27 +0100 Subject: [PATCH 2/2] fix: avoid an useless function call --- .../react-native-avoid-softinput/src/AvoidSoftInput.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/react-native-avoid-softinput/src/AvoidSoftInput.ts b/packages/react-native-avoid-softinput/src/AvoidSoftInput.ts index 47ba636..12cb8f1 100644 --- a/packages/react-native-avoid-softinput/src/AvoidSoftInput.ts +++ b/packages/react-native-avoid-softinput/src/AvoidSoftInput.ts @@ -53,13 +53,12 @@ function setShouldMimicIOSBehavior(shouldMimic: boolean) { if (Platform.OS !== 'android') { return; } - if (__DEV__) { - // Will print "setShouldMimicIOSBehavior value is ignored when using react-native-edge-to-edge" - controlEdgeToEdgeValues({ setShouldMimicIOSBehavior: shouldMimic }); + controlEdgeToEdgeValues({ shouldMimic }); + } + if (!EDGE_TO_EDGE) { + module.setShouldMimicIOSBehavior(shouldMimic); } - - module.setShouldMimicIOSBehavior(EDGE_TO_EDGE || shouldMimic); } /**