react-native-modalize icon indicating copy to clipboard operation
react-native-modalize copied to clipboard

Unable to scrollToIndex

Open austinGENEreeve opened this issue 1 year ago • 3 comments

Unable to use the ref to scrollToIndex({ index: 0 ... within the modal

Goal is to reset the scroll position to the top when the modal is "alwaysOpen" closed.

Reproduce


  const mapRef = useRef(null);
  
  ...

<Modalize
          ref={modalRef}
          modalHeight={height - 80}
          alwaysOpen={100}
          disableScrollIfPossible={true}
          onPositionChange={(pos) => {
            if(pos !== 'top') {
              modalRef?.current?.scrollToIndex({ index: 0, animated: true });
            }
          }}
          threshold={40}
        > ... </Modalize>
Error: scrollToIndex is not a function. 

Dependencies:

  • react-native-modalize [e.g. 1.3.7-rc.19]
  • react-native [e.g. 0.62.0]
  • react-native-gesture-handler [e.g. 1.6.0]
  • expo/react-navigation/react-native-navigation: [e.g. [email protected]]

austinGENEreeve avatar Aug 11 '22 21:08 austinGENEreeve

suggestion in #125 doesn't seem to work

austinGENEreeve avatar Aug 11 '22 21:08 austinGENEreeve

i guess the refs are different between the scrollview/flatlist and the bottomsheet itself. You may try to use contentRef like documented here

masbossun avatar Sep 12 '22 12:09 masbossun

i guess the refs are different between the scrollview/flatlist and the bottomsheet itself. You may try to use contentRef like documented here

I'm using contentRef with SectionList, but contentRef always undefined. I can not use SectionList methods.

thanhnn-bap-jp avatar Sep 16 '22 07:09 thanhnn-bap-jp

I was able to get it to work by using a contentRef

` <Modalize contentRef={contentRef} ....

contentRef?.current?.scrollTo({ x: 0, y: 0, animated: true }); `

austinGENEreeve avatar Sep 23 '22 20:09 austinGENEreeve