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

Simple Dialog #34

Closed
AnthonyLatty opened this issue Dec 17, 2018 · 13 comments
Closed

Simple Dialog #34

AnthonyLatty opened this issue Dec 17, 2018 · 13 comments
Labels
bug Something isn't working valid This issue/bug/feature request is valid

Comments

@AnthonyLatty
Copy link

This is more of a question than a issue, how do i get the click events on each of the string in

MaterialDialog.Instance.SelectActionAsync()

@contrix09
Copy link

contrix09 commented Dec 17, 2018

Hi. Unfortunately you can't. Once a choice is clicked, the dialog dismisses and returns the string that was selected. May I ask why you needed the click events and what are you trying to achieve?

@AnthonyLatty
Copy link
Author

Hi. What i am trying to achieve is the click event of one dialog triggers a next dialog. So i taught there was a click event that was associated with the Dialog control

@contrix09
Copy link

You can check the returned string value of the dialog. It returns string.Empty if the dialog was dismissed other than when a choice was clicked. If the string is not empty, then show the other dialog.

@AnthonyLatty
Copy link
Author

AnthonyLatty commented Dec 17, 2018

This is what i am attempting to do :

var actions = new string[] { "Test1", "Test2" };

var result = MaterialDialog.Instance.SelectActionAsync("Select an option", actions);
if(actions[0] == "Test1"
{
   //Do something
}
else
{
    //Do something else
}

@contrix09
Copy link

Hi, my mistake. SelectActionAsync returns only the index of the selected choice. If the dialog was dismissed, it returns -1. You need to detect the negative index to avoid an exception.

var actions = new string[] { "Test1", "Test2" };
var result = MaterialDialog.Instance.SelectActionAsync("Select an option", actions);

if(result >= 0)
{
    switch(actions[result])
    {
        case "Test1": 
              MethodForSomething();
              break;
        case "Test2": 
              MethodForSomethingElse();
              break;
    }
}

You can also use this.

var actions = new string[] { "Test1", "Test2" };
var result = MaterialDialog.Instance.SelectActionAsync("Select an option", actions);

switch(result)
{
    case -1:
          MethodForNoAction();
          break;
    case 0: 
          MethodForSomething();
          break;
    case 1: 
          MethodForSomethingElse();
          break;
}

@AnthonyLatty
Copy link
Author

AnthonyLatty commented Dec 18, 2018

Would i have to Dispose() of the previous dialog to see the new one?? I added a method with the same code:

var actions = new string[] { "Test3", "Test4" };

var result = MaterialDialog.Instance.SelectActionAsync("Select an option", actions);

and i am not seeing this dialog when i tapped on "Test1"

@contrix09
Copy link

contrix09 commented Dec 18, 2018

No need to call dispose, the dialog automatically disposes when it is dismissed.
Add the await keyword before calling the method.

var result = await MaterialDialog.Instance.SelectActionAsync("Select an option", actions);

@AnthonyLatty
Copy link
Author

AnthonyLatty commented Dec 18, 2018

This is the code i have

var actions = new string[] { "Residents 1", "Residents 2" };

var result = await MaterialDialog.Instance.SelectActionAsync("Select an option", actions);

switch (result)
{
   case -1:
       break;
   case 0:
       var resident1 = new string[] { "Home", "Away" };
       var result1 = await MaterialDialog.Instance.SelectActionAsync("Residents 1", resident1);
       break;
   case 1:
       var resident2 = new string[] { "Local", "Away" };
       var result2 = await MaterialDialog.Instance.SelectActionAsync("Residents 2", resident2);
       break;
}

No new dialog appears

@contrix09
Copy link

Hi. After some investigation, I saw the problem. The result is being returned but before showing the next dialog, it was dismissed immediately since the disappearing animation of the first dialog was still not finished.

@contrix09 contrix09 self-assigned this Dec 18, 2018
@contrix09 contrix09 added bug Something isn't working valid This issue/bug/feature request is valid labels Dec 18, 2018
@AnthonyLatty
Copy link
Author

Ok thats good because i taught i was misusing the library. Is is possible to allow the animation of the first dialog to disappear on click?

@contrix09
Copy link

Yes, I already have a solution. The dialog will first dismiss before it will return the result. The current implementation is that the result was first returned before dismissing the dialog.

To ensure that the old dialogs are removed from the modal stack before returning a result and showing another dialog of the same type, a delay of 100 milliseconds, which is the disappearing animation duration of all dialogs, will be seen.

I can release a new version may be later this day.

@AnthonyLatty
Copy link
Author

Will test when its released

@AnthonyLatty
Copy link
Author

AnthonyLatty commented Dec 19, 2018

Tested it, works as expected. Any further issue i will update accordingly.

@contrix09 contrix09 removed their assignment Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working valid This issue/bug/feature request is valid
Projects
None yet
Development

No branches or pull requests

1 participant