slorber / react-native-scroll-into-view

Scroll a ReactNative View into the visible screen. Similar to DOMElement.scrollIntoView() browser function.
https://thisweekinreact.com
MIT License
415 stars 13 forks source link

Not working in Android #34

Closed darshanksexathought closed 3 years ago

darshanksexathought commented 3 years ago

tried implementing the basic scenario in android , the basic example is not working it always stays in the top , I tried with different items when we call scrollIntoView(viewRef.current) it will take us to top of the screen instead the the ref that we provided it works perfectly fine in IOS but not in android parent component `const CustomScrollView = wrapScrollView(ScrollView);

` chile component SignupScreen ``` const scrollIntoView = useScrollIntoView(); const viewRef = useRef(null) return <>
slorber commented 3 years ago

I've upgraded the examples recently and tested with Android and it worked. Also integrated this lib with an Android app recently and also worked.

Please test the repo examples, run yarn start (it's an expo app) and let me know if this does not work. If it does, it means the problem is more likely in your integration code, and I can't help if you can't provide a full Expo repro.

darshanksexathought commented 3 years ago

@slorber i think i got the issue it was with the view in android adding this renderToHardwareTextureAndroid to view worked thanks for the response though

slorber commented 3 years ago

great, don't hesitate to send a doc PR or whatever if you feel it's useful

Stevemoretz commented 3 years ago

Well if you don't use renderToHardwareTextureAndroid then it won't work.

slorber commented 3 years ago

Did it break on recent RN versions?

Because last time I checked on Android it was working (Expo SDK 41 / RN 0.61). But I only have 1 Android device to test.

Stevemoretz commented 3 years ago

Did it break on recent RN versions?

Because last time I checked on Android it was working (Expo SDK 41 / RN 0.61). But I only have 1 Android device to test.

Hi thanks for the response I'm using sdk 42 and tried with a bunch of different andorid versions one physical Android 7 and the rest simulators from Android 8 to 10, all failed to move, however if you add one style to the component that you are getting the ref from and add opacity of over 1 eg: style={{opacity:1.1}} it works.

adding renderToHardwareTextureAndroid fixes this as well, but I wouldn't use it.

I'm almost certain the issue is about the measure function you are using, if you could check what it returns and it returns all undefined that is the exact issue.

MateuszRostkowski commented 1 year ago

Hi

I'm using it with expo 47 (RN 0.70.5), and adding renderToHardwareTextureAndroid resolves issues with android.

As said in the react-native documentation this prop should be used to small components so I have do it like so:

<>
  <View renderToHardwareTextureAndroid ref={viewRef} />
  <Component />
</>

On iOS it works out of the box.