@@ -15,8 +15,6 @@ import {
1515 Text ,
1616} from 'react-native'
1717
18- import PropTypes from 'prop-types' ;
19-
2018export const DURATION = {
2119 LENGTH_LONG : 2000 ,
2220 LENGTH_SHORT : 500 ,
@@ -37,9 +35,10 @@ export default class Toast extends Component {
3735 }
3836 }
3937
40- show ( text , callback , duration = DURATION . LENGTH_SHORT , ) {
38+ show ( text , duration , callback ) {
4139
42- let delay = duration ;
40+ this . duration = typeof duration === 'number' ? duration : DURATION . LENGTH_SHORT ;
41+ this . callback = callback ;
4342 this . setState ( {
4443 isShow : true ,
4544 text : text ,
@@ -57,9 +56,9 @@ export default class Toast extends Component {
5756 } ) ;
5857 }
5958
60- close ( callback , duration = DURATION . LENGTH_SHORT ) {
59+ close ( duration ) {
6160
62- let delay = duration ;
61+ let delay = typeof duration === 'undefined' ? this . duration : duration ;
6362 if ( delay === DURATION . FOREVER ) delay = this . props . defaultCloseDelay || 250 ;
6463
6564 if ( ! this . isShow && ! this . state . isShow ) return ;
@@ -72,13 +71,12 @@ export default class Toast extends Component {
7271 duration : this . props . fadeOutDuration ,
7372 }
7473 ) . start ( ( ) => {
75-
7674 this . setState ( {
7775 isShow : false ,
7876 } ) ;
7977 this . isShow = false ;
80- if ( typeof callback === 'function' ) {
81- callback ( ) ;
78+ if ( typeof this . callback === 'function' ) {
79+ this . callback ( ) ;
8280 }
8381 } ) ;
8482 } , delay ) ;
@@ -135,17 +133,17 @@ const styles = StyleSheet.create({
135133} ) ;
136134
137135Toast . propTypes = {
138- style : PropTypes . object ,
139- position : PropTypes . oneOf ( [
136+ style : View . propTypes . style ,
137+ position : React . PropTypes . oneOf ( [
140138 'top' ,
141139 'center' ,
142140 'bottom' ,
143141 ] ) ,
144- textStyle : PropTypes . object ,
145- positionValue : PropTypes . number ,
146- fadeInDuration : PropTypes . number ,
147- fadeOutDuration : PropTypes . number ,
148- opacity : PropTypes . number
142+ textStyle : Text . propTypes . style ,
143+ positionValue : React . PropTypes . number ,
144+ fadeInDuration : React . PropTypes . number ,
145+ fadeOutDuration : React . PropTypes . number ,
146+ opacity : React . PropTypes . number
149147}
150148
151149Toast . defaultProps = {
0 commit comments