Skip to content

Add a dismiss event for Alert dialog #4928

@satya164

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.

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