APSL / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
MIT License
5.24k stars 643 forks source link

scrollToFocusedInput does not work/ exists anymore on the props #553

Open NiharR27 opened 1 year ago

NiharR27 commented 1 year ago

Using: "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native": "0.67.4" Replicated with: iOS and Android devices.

Code:

const scrollToInput = React.useCallback((reactNode: number | null) => {

    currentInputScroll.current._internalFiberInstanceHandleDEV.memoizedProps.scrollToFocusedInput( 
      reactNode,
    );
  }, []);

<KeyboardAwareScrollView
   keyboardOpeningTime={0}
    enableOnAndroid={true}
    innerRef={(ref: any) => (currentInputScroll.current = ref)}>
<View>
......
<TextInput onFocus={(event: any) => scrollToInput(findNodeHandle(event.target))}> </TextInput> 
</View>
</KeyboardAwareScrollView>

Problem:

Readme suggested to use:

  // Add a 'scroll' ref to your ScrollView
  this.scroll.props.scrollToFocusedInput(reactNode)
}

Here, the currentInputScroll.current no longer has props inside it, and looking at Stack Overflow, i found the example to use

._internalFiberInstanceHandleDEV.memoizedProps.scrollToFocusedInput( 
      reactNode,
    );

which does not work either....

Console logging currentInputScroll.current inside the scrollToInput callback gives:

Screen Shot 2022-08-13 at 9 28 27 am

The problem is that the scroll works when you click the first text input, but when you hit the second text input, it doesn't go to that text input and rather jumps the scroll to the first one... I console logged the findNodeHandle(event.target) and that seem to give correct number (in terms of increasing as you click the text input below... Any idea why?

luluhoc commented 1 year ago

https://github.com/APSL/react-native-keyboard-aware-scroll-view/issues/451#issuecomment-772330068

jordzawada commented 1 year ago

I sort of have this working. The issue is it only puts the input to the top of screen and I need it in the middle.

this.scrollRef.scrollTo({ y: findNodeHandle(reactNode), animated: true });