Skip to content

Sample implementation of native modules in react-native

Notifications You must be signed in to change notification settings

avinash2fly/react-native-toast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-toast

cd /Example to test the sample code

steps:

npm install
react-native run-android

to import this library

npm install git+https://github.com/avinash2fly/react-native-toast.git

How to integrate in project

import module

import ToastAndroid from 'react-native-toast';

call function

ToastAndroid.show('Awesome', ToastAndroid.SHORT);

SHORT time

ToastAndroid.SHORT

Long time

ToastAndroid.LONG

How to create native modules

ToastModule.java

  1. Inherit ReactContextBaseJavaModule and implement below method

  2. assign module Name

@Override
  public String getName() {
    return "ToastAndroid";
  }
  1. define method
@ReactMethod
public void show(String message, int duration) {
  Toast.makeText(getReactApplicationContext(), message, duration).show();
}

ReactPackage.java

It is used to register module with react

  1. Inherit ReactContextBaseJavaModule and implement below method

  2. code to register modules

@Override
  public List<NativeModule> createNativeModules(
                              ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new ToastModule(reactContext));

    return modules;
  }

About

Sample implementation of native modules in react-native

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published