Skip to content

Commit 7da9c96

Browse files
committed
fix(Modal): 增加平滑过度
1 parent ccf02a1 commit 7da9c96

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

example/base/App.js

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,10 @@
55
*/
66

77
import React from 'react';
8-
import {
9-
SafeAreaView,
10-
ScrollView,
11-
StatusBar,
12-
StyleSheet,
13-
Text,
14-
useColorScheme,
15-
View,
16-
} from 'react-native';
8+
import {SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, useColorScheme, View} from 'react-native';
179
import {Button, Icon} from '@uiw/react-native';
1810

19-
import {
20-
Colors,
21-
DebugInstructions,
22-
Header,
23-
LearnMoreLinks,
24-
ReloadInstructions,
25-
} from 'react-native/Libraries/NewAppScreen';
11+
import {Colors, DebugInstructions, Header, LearnMoreLinks, ReloadInstructions} from 'react-native/Libraries/NewAppScreen';
2612

2713
const Section = ({children, title}) => {
2814
const isDarkMode = useColorScheme() === 'dark';
@@ -60,9 +46,7 @@ const App = () => {
6046
return (
6147
<SafeAreaView style={backgroundStyle}>
6248
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
63-
<ScrollView
64-
contentInsetAdjustmentBehavior="automatic"
65-
style={backgroundStyle}>
49+
<ScrollView contentInsetAdjustmentBehavior="automatic" style={backgroundStyle}>
6650
<Header />
6751
<View
6852
style={{
@@ -71,18 +55,15 @@ const App = () => {
7155
<Button type="primary">按钮之间的间距</Button>
7256
<Icon name="apple" size={46} color="#50CB42" />
7357
<Section title="Step One">
74-
Edit <Text style={styles.highlight}>App.js</Text> to change this
75-
screen and then come back to see your edits.
58+
Edit <Text style={styles.highlight}>App.js</Text> to change this screen and then come back to see your edits.
7659
</Section>
7760
<Section title="See Your Changes">
7861
<ReloadInstructions />
7962
</Section>
8063
<Section title="Debug">
8164
<DebugInstructions />
8265
</Section>
83-
<Section title="Learn More">
84-
Read the docs to discover what to do next:
85-
</Section>
66+
<Section title="Learn More">Read the docs to discover what to do next:</Section>
8667
<LearnMoreLinks />
8768
</View>
8869
</ScrollView>

packages/core/src/Modal/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useState, useMemo, useRef } from 'react';
2-
import { Animated, StyleSheet, LayoutChangeEvent, Dimensions, ViewStyle } from 'react-native';
1+
import React, { useState, useMemo, useRef, useLayoutEffect } from 'react';
2+
import { Animated, StyleSheet, LayoutChangeEvent, Dimensions, ViewStyle, LayoutAnimation } from 'react-native';
33
import MaskLayer, { MaskLayerProps } from '../MaskLayer';
44

55
let MainWidth = Dimensions.get('window').width;
@@ -23,7 +23,9 @@ const Modal = (props: ModalProps = {}) => {
2323
function onDismiss() {
2424
onClosed && onClosed();
2525
}
26+
2627
function measureContainer(event: LayoutChangeEvent) {
28+
LayoutAnimation.linear(); //加入该函数进行布局平滑过渡动画
2729
const { height, width } = event.nativeEvent.layout;
2830
if (!layoutHeight && isVertical) {
2931
setLayoutHeight(height);
@@ -33,7 +35,7 @@ const Modal = (props: ModalProps = {}) => {
3335
}
3436
}
3537

36-
useMemo(() => {
38+
useLayoutEffect(() => {
3739
function getTransformSize() {
3840
if (placement === 'top') {
3941
return -layoutHeight;
@@ -108,6 +110,7 @@ const Modal = (props: ModalProps = {}) => {
108110
</Animated.View>
109111
</Animated.View>
110112
);
113+
111114
return (
112115
<MaskLayer {...otherProps} visible={visible} onDismiss={onDismiss}>
113116
{child}

0 commit comments

Comments
 (0)