Skip to content

Commit

Permalink
fix: typing for rest styles
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatrun committed Dec 15, 2024
1 parent ec98ab2 commit 74e5a63
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/components/KeyboardAwareScrollView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ const KeyboardAwareScrollView = forwardRef<

const { height } = useWindowDimensions();

const restStyle = (rest?.style && rest?.style?.[0] || {})
const inverted = "transform" in restStyle ? restStyle.transform[0]?.scale === -1 : false
const restStyle = (Array.isArray(rest.style) && rest.style?.[0]) || {};
const scaleStyle =
"transform" in restStyle &&
(restStyle?.transform?.[0] as { scale?: number });
const inverted = (scaleStyle && scaleStyle?.scale === -1) || false;

const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {
if (typeof ref === "function") {
Expand Down Expand Up @@ -351,23 +354,22 @@ const KeyboardAwareScrollView = forwardRef<
[],
);

const view = useAnimatedStyle(
() => {
const invertedOffset = inverted ? -extraKeyboardSpace : 0;
return enabled
? {
// animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)
// this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
// by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
// from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
// re-calculation on every animation frame and it helps to achieve smooth animation.
// see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
paddingBottom: currentKeyboardFrameHeight.value + invertedOffset + 1,
}
: {}
},
[enabled],
);
const view = useAnimatedStyle(() => {
const invertedOffset = inverted ? -extraKeyboardSpace : 0;

return enabled
? {
// animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)
// this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
// by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
// from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
// re-calculation on every animation frame and it helps to achieve smooth animation.
// see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
paddingBottom:
currentKeyboardFrameHeight.value + invertedOffset + 1,
}
: {};
}, [enabled]);

return (
<ScrollViewComponent
Expand Down

0 comments on commit 74e5a63

Please sign in to comment.