Skip to content

Commit 247766a

Browse files
committed
fix #291: Drawer 主动关闭模态框的时候, 黑色蒙层并没有关掉也没有动画
1 parent 0b6f417 commit 247766a

File tree

3 files changed

+24
-33
lines changed

3 files changed

+24
-33
lines changed

example/examples/src/routes/Drawer/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {useState, Fragment} from 'react';
2-
import {View, Text, Bott} from 'react-native';
2+
import {View, Text} from 'react-native';
33
import {Button, Drawer, Spacing, WingBlank} from '@uiw/react-native';
44
import Layout, {Container} from '../../Layout';
55
import {ComProps} from '../../routes';

packages/core/src/Drawer/index.tsx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export interface DrawerState {
2828
drawerValue: Animated.ValueXY;
2929
overlayValue: Animated.Value;
3030
zIndexValue: number;
31-
handleDrawer: (isOpen: boolean) => void;
32-
control: 'props' | 'state';
3331
isOpen: boolean;
3432
}
3533

@@ -45,35 +43,26 @@ export default class Drawer extends Component<DrawerProps, DrawerState> {
4543
openDrawer: () => null,
4644
closeDrawer: () => null,
4745
};
48-
private handleDrawer: (isOpen: boolean) => void;
4946
constructor(props: DrawerProps) {
5047
super(props);
51-
this.handleDrawer = (isOpen: boolean) => {
52-
isOpen ? this.openDrawer() : this.closeDrawer();
53-
};
48+
5449
this.state = {
5550
zIndexValue: 0,
5651
overlayValue: new Animated.Value(0),
5752
drawerValue: new Animated.ValueXY({ ...this.getInitPosition() }),
58-
handleDrawer: this.handleDrawer,
59-
control: 'state',
6053
isOpen: !!props.isOpen,
6154
};
6255
}
63-
static getDerivedStateFromProps(props: DrawerProps, state: DrawerState) {
64-
if (state.control === 'state') {
65-
return {
66-
control: 'props',
67-
};
56+
handleDrawer = (isOpen: boolean) => {
57+
isOpen ? this.openDrawer() : this.closeDrawer();
58+
};
59+
componentDidUpdate(prevProps: DrawerProps, prevState: DrawerState) {
60+
if (prevState.isOpen !== this.state.isOpen) {
61+
this.handleDrawer(this.state.isOpen);
6862
}
69-
if (props.isOpen !== state.isOpen) {
70-
state.handleDrawer(!!props.isOpen);
71-
return {
72-
isOpen: props.isOpen,
73-
control: 'props',
74-
};
63+
if (prevProps.isOpen !== this.props.isOpen) {
64+
this.handleDrawer(!!this.props.isOpen);
7565
}
76-
return null;
7766
}
7867
componentDidMount() {
7968
if (this.props.isOpen) {
@@ -90,8 +79,8 @@ export default class Drawer extends Component<DrawerProps, DrawerState> {
9079
this.closeDrawer();
9180
};
9281
render() {
93-
const { isOpen, style, drawerWidth, drawerBackgroundColor, maskProps, placement, drawerHeight } = this.props;
94-
const { drawerValue, overlayValue, zIndexValue } = this.state;
82+
const { style, drawerWidth, drawerBackgroundColor, maskProps, placement, drawerHeight } = this.props;
83+
const { isOpen, drawerValue, overlayValue, zIndexValue } = this.state;
9584
const isTopOrBottom = placement === 'top' || placement === 'bottom';
9685
const changeStyle = isTopOrBottom ? 'height' : 'width';
9786
const dynamicDrawerStyles: any = {
@@ -180,7 +169,7 @@ export default class Drawer extends Component<DrawerProps, DrawerState> {
180169
return xy;
181170
}
182171
openDrawer() {
183-
this.setState({ zIndexValue: 3002, control: 'state' });
172+
this.setState({ zIndexValue: 3002, isOpen: true });
184173
Animated.parallel([
185174
Animated.spring(this.state.drawerValue, {
186175
toValue: { x: 0, y: 0 },
@@ -213,7 +202,7 @@ export default class Drawer extends Component<DrawerProps, DrawerState> {
213202
]).start(() => {
214203
this.props.closeDrawer!(false);
215204
this.props.onChange!(false);
216-
this.setState({ zIndexValue: 0, control: 'state' });
205+
this.setState({ zIndexValue: 0, isOpen: false });
217206
});
218207
}
219208
}

packages/core/src/Typography/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Typography 排版
55

66
[`H1~H6`](#标题) · [`<Del>`](#删除线) · [`<S>`](#删除线) · [`<U>`](#下划线) · [`<Strong>`](#加粗) · [`<P />`](#段落) · [`<Br />`](#换行) · [`<Hr />`](#水平线) · [`<Div />`](#div)
77

8-
## 标题
8+
### 基础示例
9+
10+
### 标题
911

1012
```jsx
1113
import { Fragment } from 'react';
@@ -25,7 +27,7 @@ function Demo() {
2527
}
2628
```
2729

28-
## 删除线
30+
### 删除线
2931

3032
`<s>` 标签是 `<strike>` 标签的缩写版本
3133

@@ -43,7 +45,7 @@ function Demo() {
4345
}
4446
```
4547

46-
## 下划线
48+
### 下划线
4749

4850
```jsx
4951
import { U } from '@uiw/react-native';
@@ -55,7 +57,7 @@ function Demo() {
5557
}
5658
```
5759

58-
## 加粗
60+
### 加粗
5961

6062
```jsx
6163
import { Strong } from '@uiw/react-native';
@@ -67,7 +69,7 @@ function Demo() {
6769
}
6870
```
6971

70-
## 换行
72+
### 换行
7173

7274
```jsx
7375
import { Text } from 'react-native';
@@ -80,7 +82,7 @@ function Demo() {
8082
}
8183
```
8284

83-
## 段落
85+
### 段落
8486

8587
```jsx
8688
import { Br } from '@uiw/react-native';
@@ -92,7 +94,7 @@ function Demo() {
9294
}
9395
```
9496

95-
## Div
97+
### Div
9698

9799
```jsx
98100
import { View, Text } from 'react-native';
@@ -112,7 +114,7 @@ function Demo() {
112114
}
113115
```
114116

115-
## 水平线
117+
### 水平线
116118

117119
```jsx
118120
import { View, Text } from 'react-native';

0 commit comments

Comments
 (0)