Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28463

Custom Native Module stoped working on android after upgrading to react native 0.61

$
0
0

I upgraded my react native to 0.61.2 from 0.59.9, ever since then, I cannot use my custom native modules on android.

Tried to use the code from the guide in react native ( https://facebook.github.io/react-native/docs/native-modules-android ) to see if something changed in the new version of RN, but I keep getting

   TypeError: Cannot read property 'show' of undefined.

This is the basic of my code:

ToastModule.java

        public class ToastModule extends ReactContextBaseJavaModule {

        ...

        @Override
        public String getName() {
            return "ToastExample";
        }

        @ReactMethod
        public void show(String message, int duration) {
            Toast.makeText(getReactApplicationContext(), message, duration).show();
        }

        }

CustomToastPackage.java

        public class CustomToastPackage implements ReactPackage {
        ...
            @Override
            public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
                return Arrays.<NativeModule>asList(new ToastModule(reactContext));
            }

        }

MainApplication.java

        ...

        import com.xxx.CustomToastPackage;

        public class MainApplication extends NavigationApplication {

        ...

            @Nullable
            @Override
            public List<ReactPackage> createAdditionalReactPackages() {
                return new PackageList(this).getPackages();
            }

            protected List<ReactPackage> getPackages() {
                List<ReactPackage> packages = new ArrayList<>();
                packages.add(new IntercomPackage());
                packages.add(new CustomToastPackage());
                return packages;
            }


        }

example.js

        import {NativeModules} from 'react-native';
        NativeModules.ToastExample.show("test", NativeModules.ToastExample.DURATION_SHORT_KEY)

When tried to debug in JS, I see that the NativeModules object exported from react-native really doesn't have the desired modules.

It's critical for me to get native modules working.

What am I missing?


Viewing all articles
Browse latest Browse all 28463

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>