All Projects → openUmbrella → React Native Root Tips

openUmbrella / React Native Root Tips

Licence: mit
very simple and powerful way to show a toast in react-native

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Root Tips

Jquery Tips Everyone Should Know
A collection of tips to help up your jQuery game
Stars: ✭ 4,178 (+4758.14%)
Mutual labels:  tips
Elixir Tips
The Killer Elixir Tips and Tricks...from the experience...
Stars: ✭ 833 (+868.6%)
Mutual labels:  tips
Layer
丰富多样的 Web 弹出层组件,可轻松实现 Alert/Confirm/Prompt/ 普通提示/页面区块/iframe/tips等等几乎所有的弹出交互。目前已成为最多人使用的弹层解决方案
Stars: ✭ 8,202 (+9437.21%)
Mutual labels:  tips
Android Daily Tips
Daily tips from Android World
Stars: ✭ 492 (+472.09%)
Mutual labels:  tips
Swift Tips
A collection useful tips for the Swift language
Stars: ✭ 743 (+763.95%)
Mutual labels:  tips
Android Tips Tricks Cn
震惊!这么多的安卓开发Tips
Stars: ✭ 931 (+982.56%)
Mutual labels:  tips
Patronkit
A framework to add patronage to your apps.
Stars: ✭ 370 (+330.23%)
Mutual labels:  tips
Html File Upload
Useful HTML file upload tips for web developers
Stars: ✭ 83 (-3.49%)
Mutual labels:  tips
Burpsuite
BurpSuite using the document and some extensions
Stars: ✭ 832 (+867.44%)
Mutual labels:  tips
Azuretipsandtricks
Learn some of our favorite Azure tips and tricks—some long-standing, and new ones that have recently been added to become more productive with Azure. Star the repo now to shave hours off your coding tasks tomorrow.
Stars: ✭ 957 (+1012.79%)
Mutual labels:  tips
Git Tips
Часто используемые трюки и советы при работе с Git
Stars: ✭ 551 (+540.7%)
Mutual labels:  tips
So You Want An Internship
for those seeking software engineering internships
Stars: ✭ 656 (+662.79%)
Mutual labels:  tips
Linux Tips
Linux Tips
Stars: ✭ 8 (-90.7%)
Mutual labels:  tips
Android Tips Tricks
☑️ [Cheatsheet] Tips and tricks for Android Development
Stars: ✭ 4,496 (+5127.91%)
Mutual labels:  tips
Learn Vim
Vim 实操教程(Learning Vim)Vim practical tutorial.
Stars: ✭ 1,166 (+1255.81%)
Mutual labels:  tips
Free r tips
Free R-Tips is a FREE Newsletter provided by Business Science. It comes with bite-sized code tutorials every Tuesday.
Stars: ✭ 381 (+343.02%)
Mutual labels:  tips
Pandoc Latex Tip
A pandoc filter for adding tip in LaTeX
Stars: ✭ 7 (-91.86%)
Mutual labels:  tips
Ctf Pwn Tips
Here record some tips about pwn. Something is obsoleted and won't be updated. Sorry about that.
Stars: ✭ 1,249 (+1352.33%)
Mutual labels:  tips
Vue Marquee Tips
基于Vue的横向跑马灯提示
Stars: ✭ 73 (-15.12%)
Mutual labels:  tips
Awesome Seo
Google SEO研究及流量变现
Stars: ✭ 942 (+995.35%)
Mutual labels:  tips

react-native-root-tips

screen-shoot

Features

  1. Pure javascript solution.
  2. Support both Android and iOS.
  3. Lots of custom options for Toast.
  4. You can show/hide Toast by calling api or using Component inside render.
  5. You can custom icon and text and so on
  6. Provide a global setting default options method: setDefaultOptions
  7. Provide convenience methods: showLoading/showSuccess/showInfo/showWarn
  8. Better performance

如果你恰好也在天朝,请点击这里

Thanks

react-native-root-toast package's author

Install

npm install react-native-root-tips --save

In react native >= 0.62, the new LogBox component would impact this component's initialization. To make it work we have to explicitly insert a mount point in your app like this:

// in your entry file like `App.js`

// In theory you don't have to install `react-native-root-siblings` because it's a dep of root-toast
// But you can install it explicitly if your editor complains about it.
import { RootSiblingParent } from 'react-native-root-siblings';

// in your render function 
return (
  <RootSiblingParent>  // <- use RootSiblingParent to wrap your root component
    <App />
  </RootSiblingParent>
);
            

You can skip this step if your react-native is lower than 0.62. And actually you can inject RootSiblingParent into anywhere like a react portal, for example if you have multiple rootviews you can choose where to display the root toast.

Read more about react-native-root-siblings which powers react-native-root-toast.

Simple Useage

convenience method usage

now, you can call these methods to show a tips

// show a loading tips
// you need call Tips.hide() to make tips disappear
Tips.showLoading('loading...');

// show a successful tips
Tips.showSuccess('wow! success');

// show a failed tips
Tips.showFail('em...failed');

// show a Info tips
Tips.showInfo('info tips');

// show a warning tips
Tips.showWarn('warning');

// ** you can call hide() to hide showing tips **
// Tips.hide();

if you don't like the default icons, you can setting them in setDefaultOptions method

//you can set a global default options you like
Tips.setDefaultOptions({
    showLoading: true,
    backgroundColor: 'gray',
    opacity: 0.95,
    textColor: 'white',
    
    // setting image you like
    imageLoading: require('xxxxxxxxxx'),
    imageSuccess: require('xxxxxxxxxx'),
    imageFail: require('xxxxxxxxxx'),
    imageInfo: require('xxxxxxxxxx'),
    imageWarn: require('xxxxxxxxxx'),
});

