Skip to content

A toast that can be used for react-native, while available for native android and ios

License

Notifications You must be signed in to change notification settings

listenzz/react-native-toast-hybrid

Repository files navigation

react-native-toast-hybrid

A toast that can be used for react-native, while available for native android, ios.

ios-hud

Installation

yarn add react-native-toast-hybrid

Usage

example

// Use in react code.

import { useToast } from 'react-native-toast-hybrid'

const toast = useToast()

text() {
    toast.text('Hello World!!')
}

info() {
    toast.info('A long long message to tell you.')
}

done() {
    toast.done('Work is done!')
}

error() {
    toast.error('Maybe somthing is wrong!')
}

As the word Hybrid implies, use in native is also supported.

// Use in iOS native code

- (IBAction)showText:(UIButton *)sender {
    [Toast text:@"Hello Native!"];
}

- (IBAction)showInfo:(UIButton *)sender {
    [Toast info:@"A long long message to tell you."];
}

- (IBAction)showDone:(UIButton *)sender {
    [Toast done:@"Work is done!"];
}

- (IBAction)showError:(UIButton *)sender {
    [Toast error:@"Maybe somthing is wrong!"];
}
// Use in Android native code

root.findViewById(R.id.text).setOnClickListener(v -> {
    Toast.text(requireActivity(), "Hello Native!");
});

root.findViewById(R.id.info).setOnClickListener(v -> {
    Toast.info(requireActivity(), "A long long message to tell you.");
});

root.findViewById(R.id.done).setOnClickListener(v -> {
    Toast.done(requireActivity(), "Work is done!");
});

root.findViewById(R.id.error).setOnClickListener(v -> {
    Toast.error(requireActivity(), "Maybe somthing is wrong!");
});

About

A toast that can be used for react-native, while available for native android and ios

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published