Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable modal button before press handler promise becomes to resolve state #1252

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions components/modal/AlertContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ export default class AlertContainer extends React.Component<
const { title, actions, content, onAnimationEnd } = this.props
const footer = actions.map((button) => {
// tslint:disable-next-line:only-arrow-functions
const orginPress = button.onPress || function () {}
button.onPress = () => {
const res = orginPress()
if (res && res.then) {
res.then(() => {
this.onClose()
})
} else {
const originPress = button.onPress ?? function () {}
const originStyle = button.style
button.onPress = async () => {
if (button.style === 'disabled') {
return
}
button.style = 'disabled'
// developer should handle the errors by themselves,
// so we don't need to do anything at here
try {
await originPress()
} finally {
button.style = originStyle
this.onClose()
}
}
Expand Down
5 changes: 3 additions & 2 deletions components/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,16 @@ class AntmModal extends React.Component<ModalProps, any> {
}
if (button.style) {
buttonStyle = button.style
if (typeof buttonStyle === 'string') {
if (typeof button.style === 'string') {
const styleMap: {
[key: string]: object
} = {
cancel: { color: '#000' },
default: {},
destructive: { color: 'red' },
disabled: { color: 'lightgray' },
}
buttonStyle = styleMap[buttonStyle] || {}
buttonStyle = styleMap[button.style] || {}
}
}
const noneBorder =
Expand Down