or, you want to set a special icon in some places. you can do that:

// example
Tips.showSuccess('difference icon',{image:require('yyyyyyyyyyy')});

normal usage

import Tips from 'react-native-root-tips';

  _sampleSimple(){
    Tips.show('hello world!');
  }
  _sampleDefaultLoading(){
    Tips.show('loading...',{showLoading: true});
  }
  _sampleDefaultSuccess(){
    Tips.show('loading success',{showSuccess: true});
  }
  _sampleDefaultFail(){
    Tips.show('loading fail',{showFail: true});
  }
  
  _sampleCustomImage(){
    // you can use local Image or net image
    // you need to set App Transport Security Settings -> Allow Arbitrary Loads is YES in info.plist
    Tips.show('Custom Images', { backgroundColor: 'white',textColor:'black',opacity:0.9,image:{uri:'https://github.com/openUmbrella/react-native-root-tips/raw/master/example/src/loading1.gif'}});
    
    // local Image
    // Tips.show('Custom Images',{image: require('./src/loading.gif')});
  }
  _sampleOnlyImage(){
    Tips.show('tips will not show',{showText: false,showLoading:true});
  }
  _sampleMask(){
    //when showing, you can't touch anything
    Tips.show('masking...',{mask:true,showLoading:true, maskColor:'gray'});
  }


Settings

Name Default Type Description
duration Toast.durations.SHORT Number The duration of the toast. (Only for api calling method)
visible false Bool The visibility of toast. (Only for Toast Component)
position Toast.positions.CENTER Number The position of toast showing on screen (A negative number represents the distance from the bottom of screen. A positive number represents the distance form the top of screen. 0 will position the toast to the middle of screen.)
animation true Bool Should preform an animation on toast appearing or disappearing.
shadow true Bool Should drop shadow around Toast element.
backgroundColor null String The background color of the toast.
shadowColor null String The shadow color of the toast.
textColor null String The text color of the toast.
delay 0 Number The delay duration before toast start appearing on screen.
hideOnPress false Bool Should hide toast that appears by pressing on the toast.
onShow null Function Callback for toast`s appear animation start
onShown null Function Callback for toast`s appear animation end
onHide null Function Callback for toast`s hide animation start
onHidden null Function Callback for toast`s hide animation end

adding props

Name               Default                 Type   Description
showLoading          null                   Function convenience method,show an Loading tips
showSuccess          null                   Function convenience method,show an Success tips
showFail          null                   Function convenience method,show an Fail tips
showInfo          null                   Function convenience method,show an Info tips
showWarn          null                   Function convenience method,show an Warn tips
hide          null                   Function hide showing tips
imageLoading         null               Object showLoading method custom Image
imageSuccess         null               Object showSuccess method custom Image
imageFail        null               Object showFail method custom Image
imageInfo         null               Object showInfo method custom Image
imageWarn         null               Object showWarn method custom Image
textFont             14                     Number     text's font
mask               false                     Bool     If can touch other place when shown
maskColor           string                   Bool     The mask's color
maskOpacity         false                     Bool     The mask's opacity
image         null                     Object   show image icon that you like. notice: if you setting image/showSuccess/showFail/showLoading at once, the priority is descendant
imageStyle         null                     Object   the image style
showText             true                     Bool     If show text
showSuccess         false                     Bool     If show default success icon
showFail         false                     Bool     If show default fail icon
showLoading         false                     Bool     If show default loading icon

Properties

Tips.durations

presets of duration of the toast.

  1. Tips.durations.SHORT (equals to 2000)

  2. Tips.durations.LONG (equals to 3500)

Tips.positions

presets of position of toast.

  1. Tips.positions.TOP (equals to 20)

  2. Tips.positions.BOTTOM (equals to -20)

  3. Tips.positions.CENTER (equals to 0)

Usage

There are two different ways to manage a Toast.

Calling api

NOTE: I recommend you to use this way

import Tips from 'react-native-root-tips';

// Add a Tips on screen.
let tips = Tips.show('This is a message', {
    duration: 2500,
    position: Tips.positions.CENTER,
    shadow: true,
    animation: true,
    hideOnPress: true,
    delay: 0,
    onShow: () => {
        // calls on toast\`s appear animation start
    },
    onShown: () => {
        // calls on toast\`s appear animation end.
    },
    onHide: () => {
        // calls on toast\`s hide animation start.
    },
    onHidden: () => {
        // calls on toast\`s hide animation end.
    }
});

// You can manually hide the Toast, or it will automatically disappear after a `duration` ms timeout.
setTimeout(function () {
    Tips.hide(tips);
}, 500);

Using a Component

NOTE: Showing a tips by using a Component inside render, The tips will be automatically disappeared when the <Tips /> is unmounted.

import React, {Component} from 'react-native';
import Tips from 'react-native-root-tips';

class Example extends Component{
    constructor() {
        super(...arguments);
        this.state = {
            visible: false
        };
    }

    componentDidMount() {
        setTimeout(() => this.setState({
            visible: true
        }), 2000); // show tips after 2s

        setTimeout(() => this.setState({
            visible: false
        }), 5000); // hide tips after 5s
    };

    render() {
        return <Tips
            visible={this.state.visible}
            position={50}
            shadow={false}
            animation={false}
            hideOnPress={true}
        >This is a message</Tips>;
    }
}

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].