Giter Site home page Giter Site logo

mochixuan / react-native-smart-tip Goto Github PK

View Code? Open in Web Editor NEW
247.0 4.0 36.0 2.62 MB

🔥🔥🔥Toast , SnackBar , Modal , Show Toast above Modal

JavaScript 91.61% Java 1.70% Objective-C 4.37% Starlark 2.32%
toast snackbar modal react-native message react-native-toast react-native-snackbar react-native-modal

react-native-smart-tip's Introduction

react-native-smart-tip

React-native smart tip, including Toast、Modal、SnackBar

GitHub license npm

2021.4

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

import { WRootToastApp } from 'react-native-smart-tip'

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

return (
  <WRootToastApp>  // <- use WRootToastApp to wrap your root component
    <App />
  </WRootToastApp>
);

2020.5

  1. Add property isShowShadow to WSnackBar and WToast
  2. Add sliding hide function for WSnackBar

2020.3 Show Toast above Modal (Compatible with Android and iOS)

import { ModalShowToastView } from 'react-native-smart-tip'

getToastInstance = (toastInstance) => {
    this.toastInstance = toastInstance;
}

<Modal>
	<View>
		<ModalShowToastView toastInstance={this.getToastInstance} />
	</View>
</Modal>

this.toastInstance({data: 'toast'})

2019.7 Remove the method in the componentWillMount method. Compatible with future React 17 versions, [email protected] version.

Installation

yarn add react-native-smart-tip
or
npm i react-native-smart-tip --save 

Features

Toast

SnackBar

Modal

Show tips on Modal

Tip: Modal shows that modal can only be used on Android issue

Usage

WToast
import {WToast} from 'react-native-smart-tip'

// Base 
show = () => {
	WToast.show({data: 'hello world'})
}

// Other
show = () => {
	const toastOpts = {
	    data: 'Success',
	    textColor: '#ffffff',
	    backgroundColor: '#444444',
	    duration: WToast.duration.LONG, //1.SHORT 2.LONG
	    position: WToast.position.TOP, // 1.TOP 2.CENTER 3.BOTTOM
	    icon: <Image source={require('../data/img/success.png')} style={{width: 32,height: 32,resizeMode: 'contain'}}/>
	}
	
	WToast.show(toastOpts)
}

WToast.hide(); // Can be hidden immediately

WToast API
Props Type Required Default Description
data String true ' ' Displayed content
duration Number false WToast.duration.SHORT The duration of the toast
position Number false WToast.position.BOTTOM Displayed position
inEasing Easing false Easing.elastic(1) Admission animation
textColor String false 'white' font color
backgroundColor String false 'black' background color
icon Component fasse undefined Image to be displayed
isShowShadow boolean false true Shadow effect

WSnackBar
import {WSnackBar} from 'react-native-smart-tip'

// Base 
show = () => {
	WSnackBar.show({data: 'hello world'})
}

// Other
show = () => {
	const snackBarOpts = {
	    data: 'Please check the network first.',
	    position: WSnackBar.position.BOTTOM, // 1.TOP 2.CENTER 3.BOTTOM
	    duration: WSnackBar.duration.LONG, //1.SHORT 2.LONG 3.INDEFINITE
	    textColor: '#ff490b',
	    backgroundColor: '#050405',
	    actionText: 'Sure',
	    actionTextColor: '#ff490b',
	    onActionHide: (isSlideHide)=>{
	    	// Click Action
	    },
	}
	
	WSnackBar.show(snackBarOpts)
}

WSnackBar API
Props Type Required Default Description
data String true ' ' Displayed content
statusBarHeight Number false -1 Prevent Android statusBar
height Number false 44 Height to display
duration Number false WSnackBar.duration.SHORT The duration of the toast
position Number false WSnackBar.position.BOTTOM Displayed position
inEasing Easing false Easing.linear Admission animation
textColor String false 'white' font color
backgroundColor String false 'black' background color
actionText String false undefined action text
actionTextColor String false 'white' action text color
isAllowSlideExit boolean false true Whether to run sliding hide
onActionHide Function false undefined listener click
isShowShadow boolean false true Shadow effect
numberOfLines number false 1 Maximum number of rows

WModal
import {WModal} from 'react-native-smart-tip'

// Base 
show = () => {
	WModal.show({data: 'hello world'})
}

// Other
show = () => {
	const modalOpts = {
	    data: 'Loading',
	    textColor: '#fff',
	    backgroundColor: '#444444',
	    position: WModal.position.CENTER,
	    icon: <ActivityIndicator color='#fff' size={'large'}/>
	}
	
	WModal.show(modalOpts)
}

WToast API
Props Type Required Default Description
data String true ' ' Displayed content
position Number false WToast.position.BOTTOM Displayed position
inEasing Easing false Easing.elastic(1) Admission animation
textColor String false 'white' font color
backgroundColor String false 'black' background color
icon Component fasse undefined Image to be displayed
onRequestClose Function false undefined Android Back
MIT Licensed

