Skip to content

Commit

Permalink
fix(android): issue with safearea insets top
Browse files Browse the repository at this point in the history
  • Loading branch information
EQuimper committed Jun 17, 2024
1 parent 16c1fb6 commit 8681738
Show file tree
Hide file tree
Showing 4 changed files with 10,426 additions and 18,397 deletions.
105 changes: 85 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"react-native": "0.73.6",
"react-native-builder-bob": "^0.23.2",
"react-native-reanimated": "^3.11.0",
"react-native-safe-area-context": "^4.10.5",
"release-it": "^15.0.0",
"typescript": "^5.2.2"
},
Expand All @@ -80,7 +81,8 @@
"peerDependencies": {
"react": "*",
"react-native": "*",
"react-native-reanimated": ">=2.0.0"
"react-native-reanimated": ">=2.0.0",
"react-native-safe-area-context": "*"
},
"workspaces": [
"example"
Expand Down
19 changes: 11 additions & 8 deletions src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
wrapperViewRefAtom,
} from './state';
import { useKeyboard } from './useKeyboard';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

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

Expand Down Expand Up @@ -120,6 +121,7 @@ export function useFormSmartScroll({
}: {
padding?: number;
} = {}) {
const insets = useSafeAreaInsets();
const wrapperOffset = useAtomValue(wrapperOffsetAtom);
const scrollY = useSharedValue(0);
const scrollRef = useAnimatedRef<Animated.ScrollView>();
Expand All @@ -141,14 +143,15 @@ export function useFormSmartScroll({
_keyboard.coordinates.end.screenY - currentFocus.height * 2
) {
if (wrapperOffset) {
const diff = Math.abs(
_keyboard.coordinates.end.screenY -
currentFocus.position -
currentFocus.height -
padding +
scrollY.value -
wrapperOffset
);
const diff =
Math.abs(
_keyboard.coordinates.end.screenY -
currentFocus.position -
currentFocus.height -
padding +
scrollY.value -
wrapperOffset
) + insets.top;
return -diff;
}

Expand Down
Loading

0 comments on commit 8681738

Please sign in to comment.