镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Add a dismiss event for Alert dialog #4928

Closed

Description

@satya164

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),

  • Check if GPS is enabled, if not, prompt the user to enable it
  • If the user chooses to enable GPS, wait for the location data
  • If the user cancels the dialog, fallback to something else

I'm not sure what'll be the correct way to handle this. Few things come to my mid,

  • Disable dismiss on back button and touch outside
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
  • Dispatch a global event when a dialog is dismissed
Alert.addListener('dismiss', () => { /* do the thing */ });
  • Add a callback to the dialog, which gets called when it is dismissed
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.

Activity

  1. mkonicek commented on Dec 24, 2015

    @mkonicek
    Contributor

    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.

  2. mkonicek commented on Dec 24, 2015

    @mkonicek
    Contributor

    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?

  3. satya164 commented on Dec 24, 2015

    @satya164
    ContributorAuthor

    @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

  4. ide commented on Dec 24, 2015

    @ide
    Contributor

    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?

  5. satya164 commented on Dec 25, 2015

    @satya164
    ContributorAuthor

    @ide May be pass an event object or something like that?

    function onPress(e) {
        // e.cancelledOnTouchOutside
        // e.cancelledByBackButton
    };
  6. mkonicek commented on Apr 10, 2016

    @mkonicek
    Contributor

    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.

  7. antonzy commented on Aug 8, 2016

    @antonzy

    Any progress on this one?
    Really annoying on Android....

  8. satya164 commented on Aug 9, 2016

    @satya164
    ContributorAuthor

    @antonzy #8652 might help

  9. droid-lover commented on Dec 16, 2017

    @droid-lover

    how to dismiss an alert programmatically, any suggestions?

  10. sandropoluan commented on Jan 28, 2018

    @sandropoluan

    Any update?

  11. eassymo commented on Mar 11, 2018

    @eassymo

    any update? x2

  12. dann1609 commented on Mar 30, 2018

    @dann1609

    any update? x3

  13. kunalqss commented on Apr 23, 2018

    @kunalqss

    If you could give us a way to dismiss a dialog programmatically, that'd be great, thanks. 😁

  14. bintoll commented on May 25, 2018

    @bintoll

    I also think that it would be really great

  15. rumbogs commented on Jun 10, 2018

    @rumbogs

    +1

  16. droid-lover commented on Jun 11, 2018

    @droid-lover
  17. mmazzarolo commented on Jun 11, 2018

    @mmazzarolo

    Framework is just a Framework , Not a replacement for any
    Core Language

    🤔

  18. huunovahub commented on Jul 10, 2018

    @huunovahub

    any update x4?

  19. locked as resolved and limited conversation to collaborators on Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions