Is modifying a native module/component like ScrollView in react native only possible via building from source?

47 views Asked by At

So i need some custom functionality in a certain native Android component, Reading RN documentation i found 2 ways of doing so:

  1. Editing react native code and building from source.

  2. Making a library that implements the native component, modifying it there and importing it in my project.

I don't know if I'm missing some other way, like if i go to my project's /android/src/java/… and just make a module there, will it work ?

Specifically i want to alter horizontal ScrollView behavior (paging enabled) to only 'listen' to explicit horizontal swipe gestures and not diagonal or fling

For example, when scrolling vertically some text and u swipe a little diagonally, it changes page instead of only scrolling inside.

I spent 2-3 days building from source and always bumped into different errors so i gave up. Now I'm trying to understand how the second way works, but I'm in the dark. learning as I'm doing it.

PS: i have experience both in react native (~1y) and android (~2y)

1

There are 1 answers

0
Kirill Novikov On

Technically you are right - you can build your own implementation of any native side you want and you can patch RN (for example with https://www.npmjs.com/package/patch-package)

However, patching RN base components is not a good practice because it would be very difficult to support updates to the next RN versions.

Regarding your problem, you can try to use this gesture handler https://docs.swmansion.com/react-native-gesture-handler/ instead of RN implementation.