1- import React , { useState , useMemo , useRef , useLayoutEffect } from 'react' ;
2- import { Animated , StyleSheet , LayoutChangeEvent , Dimensions , ViewStyle , LayoutAnimation } from 'react-native' ;
1+ import React , { useState , useMemo , useRef } from 'react' ;
2+ import { Animated , StyleSheet , LayoutChangeEvent , Dimensions , ViewStyle } from 'react-native' ;
33import MaskLayer , { MaskLayerProps } from '../MaskLayer' ;
44
55let MainWidth = Dimensions . get ( 'window' ) . width ;
@@ -23,9 +23,7 @@ const Modal = (props: ModalProps = {}) => {
2323 function onDismiss ( ) {
2424 onClosed && onClosed ( ) ;
2525 }
26-
2726 function measureContainer ( event : LayoutChangeEvent ) {
28- LayoutAnimation . linear ( ) ; //加入该函数进行布局平滑过渡动画
2927 const { height, width } = event . nativeEvent . layout ;
3028 if ( ! layoutHeight && isVertical ) {
3129 setLayoutHeight ( height ) ;
@@ -35,7 +33,7 @@ const Modal = (props: ModalProps = {}) => {
3533 }
3634 }
3735
38- useLayoutEffect ( ( ) => {
36+ useMemo ( ( ) => {
3937 function getTransformSize ( ) {
4038 if ( placement === 'top' ) {
4139 return - layoutHeight ;
@@ -110,7 +108,6 @@ const Modal = (props: ModalProps = {}) => {
110108 </ Animated . View >
111109 </ Animated . View >
112110 ) ;
113-
114111 return (
115112 < MaskLayer { ...otherProps } visible = { visible } onDismiss = { onDismiss } >
116113 { child }
0 commit comments