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
import module
import ToastAndroid from 'react-native-toast';
call function
ToastAndroid.show('Awesome', ToastAndroid.SHORT);
SHORT time
ToastAndroid.SHORT
Long time
ToastAndroid.LONG
ToastModule.java
-
Inherit ReactContextBaseJavaModule and implement below method
-
assign module Name
@Override
public String getName() {
return "ToastAndroid";
}
- 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
-
Inherit ReactContextBaseJavaModule and implement below method
-
code to register modules
@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new ToastModule(reactContext));
return modules;
}