Skip to content

Commit

Permalink
refactor: reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Feb 24, 2025
1 parent 0b8d1cb commit 380b8fa
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/components/KeyboardAvoidingView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ const KeyboardAvoidingView = forwardRef<

return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
}, [screenHeight, keyboardVerticalOffset]);
const interpolateToRelativeKeyboardHeight = useCallback(
(value: number) => {
"worklet";

return interpolate(value, [0, 1], [0, relativeKeyboardHeight()]);
},
[relativeKeyboardHeight],
);

const onLayoutWorklet = useCallback((layout: LayoutRectangle) => {
"worklet";
Expand All @@ -115,21 +123,9 @@ const KeyboardAvoidingView = forwardRef<
);

const animatedStyle = useAnimatedStyle(() => {
const bottom = interpolate(
keyboard.progress.value,
[0, 1],
[0, relativeKeyboardHeight()],
);
const translateY = interpolate(
translate.value,
[0, 1],
[0, relativeKeyboardHeight()],
);
const paddingBottom = interpolate(
padding.value,
[0, 1],
[0, relativeKeyboardHeight()],
);
const bottom = interpolateToRelativeKeyboardHeight(keyboard.progress.value);

Check failure on line 126 in src/components/KeyboardAvoidingView/index.tsx

View workflow job for this annotation

GitHub Actions / 🔎 Lint TS

Replace `keyboard.progress.value` with `⏎········keyboard.progress.value,⏎······`
const translateY = interpolateToRelativeKeyboardHeight(translate.value);
const paddingBottom = interpolateToRelativeKeyboardHeight(padding.value);
const bottomHeight = enabled ? bottom : 0;

switch (behavior) {
Expand Down Expand Up @@ -158,7 +154,7 @@ const KeyboardAvoidingView = forwardRef<
default:
return {};
}
}, [behavior, enabled, relativeKeyboardHeight]);
}, [behavior, enabled, interpolateToRelativeKeyboardHeight]);
const isPositionBehavior = behavior === "position";
const containerStyle = isPositionBehavior ? contentContainerStyle : style;
const combinedStyles = useMemo(
Expand Down

0 comments on commit 380b8fa

Please sign in to comment.