File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import {
2323 useWindowDimensions ,
2424} from "../../hooks" ;
2525import { findNodeHandle } from "../../utils/findNodeHandle" ;
26+ import useCombinedRef from "../hooks/useCombinedRef" ;
2627
2728import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler" ;
2829import { debounce , scrollDistanceWithRespectToSnapPoints } from "./utils" ;
@@ -127,6 +128,7 @@ const KeyboardAwareScrollView = forwardRef<
127128 ) => {
128129 const scrollViewAnimatedRef = useAnimatedRef < Reanimated . ScrollView > ( ) ;
129130 const scrollViewRef = React . useRef < ScrollView > ( null ) ;
131+ const onRef = useCombinedRef ( scrollViewAnimatedRef , scrollViewRef ) ;
130132 const scrollViewTarget = useSharedValue < number | null > ( null ) ;
131133 const scrollPosition = useSharedValue ( 0 ) ;
132134 const position = useScrollViewOffset ( scrollViewAnimatedRef ) ;
@@ -143,11 +145,6 @@ const KeyboardAwareScrollView = forwardRef<
143145
144146 const { height } = useWindowDimensions ( ) ;
145147
146- const onRef = useCallback ( ( assignedRef : Reanimated . ScrollView ) => {
147- scrollViewRef . current = assignedRef ;
148-
149- scrollViewAnimatedRef ( assignedRef ) ;
150- } , [ ] ) ;
151148 const onScrollViewLayout = useCallback (
152149 ( e : LayoutChangeEvent ) => {
153150 scrollViewTarget . value = findNodeHandle ( scrollViewAnimatedRef . current ) ;
Original file line number Diff line number Diff line change 1+ import { useCallback } from "react" ;
2+
3+ import type { Ref , RefCallback } from "react" ;
4+
5+ const useCombinedRef = < T > ( ...refs : Ref < T > [ ] ) : RefCallback < T > => {
6+ return useCallback ( ( value : T | null ) => {
7+ for ( const ref of refs ) {
8+ if ( ! ref ) {
9+ continue ;
10+ }
11+
12+ if ( typeof ref === "function" ) {
13+ ref ( value ) ;
14+ } else {
15+ ref . current = value ;
16+ }
17+ }
18+ // eslint-disable-next-line react-compiler/react-compiler
19+ } , refs ) ;
20+ } ;
21+
22+ export default useCombinedRef ;
You can’t perform that action at this time.
0 commit comments