forked from GaneshSinghPapola/rn-easy-toast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (41 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Toast component
* Author - Ganesh Singh Papola
* simple animated toast callable with api method from anywhere
*/
import React from "react";
import PropTypes from 'prop-types';
import WideToast from "./WideToast";
import DefaultToast from "./DefaultToast";
import RootSiblings from 'react-native-root-siblings';
const Container = ({type="default", ...props}) => {
return (
type==="default"?
<DefaultToast {...props}/> :
<WideToast {...props}/>
)
}
const Toast = props => {
const {delay = 3000} = props;
let sibling = new RootSiblings(<Container {...props}/>);
setTimeout(() => {
sibling.destroy();
sibling = null;
}, delay+1000);
}
Container.propTypes = {
message : PropTypes.string.isRequired,
delay : PropTypes.number,
textStyle : PropTypes.object,
borderRadius : PropTypes.number,
position : PropTypes.oneOf(['top', 'bottom']),
background : PropTypes.string,
button : PropTypes.object,
type : PropTypes.oneOf(['default', 'wide']),
animation : PropTypes.oneOf(['slideUpDown', 'slideLeft', 'slideRight'])
};
export default Toast;
export const ToastContainer = props => {
Toast(props);
return null;
}