11import * as React from 'react' ;
2- import { Animated , View } from 'react-native' ;
2+ import { View } from 'react-native' ;
3+ import { animated , useSpring } from 'react-spring/native.cjs' ;
34import { DeepPartial } from 'ts-essentials' ;
45
56import { useTheme } from '../../theme' ;
@@ -13,6 +14,7 @@ import {
1314} from './Drawer.styles' ;
1415
1516type Position = 'bottom' | 'top' | 'right' | 'left' ;
17+ const AnimatedView = animated ( View ) ;
1618
1719export interface DrawerProps {
1820 children : React . ReactNode ;
@@ -47,23 +49,21 @@ export const Drawer = (props: DrawerProps) => {
4749 getStyles ,
4850 ) ( theme ) ;
4951
50- if ( ! isVisible ) return null ;
51-
52- const value = new Animated . Value ( - 500 ) ;
53-
54- Animated . spring ( value , {
55- bounciness : 0 ,
56- speed : 70 ,
57- toValue : offset ,
58- } ) . start ( ) ;
52+ const animation = useSpring ( {
53+ [ position ] : offset ,
54+ from : { [ position ] : - 600 } ,
55+ reset : true ,
56+ } ) ;
5957
6058 return (
61- < Modal visible transparent onRequestClose = { onClose } >
59+ < Modal visible = { isVisible } transparent onRequestClose = { onClose } >
6260 < View style = { modalContainerStyle } >
63- < Animated . View
61+ { /*
62+ // @ts -ignore */ }
63+ < AnimatedView
6464 style = { {
6565 ...containerStyle ,
66- [ position ] : value ,
66+ [ position ] : animation [ position ] ,
6767 ...( ( position === 'left' || position === 'right' ) &&
6868 space && {
6969 height : '100%' ,
@@ -77,7 +77,7 @@ export const Drawer = (props: DrawerProps) => {
7777 } }
7878 >
7979 { children }
80- </ Animated . View >
80+ </ AnimatedView >
8181 < Overlay onPress = { onClose } />
8282 </ View >
8383 </ Modal >
0 commit comments