@@ -19,20 +19,6 @@ import type {
1919} from '../types' ;
2020import { useConstructor } from '../hooks' ;
2121
22- const defaultProps : ToastableWrapperProps = {
23- animationInTiming : 600 ,
24- animationOutTiming : 600 ,
25- useNativeDriver : false ,
26- isVisible : false ,
27- panResponderThreshold : 4 ,
28- swipeThreshold : 100 ,
29- onToasterHide : ( ) => null ,
30- onToasterWillHide : ( ) => null ,
31- swipeDirection : [ 'right' , 'left' , 'up' ] ,
32- onSwipeComplete : ( ) => null ,
33- onSwipeStart : ( ) => null ,
34- } ;
35-
3622type ToastableWrapperProps = {
3723 animationInTiming : number ;
3824 animationOutTiming : number ;
@@ -236,11 +222,21 @@ const ANIMATION_MAP: Record<SwipeDirection, AnimatableViewAnimation> = {
236222} ;
237223
238224export const ToastableWrapper = ( {
225+ animationInTiming = 600 ,
226+ animationOutTiming = 600 ,
227+ isVisible = false ,
228+ panResponderThreshold = 4 ,
229+ swipeThreshold = 100 ,
230+ onToasterHide = ( ) => null ,
231+ onToasterWillHide = ( ) => null ,
232+ swipeDirection = [ 'right' , 'left' , 'up' ] ,
233+ onSwipeComplete = ( ) => null ,
234+ onSwipeStart = ( ) => null ,
239235 ...props
240236} : PropsWithChildren < ToastableWrapperProps > ) => {
241- const isSwipeable = ! ! props . swipeDirection ;
237+ const isSwipeable = ! ! swipeDirection ;
242238
243- const [ isVisible , setIsVisible ] = useState ( props . isVisible ) ;
239+ const [ isShown , setIsShown ] = useState ( isVisible ) ;
244240 const pan = useRef ( new Animated . ValueXY ( ) ) . current ;
245241 const contentRef = useRef < AnimatableViewRef > ( null ) ;
246242
@@ -264,15 +260,15 @@ export const ToastableWrapper = ({
264260 if ( interactionHandle == null ) {
265261 interactionHandle = InteractionManager . createInteractionHandle ( ) ;
266262 }
267- content . animate ( 'slideInDown' , props . animationInTiming ) . then ( ( ) => {
263+ content . animate ( 'slideInDown' , animationInTiming ) . then ( ( ) => {
268264 isTransitioning = false ;
269265
270266 if ( interactionHandle ) {
271267 InteractionManager . clearInteractionHandle ( interactionHandle ) ;
272268 interactionHandle = null ;
273269 }
274270
275- if ( ! props . isVisible ) {
271+ if ( ! isVisible ) {
276272 close ( ) ;
277273 }
278274 } ) ;
@@ -291,14 +287,14 @@ export const ToastableWrapper = ({
291287 return ;
292288 }
293289
294- props . onToasterWillHide ?.( ) ;
290+ onToasterWillHide ?.( ) ;
295291
296292 if ( interactionHandle == null ) {
297293 interactionHandle = InteractionManager . createInteractionHandle ( ) ;
298294 }
299295
300296 content
301- . animate ( ANIMATION_MAP [ currentSwipingDirection ] , props . animationOutTiming )
297+ . animate ( ANIMATION_MAP [ currentSwipingDirection ] , animationOutTiming )
302298 . then ( ( ) => {
303299 isTransitioning = false ;
304300
@@ -307,9 +303,9 @@ export const ToastableWrapper = ({
307303 interactionHandle = null ;
308304 }
309305
310- if ( ! props . isVisible ) {
311- setIsVisible ( false ) ;
312- props . onToasterHide ( ) ;
306+ if ( ! isVisible ) {
307+ setIsShown ( false ) ;
308+ onToasterHide ( ) ;
313309 return ;
314310 }
315311
@@ -319,21 +315,21 @@ export const ToastableWrapper = ({
319315
320316 useConstructor ( ( ) => {
321317 buildPanResponder ( {
322- onSwipeComplete : props . onSwipeComplete ,
323- onSwipeStart : props . onSwipeStart ,
318+ onSwipeComplete : onSwipeComplete ,
319+ onSwipeStart : onSwipeStart ,
324320 pan,
325- panResponderThreshold : props . panResponderThreshold ,
326- swipeDirection : props . swipeDirection ,
327- swipeThreshold : props . swipeThreshold ,
321+ panResponderThreshold : panResponderThreshold ,
322+ swipeDirection : swipeDirection ,
323+ swipeThreshold : swipeThreshold ,
328324 } ) ;
329325 } ) ;
330326
331327 useEffect ( ( ) => {
332- if ( isVisible ) {
328+ if ( isShown ) {
333329 open ( ) ;
334330 }
335331 // eslint-disable-next-line react-hooks/exhaustive-deps
336- } , [ isVisible ] ) ;
332+ } , [ isShown ] ) ;
337333
338334 useEffect ( ( ) => {
339335 return ( ) => {
@@ -349,12 +345,16 @@ export const ToastableWrapper = ({
349345 useEffect ( ( ) => {
350346 const wasVisible = prevIsVisibleRef . current ;
351347
352- if ( props . isVisible !== wasVisible ) {
353- props . isVisible ? open ( ) : close ( ) ;
354- prevIsVisibleRef . current = props . isVisible ;
348+ if ( isVisible !== wasVisible ) {
349+ if ( isVisible ) {
350+ open ( ) ;
351+ } else {
352+ close ( ) ;
353+ }
354+ prevIsVisibleRef . current = isVisible ;
355355 }
356356 // eslint-disable-next-line react-hooks/exhaustive-deps
357- } , [ props . isVisible ] ) ;
357+ } , [ isVisible ] ) ;
358358
359359 // FIXME: this should be placed in the render method, but it causes a bug
360360 // if (!isVisible) {
@@ -375,8 +375,6 @@ export const ToastableWrapper = ({
375375 ) ;
376376} ;
377377
378- ToastableWrapper . defaultProps = defaultProps ;
379-
380378const styles = StyleSheet . create ( {
381379 container : {
382380 ...StyleSheet . absoluteFillObject ,
0 commit comments