import React from 'react' ; import ToastContainer from './ToastContainer' ; import RootSiblings from 'react-native-root-siblings' ; import { IconsName } from '../Icon' ; const elements = [ ] ; export interface ToastProps { type ? : string ; content : string ; duration ? : number ; icon ? : IconsName ; } function notice ( content , type , duration = 2 , icon ? ) { const addSibling = ( ) => { let sibling = new RootSiblings ( ( < ToastContainer style = { { top : 100 + elements . length * 30 } } icon = { icon } content = { content } type = { type } duration = { duration } / > ) ) ; elements . push ( sibling ) ; } ; const destroySibling = ( ) => { let lastSibling = elements . pop ( ) ; lastSibling && lastSibling . destroy ( ) ; } ; addSibling ( ) ; setTimeout ( ( ) => { destroySibling ( ) ; } , duration * 1000 ) ; } export default { info ( content , duration ? , icon ? ) { return notice ( content , 'info' , duration , icon ) ; } , success ( content , duration ? , icon ? ) { return notice ( content , 'success' , duration , icon ) ; } , warning ( content , duration ? , icon ? ) { return notice ( content , 'warning' , duration , icon ) ; } , error ( content , duration ? , icon ? ) { return notice ( content , 'error' , duration , icon ) ; } , } ;