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
Added a PositiveAction Action to the MessagingServiceQuestion type. #1
Conversation
Can be used like this: var task = Application.Current?.MainPage?.DisplayAlert(info.Title, info.Question, info.Positive, info.Negative); if (task != null && await task) info.PositiveAction.Invoke();
So I am thinking that actually it should have a OnResult, which returns the Positive or Negative probably a boolean is fine here and let's you make a decision based on it. Also, wondering if it should be an Action or a Fun |
You mean instead of only taking action on Positive? Instead, allowing dev to specify the action taken, whether Positive or Negative? |
I'd be cool with Action or Func. My thought for Action is: at the point that I'm calling SendMessage, I already have access to all the values I'll need in order to take action when the user makes a decision. |
Yeah, that sounds good, i think just it should be Action that returns if it was positive or negative so you can respond. If you implement that I can go ahead and merge in. |
I guess I'm not understanding. Since the DisplayAlert gets fired off by using the MessageService, then we essentially have no control over what happens with the result of the user decision. Wouldn't you have to setup a second pub/sub item with the MessagingService to communicate the result back to the original caller? If you just tuck an Action or a Func into the TArgs type, then it can be fired off in the subscriber, like this:
I dunno, maybe I'm missing something. Thoughts? |
So, I would do this:
I think this should also be added to the alert, but with just an public Action OnCompleted; |
Ahhh!! I dig. I'll wire it up and update the PR. |
And the usage can even be simplified to:
...placing the await task directly in the Invoke call, avoiding the var altogether. Pretty slick! ...or maybe even this:
|
In your code make sure you actually do this:
Because if any of those were null then your task would never get awaited! |
Oh, true! |
Added a PositiveAction Action to the MessagingServiceQuestion type.
Can be used like this:
var task = Application.Current?.MainPage?.DisplayAlert(info.Title, info.Question, info.Positive, info.Negative);
if (task != null && await task)
info?.PositiveAction?.Invoke();