Skip to content

Commit 8681738

Browse files
committed
fix(android): issue with safearea insets top
1 parent 16c1fb6 commit 8681738

File tree

4 files changed

+10426
-18397
lines changed

4 files changed

+10426
-18397
lines changed

package-lock.json

Lines changed: 85 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"react-native": "0.73.6",
7272
"react-native-builder-bob": "^0.23.2",
7373
"react-native-reanimated": "^3.11.0",
74+
"react-native-safe-area-context": "^4.10.5",
7475
"release-it": "^15.0.0",
7576
"typescript": "^5.2.2"
7677
},
@@ -80,7 +81,8 @@
8081
"peerDependencies": {
8182
"react": "*",
8283
"react-native": "*",
83-
"react-native-reanimated": ">=2.0.0"
84+
"react-native-reanimated": ">=2.0.0",
85+
"react-native-safe-area-context": "*"
8486
},
8587
"workspaces": [
8688
"example"

src/Provider.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
wrapperViewRefAtom,
3838
} from './state';
3939
import { useKeyboard } from './useKeyboard';
40+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
4041

4142
const isAndroid = Platform.OS === 'android';
4243

@@ -120,6 +121,7 @@ export function useFormSmartScroll({
120121
}: {
121122
padding?: number;
122123
} = {}) {
124+
const insets = useSafeAreaInsets();
123125
const wrapperOffset = useAtomValue(wrapperOffsetAtom);
124126
const scrollY = useSharedValue(0);
125127
const scrollRef = useAnimatedRef<Animated.ScrollView>();
@@ -141,14 +143,15 @@ export function useFormSmartScroll({
141143
_keyboard.coordinates.end.screenY - currentFocus.height * 2
142144
) {
143145
if (wrapperOffset) {
144-
const diff = Math.abs(
145-
_keyboard.coordinates.end.screenY -
146-
currentFocus.position -
147-
currentFocus.height -
148-
padding +
149-
scrollY.value -
150-
wrapperOffset
151-
);
146+
const diff =
147+
Math.abs(
148+
_keyboard.coordinates.end.screenY -
149+
currentFocus.position -
150+
currentFocus.height -
151+
padding +
152+
scrollY.value -
153+
wrapperOffset
154+
) + insets.top;
152155
return -diff;
153156
}
154157

0 commit comments

Comments
 (0)