Currently the Alert dialog on Android can be dismissed by tapping outside or pressing back button as well as pressing on any of the action buttons. The problem with this is that you've no way of knowing that the dialog was cancelled if the user cancels it by tapping outside.
For example, consider a location based app (my use case),
I'm not sure what'll be the correct way to handle this. Few things come to my mid,
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
Alert.addListener('dismiss', () => { /* do the thing */ });
Alert.alert('Title', 'Message', [ { text: 'Okay' } ], () => { /* do the thing */ });
Please give your inputs on what do you think the best way is. For me personally, I prefer the last one.
The native module does say whether the dialog was dismissed:
https://github.com/facebook/react-native/blob/master/Libraries/Utilities/Alert.js#L115
But it might be the same constant for the Cancel button and tapping outside the dialog. Shouldn't that always do exactly the same thing? If there should be a button that does something else than _dismiss the dialog_ (this is what tapping outside does), maybe it should be a different, third button?
I didn't see API for that on iOS so wanted to keep the API consistent.
Some users might not know that tapping outside the dialog dismisses it. Having the 'Cancel' button, Back button and tapping outside do exactly the same thing (usually, do nothing) sounds consistent from the UX perspective. What do you think?
@mkonicek Totally agree. The ideal behaviour would be to trigger same handler as cancel button.
We allow having a dialog without cancel button though. But I guess it's okay, because if the dev wanted to handle cancel event, he would have added a cancel button. I can send a PR to do this, if it's what we settle on.
I don't know what's the behaviour on iOS. Curious to know. cc @ide
On iOS you can't dismiss alerts by tapping outside of them (at least on an alert that I just tested). Would it be possible to design a clean API that acts almost the same whether the user tapped Cancel or tapped outside of the dialog, but also passes in a bit of extra information specifying how the dialog was canceled?
@ide May be pass an event object or something like that?
function onPress(e) {
// e.cancelledOnTouchOutside
// e.cancelledByBackButton
};
Hi there! This issue is being closed because it has been inactive for a while.
But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/add-a-dismiss-event-for-alert-dialog
ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub.
Also, if this issue is a bug, please consider sending a PR with a fix.
We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.
Any progress on this one?
Really annoying on Android....
@antonzy #8652 might help
how to dismiss an alert programmatically, any suggestions?
Any update?
any update? x2
any update? x3
If you could give us a way to dismiss a dialog programmatically, that'd be great, thanks. :grin:
I also think that it would be really great
+1
This issue is from 4-5 months open only.
Bottomline is - Framework is just a Framework , Not a replacement for any
Core Language.
On Sun, Jun 10, 2018 at 1:24 PM, Bogdan notifications@github.com wrote:
+1
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/facebook/react-native/issues/4928#issuecomment-396028896,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AN3adRxpNxfv110_DxLcEFcLXRxhGkCNks5t7NDMgaJpZM4G57tH
.
Framework is just a Framework , Not a replacement for any
Core Language
🤔
any update x4?
Most helpful comment
how to dismiss an alert programmatically, any suggestions?