From 72b12d0370964865f1b6a137523b3c769b29cea8 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Thu, 4 Apr 2024 10:24:34 +0100 Subject: [PATCH 1/3] fix: missing `onScroll` event in `KeyboardAwareScrollView` --- .prettierignore | 2 ++ src/components/KeyboardAwareScrollView/index.tsx | 10 ++++++++-- tea.yaml | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.prettierignore b/.prettierignore index b8b9f386ec..81be941634 100644 --- a/.prettierignore +++ b/.prettierignore @@ -16,3 +16,5 @@ FabricExample/ios/build/ FabricExample/src/**/Lottie/*.json android/build/ + +tea.yaml diff --git a/src/components/KeyboardAwareScrollView/index.tsx b/src/components/KeyboardAwareScrollView/index.tsx index 84e3ebcc23..51d26f074b 100644 --- a/src/components/KeyboardAwareScrollView/index.tsx +++ b/src/components/KeyboardAwareScrollView/index.tsx @@ -2,6 +2,7 @@ import React, { forwardRef, useCallback, useMemo } from "react"; import { findNodeHandle, useWindowDimensions } from "react-native"; import Reanimated, { interpolate, + runOnJS, scrollTo, useAnimatedReaction, useAnimatedRef, @@ -83,6 +84,7 @@ const KeyboardAwareScrollView = forwardRef< bottomOffset = 0, disableScrollOnKeyboardHide = false, enabled = true, + onScroll: onScrollProps, ...rest }, ref, @@ -106,6 +108,11 @@ const KeyboardAwareScrollView = forwardRef< { onScroll: (e) => { position.value = e.contentOffset.y; + + if (onScrollProps) { + // @ts-expect-error we can not pass currentTarget, bubbles and other properties + runOnJS(onScrollProps)({ nativeEvent: e }); + } }, }, [], @@ -320,8 +327,7 @@ const KeyboardAwareScrollView = forwardRef< ref={onRef} {...rest} onLayout={onScrollViewLayout} - // @ts-expect-error `onScrollReanimated` is a fake prop needed for reanimated to intercept scroll events - onScrollReanimated={onScroll} + onScroll={onScroll} scrollEventThrottle={16} > {children} diff --git a/tea.yaml b/tea.yaml index 0790aa2aa6..6c26f2e60b 100644 --- a/tea.yaml +++ b/tea.yaml @@ -2,5 +2,5 @@ --- version: 1.0.0 codeOwners: - - "0xeeF83F6BC5a2bC68A29F6e075e7780Aaa928FD5A" + - '0xeeF83F6BC5a2bC68A29F6e075e7780Aaa928FD5A' quorum: 1 From f6ebd3408bf4841929a37180f94a53d8f6812749 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Thu, 4 Apr 2024 21:12:16 +0100 Subject: [PATCH 2/3] fix: added missing dependency --- src/components/KeyboardAwareScrollView/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/KeyboardAwareScrollView/index.tsx b/src/components/KeyboardAwareScrollView/index.tsx index 51d26f074b..ce921b85d9 100644 --- a/src/components/KeyboardAwareScrollView/index.tsx +++ b/src/components/KeyboardAwareScrollView/index.tsx @@ -115,7 +115,7 @@ const KeyboardAwareScrollView = forwardRef< } }, }, - [], + [onScrollProps], ); const onRef = useCallback((assignedRef: Reanimated.ScrollView) => { From a3c3d10e4d411181c51693dd8e64d6da1b942a72 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Thu, 4 Apr 2024 22:01:39 +0100 Subject: [PATCH 3/3] feat: try to use js-scroll based solution --- src/components/KeyboardAwareScrollView/index.tsx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/components/KeyboardAwareScrollView/index.tsx b/src/components/KeyboardAwareScrollView/index.tsx index ce921b85d9..353f67de5f 100644 --- a/src/components/KeyboardAwareScrollView/index.tsx +++ b/src/components/KeyboardAwareScrollView/index.tsx @@ -2,11 +2,9 @@ import React, { forwardRef, useCallback, useMemo } from "react"; import { findNodeHandle, useWindowDimensions } from "react-native"; import Reanimated, { interpolate, - runOnJS, scrollTo, useAnimatedReaction, useAnimatedRef, - useAnimatedScrollHandler, useAnimatedStyle, useSharedValue, } from "react-native-reanimated"; @@ -104,16 +102,11 @@ const KeyboardAwareScrollView = forwardRef< const { height } = useWindowDimensions(); - const onScroll = useAnimatedScrollHandler( - { - onScroll: (e) => { - position.value = e.contentOffset.y; + const onScroll = useCallback>( + (event) => { + position.value = event.nativeEvent.contentOffset.y; - if (onScrollProps) { - // @ts-expect-error we can not pass currentTarget, bubbles and other properties - runOnJS(onScrollProps)({ nativeEvent: e }); - } - }, + onScrollProps?.(event); }, [onScrollProps], );