react-native-smart-tip's People

Contributors

a-kylin avatar mochixuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-smart-tip's Issues

关于 Toast 显示在 Modal 上方

image

这个解决方法和我在 native-base 的 issue 里看到的类似,链接如下:
GeekyAnts/NativeBase#985

但是有些应用场景貌似不太适用,比如一个 Page 包含一个 Modal,需要满足既能够在页面显示 Toast 又能在 Modal 显示时 Toast 能显示在 Modal 上方。

麻烦您看一下(^▽^)

[0.65.x] Deprecated Dimensions event listeners

Since react-native 0.65.x handling listeners has changed, here's a patch-package file to temp fix only ToastView.js:

diff --git a/node_modules/react-native-smart-tip/toast/ToastView.js b/node_modules/react-native-smart-tip/toast/ToastView.js
index 348e3a4..27f36e7 100644
--- a/node_modules/react-native-smart-tip/toast/ToastView.js
+++ b/node_modules/react-native-smart-tip/toast/ToastView.js
@@ -25,7 +25,7 @@ export default class ToastView extends Component{
         }
 
         // React after 17
-        Dimensions.addEventListener('change', this.onWindowChange);
+       this.dimensionsSubscription = Dimensions.addEventListener('change', this.onWindowChange);
     }
 
     componentDidMount() {
@@ -37,7 +37,7 @@ export default class ToastView extends Component{
             this.liftCycleAnimated.stop()
             this.liftCycleAnimated = undefined
         }
-        Dimensions.removeEventListener('change', this.onWindowChange);
+        this.dimensionsSubscription?.remove();
     }
 
     render() {


@mochixuan for backwards compatibility you could add:

import React from 'react';
const ReactNativeVersion = require('react-native/Libraries/Core/ReactNativeVersion');


constructor(props) {
    super(props);

    const { width, height } = Dimensions.get("window");

    this.state = {
      deviceWidth: width,
      deviceHeight: height,
      animatedValue1: new Animated.Value(0),
      animatedValue2: new Animated.Value(0.2)
    };

    // React after 17
    if (v >= 65) {
      this.dimensionsSubscription = Dimensions.addEventListener(
        "change",
        this.onWindowChange
      );
    } else {
      Dimensions.addEventListener("change", this.onWindowChange);
    }
  }

  componentWillUnmount() {
    if (this.liftCycleAnimated) {
      this.liftCycleAnimated.stop();
      this.liftCycleAnimated = undefined;
    }

    const v = parseInt(
      ReactNativeVersion.version.major + ReactNativeVersion.version.minor,
      10
    );

    if (v >= 65) {
      this.dimensionsSubscription?.remove();
    } else {
      Dimensions.removeEventListener("change", this.onWindowChange);
    }
  }


not tested ^^, just a suggestion, this should apply to all Views, not only ToastView 😄

WSnackBar close suggestion

I would like to leave it as a suggestion: An option to slide to close in SnackBar mode, or to click on the component and close.

The suggestion was to close it, invoking the .hide() method, but it could be a customizable action property as well.

Yes, I know you have a similar option, but it is using text. The ideal would be one executed from the interaction of any area of ​​the component. Using only WSnackBar.show().

点击没有反应

image
大佬,您好。我是直接把您的demo里的拿过来,但是没有效果也。是我少了什么吗,打过断点,Toast确实有这个对象,引用到了。但是就是没有tip弹出。

WToast in android can not show backgroundColor

"react": "16.9.0",
"react-native": "0.61.0",

WToast.show({
            data: msg,
            textColor: '#ffffff',
            backgroundColor: '#000000',
            duration: 2, // 1.SHORT 2.LONG
            position: WToast.position.CENTER, // 1.TOP 2.CENTER 3.BOTTOM
        });

怎么集成全局Toast

老大,想把你插件里的Toast集成到全局

123123213123

全局Loading我集成好了,好像直接用你写的Toast不行

请问 WModal 有没有关闭的 api?

const load1 = WModal.show({
        data: '加载中',
        textColor: '#fff',
        backgroundColor: '#444444',
        position: WModal.position.CENTER,
        icon: <ActivityIndicator color="#fff" size={'large'} />,
});
console.log(load1);// undefined 这里是 undefined

show 了以后不知道怎么关闭.

有个警告错误

Animated: useNativeDriver was not specified. This is a required option and must be explicitly set to true or false
in SnackView (at SnackBar.js:25)

最新的0.62版本。

inEasing not working for android

inEasing not working in android (debug) not tested in APK

data: "", textColor: "#ffffff", backgroundColor: error ? "#ff490b" : CONST.APP_COLOR, duration: WToast.duration.LONG, position: WToast.position.BOTTOM, isShowShadow: false, inEasing: Easing.ease,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.