r/reactnative • • Jul 18 '22

Help Is it possible to modify the native code of packages?

Been having some issues on android with a couple packages and was hoping to be able to make some changes to the java/kotlin code in them and test that out. What is involved in doing that? Make the change, npm install then build it again? Seems like that isn't really working.

Same question for React Native itself. If I wanted to make changes to iOS and Android native code inside React Native and try that what would be required?

3 Upvotes

10 comments sorted by

14

u/kbcool iOS & Android Jul 18 '22

Fork the project on git, make changes, push to GitHub and install the package from git: https://stackoverflow.com/questions/17509669/how-to-install-an-npm-package-from-github-directly

Don't forget to submit a pull request against the original project to add your feature/bug to the master branch.

2

u/ForsakenMolasses4408 Jul 19 '22

awesome idea thanks for that!

1

u/OsagieTheGreat Jul 22 '22

to add your bug to the master branch

i laughed so hard

11

u/Saf94 Jul 18 '22

1

u/ForsakenMolasses4408 Jul 19 '22

been my main approach but doesn't seem to work in all cases, which made me thing there was some wacky build magic happening

1

u/BlueDistribution16 Jul 18 '22

Dont do Npm install, change the package then run a native build again. Downloading the node modules would of course override the changes you've made so you probably need to patch with with a shell script or something which can be called in the post install to apply it every time you download that package again.

1

u/ForsakenMolasses4408 Jul 19 '22

that makes sense thanks for the reply!

1

u/Ok-Season-2644 Jul 19 '22

You could fork the package, apply your changes and replace the version of the package in your package.json with your package url

0

u/slackademic Jul 18 '22

You can patch a package JavaScript without issue and change the native component or native module that is looked up, and point it to one defined by you.

For example, you can patch-package react native to change RCTView to instead look for RCTMyView, which you then define and extend RCTView.

This can be done if you want to use your own implementation instead of the one provided.

1

u/ForsakenMolasses4408 Jul 19 '22

I have been using patch-package a fair bit but wasn't working in all cases so though maybe there is something else happening that I am not aware of.

I'll be exploring patch package more based on these comments so thank you :)