diff --git a/index.d.ts b/index.d.ts index 88c2647..7c93779 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,7 +25,11 @@ declare module "react-native-root-toast"{ onHidden?: Function, onShow?: Function, onShown?: Function, - onPress?: Function + onPress?: Function, + accessible?: boolean, + accessibilityLabel?: string, + accessibilityHint?: string, + accessibilityRole?: string } export interface ToastProps extends ToastOptions,ReactNative.ViewProperties{ diff --git a/lib/Toast.js b/lib/Toast.js index f765306..9b78590 100644 --- a/lib/Toast.js +++ b/lib/Toast.js @@ -1,9 +1,6 @@ import React, { Component, } from 'react'; -import { - View -} from 'react-native'; import RootSiblings from 'react-native-root-siblings'; import ToastContainer, {positions, durations} from './ToastContainer'; diff --git a/lib/ToastContainer.js b/lib/ToastContainer.js index a645d4d..8fa84af 100644 --- a/lib/ToastContainer.js +++ b/lib/ToastContainer.js @@ -81,7 +81,11 @@ class ToastContainer extends Component { onHide: PropTypes.func, onHidden: PropTypes.func, onShow: PropTypes.func, - onShown: PropTypes.func + onShown: PropTypes.func, + accessible: PropTypes.bool, + accessibilityLabel: PropTypes.string, + accessibilityHint: PropTypes.string, + accessibilityRole: PropTypes.string }; static defaultProps = { @@ -93,7 +97,11 @@ class ToastContainer extends Component { opacity: 0.8, delay: 0, hideOnPress: true, - keyboardAvoiding: true + keyboardAvoiding: true, + accessible: true, + accessibilityLabel: undefined, + accessibilityHint: undefined, + accessibilityRole: "alert" }; constructor() { @@ -194,11 +202,11 @@ class ToastContainer extends Component { pointerEvents: 'none' }); } - + if (this.props.onHide) { this.props.onHide(this.props.siblingManager); } - + Animated.timing(this.state.opacity, { toValue: 0, duration: this.props.animation ? TOAST_ANIMATION_DURATION : 0, @@ -207,12 +215,18 @@ class ToastContainer extends Component { }).start(({finished}) => { if (finished) { this._animating = false; + this.setState({ visible: false }); this.props.onHidden && this.props.onHidden(this.props.siblingManager); } }); } }; + onHide = () => { + typeof this.props.onPress === 'function' ? this.props.onPress() : null; + this.props.hideOnPress ? this._hide() : null; + } + render() { let {props} = this; const { windowWidth } = this.state; @@ -227,44 +241,64 @@ class ToastContainer extends Component { bottom: keyboardHeight }; - return (this.state.visible || this._animating) ? - { - typeof this.props.onPress === 'function' ? this.props.onPress() : null - this.props.hideOnPress ? this._hide() : null + return (this.state.visible || this._animating) ? ( + { + switch (event.nativeEvent.actionName) { + case 'activate': + this.onHide(); + break; + default: + break; + } }} + accessibilityLabel={this.props.accessibilityLabel ? this.props.accessibilityLabel : undefined} + accessibilityHint={this.props.accessibilityHint ? this.props.accessibilityHint : undefined} + accessibilityRole={this.props.accessibilityRole ? this.props.accessibilityRole : "alert"} > - this._root = ele} + - - {this.props.children} - - - - : null; + this._root = ele} + > + + {this.props.children} + + + + + ) : null; } }