项目作者: onemolegames

项目描述 :
A native and easy to use toast plugin for react-native
高级语言: Objective-C
项目地址: git://github.com/onemolegames/react-native-toast-native.git
创建时间: 2017-06-20T06:46:16Z
项目社区:https://github.com/onemolegames/react-native-toast-native

开源协议:

下载


StackShare

react-native-toast-native

React Native Toast is a toast component for both Android and iOS. it uses scalessec/Toast for iOS;

Demo:

Getting started

$ npm install react-native-toast-native --save

Mostly automatic installation

$ react-native link react-native-toast-native

Manual installation

iOS (CocoaPods)

Add the following to your podfile:

  1. pod 'RNToastNative', :path => '../node_modules/react-native-toast-native/ios`

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-toast-native and add RNToastNative.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNToastNative.a to your project’s Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
    • Add import com.toast.RCTToastPackage; to the imports at the top of the file
    • Add new RCTToastPackage() to the list returned by the getPackages() method
  2. Append the following lines to android/settings.gradle:
    1. include ':react-native-toast-native'
    2. project(':react-native-toast-native').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-toast-native/android')
  3. Insert the following lines inside the dependencies block in android/app/build.gradle:

    1. compile project(':react-native-toast-native')

    Usage

    It’s just the same as ToastAndroid

    1. import Toast from 'react-native-toast-native';
    2. Toast.show(); // Default toast message is shown.
    3. Toast.show('This is a toast.'); // Specific message is shown with default duration("SHORT") and poistion("TOP") and styles.
    4. Toast.show('This is a long toast.',Toast.LONG); //Specific message and duration are shown with default position and styles.

    It is higly customasible. Just provide a style object as a parameter.
    example:

    1. import Toast from 'react-native-toast-native';
    2. const styles={
    3. width,
    4. height,
    5. backgroundColor,
    6. color,
    7. borderWidth,
    8. borderColor,
    9. borderRadius
    10. }
    11. Toast.show('This is a long toast.',Toast.SHORT,Toast.TOP,styles);
    12. // Customizable toast message is shown with specific message,duration and position.

Options

You can style the toast with below options;
Android:

  1. {
  2. width,
  3. height,
  4. backgroundColor,
  5. color,
  6. borderWidth,
  7. paddingLeft,
  8. paddingRight,
  9. paddingBottom,
  10. paddingTop,
  11. fontSize,
  12. lineHeight,
  13. xOffset,
  14. yOffset,
  15. letterSpacing,
  16. fontWeight
  17. }

Ios:

  1. {
  2. width,
  3. height,
  4. backgroundColor,
  5. color,
  6. borderWidth,
  7. borderColor,
  8. borderRadius
  9. }

if you want to make a customizable toast,you add an object like above to show and showGravity

Example usage:

  1. import Toast from 'react-native-toast-native';
  2. import {Platform} from 'react-native';
  3. const style={
  4. backgroundColor: "#4ADDFB",
  5. width: 300,
  6. height: Platform.OS === ("ios") ? 50 : 100,
  7. color: "#ffffff",
  8. fontSize: 15,
  9. lineHeight: 2,
  10. lines: 4,
  11. borderRadius: 15,
  12. fontWeight: "bold",
  13. yOffset: 40
  14. };
  15. Toast.show(message, Toast.SHORT, Toast.TOP,style);