Skip to content

Commit 9a74381

Browse files
committed
update code
1 parent 4853f82 commit 9a74381

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

src/ActionSheet/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ function createActionSheet(flag, config, callback) {
3232

3333
const div = document.createElement('div');
3434
document.body.appendChild(div);
35+
const root = createRoot(div);
3536

3637
queue.push(close);
3738

3839
function close() {
3940
if (div) {
40-
ReactDOM.unmountComponentAtNode(div);
41+
root.unmount();
4142
if (div.parentNode) {
4243
div.parentNode.removeChild(div);
4344
}
@@ -207,7 +208,6 @@ function createActionSheet(flag, config, callback) {
207208
}
208209

209210
const rootCls = classnames(`${prefixCls}-${mode}`, className);
210-
const root = createRoot(div);
211211
root.render(
212212
<Dialog
213213
visible

src/Modal/alert.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
3+
import { createRoot } from 'react-dom/client';
34
import closest from '../_util/closest';
45
import Modal from './modal';
56

@@ -14,23 +15,26 @@ export default function alert(
1415
if (!title && !message) {
1516
// console.log('Must specify either an alert title, or message, or both');
1617
return {
17-
close: () => {}
18+
close: () => { }
1819
};
1920
}
2021

2122
const div = document.createElement('div');
2223
document.body.appendChild(div);
24+
const root = createRoot(div);
2325

2426
function close() {
25-
ReactDOM.unmountComponentAtNode(div);
26-
if (div && div.parentNode) {
27-
div.parentNode.removeChild(div);
27+
if (div) {
28+
root.unmount();
29+
if (div.parentNode) {
30+
div.parentNode.removeChild(div);
31+
}
2832
}
2933
}
3034

3135
const footer = actions.map(button => {
3236
// tslint:disable-next-line:only-arrow-functions
33-
const orginPress = button.onPress || function () {};
37+
const orginPress = button.onPress || function () { };
3438
button.onPress = () => {
3539
if (closed) {
3640
return;
@@ -43,7 +47,7 @@ export default function alert(
4347
closed = true;
4448
close();
4549
})
46-
.catch(() => {});
50+
.catch(() => { });
4751
} else {
4852
closed = true;
4953
close();
@@ -64,7 +68,7 @@ export default function alert(
6468
}
6569
}
6670

67-
ReactDOM.render(
71+
root.render(
6872
<Modal
6973
visible
7074
transparent
@@ -78,8 +82,7 @@ export default function alert(
7882
wrapProps={{ onTouchStart: onWrapTouchStart }}
7983
>
8084
<div className={`${prefixCls}-alert-content`}>{message}</div>
81-
</Modal>,
82-
div
85+
</Modal>
8386
);
8487

8588
return {

src/Modal/operation.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
3+
import { createRoot } from 'react-dom/client';
34
import closest from '../_util/closest';
45
import Modal from './modal';
56

@@ -12,17 +13,20 @@ export default function operation(
1213
const prefixCls = 'am-modal';
1314
const div = document.createElement('div');
1415
document.body.appendChild(div);
16+
const root = createRoot(div);
1517

1618
function close() {
17-
ReactDOM.unmountComponentAtNode(div);
18-
if (div && div.parentNode) {
19-
div.parentNode.removeChild(div);
19+
if (div) {
20+
root.unmount();
21+
if (div.parentNode) {
22+
div.parentNode.removeChild(div);
23+
}
2024
}
2125
}
2226

2327
const footer = actions.map(button => {
2428
// tslint:disable-next-line:only-arrow-functions
25-
const orginPress = button.onPress || function () {};
29+
const orginPress = button.onPress || function () { };
2630
button.onPress = () => {
2731
if (closed) {
2832
return;
@@ -35,7 +39,7 @@ export default function operation(
3539
closed = true;
3640
close();
3741
})
38-
.catch(() => {});
42+
.catch(() => { });
3943
} else {
4044
closed = true;
4145
close();
@@ -54,7 +58,7 @@ export default function operation(
5458
}
5559
}
5660

57-
ReactDOM.render(
61+
root.render(
5862
<Modal
5963
visible
6064
operation
@@ -69,8 +73,7 @@ export default function operation(
6973
className="am-modal-operation"
7074
platform={platform}
7175
wrapProps={{ onTouchStart: onWrapTouchStart }}
72-
/>,
73-
div
76+
/>
7477
);
7578

7679
return {

src/Modal/prompt.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
3+
import { createRoot } from 'react-dom/client';
34
import closest from '../_util/closest';
45
import Modal from './modal';
56

@@ -24,7 +25,7 @@ export default function prompt(
2425
if (!callbackOrActions) {
2526
// console.log('Must specify callbackOrActions');
2627
return {
27-
close: () => {}
28+
close: () => { }
2829
};
2930
}
3031

@@ -147,11 +148,14 @@ export default function prompt(
147148

148149
const div = document.createElement('div');
149150
document.body.appendChild(div);
151+
const root = createRoot(div);
150152

151153
function close() {
152-
ReactDOM.unmountComponentAtNode(div);
153-
if (div && div.parentNode) {
154-
div.parentNode.removeChild(div);
154+
if (div) {
155+
root.unmount();
156+
if (div.parentNode) {
157+
div.parentNode.removeChild(div);
158+
}
155159
}
156160
}
157161

@@ -175,7 +179,7 @@ export default function prompt(
175179
actions = [
176180
{
177181
text: '取消',
178-
onPress: () => {}
182+
onPress: () => { }
179183
},
180184
{
181185
text: '确定',
@@ -197,7 +201,7 @@ export default function prompt(
197201

198202
const footer = actions.map(button => {
199203
// tslint:disable-next-line:only-arrow-functions
200-
const orginPress = button.onPress || function () {};
204+
const orginPress = button.onPress || function () { };
201205
button.onPress = () => {
202206
if (closed) {
203207
return;
@@ -210,7 +214,7 @@ export default function prompt(
210214
closed = true;
211215
close();
212216
})
213-
.catch(() => {});
217+
.catch(() => { });
214218
} else {
215219
closed = true;
216220
close();
@@ -230,7 +234,7 @@ export default function prompt(
230234
}
231235
}
232236

233-
ReactDOM.render(
237+
root.render(
234238
<Modal
235239
visible
236240
transparent
@@ -245,8 +249,7 @@ export default function prompt(
245249
wrapProps={{ onTouchStart: onWrapTouchStart }}
246250
>
247251
<div className={`${prefixCls}-propmt-content`}>{content}</div>
248-
</Modal>,
249-
div
252+
</Modal>
250253
);
251254

252255
return {

0 commit comments

Comments
 (0)