Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin: Use the Notify method that has a UICompletion Handler is not available

I have this static Source Analysis warning in Xamarin Studio:

API Usage Issue: Use the *Notify method that has a UICompletion Handler completion parameter, the bool will tell you if the operation finished

when invoking UIView.Animate(double duration, Action animation, Action completion):

UIView.Animate(duration,
   () => Animation(),
   () => Completion());

However, I can't seem to be able to pass parameters to the lambda expression. None of these options compile:

  • (bool) => Completion()
  • (finished) => Completion()
  • (bool finished) => Completion()

How can I pass this finished parameter to to completion block?

like image 860
SwiftArchitect Avatar asked Oct 25 '16 13:10

SwiftArchitect


2 Answers

The Animate static methods use NSAction methods, more of a C# style annotation and AnimateNotify use UICompletionHandler methods, ObjC-style...

The Animate methods are just helper wrappers around AnimateNotify:

So instead of:

UIView.Animate(30, () => { }, () => { });

You can use:

UIView.AnimateNotify(30, () => { }, (bool finished) => { });

The result is the same....

Ref: https://github.com/xamarin/xamarin-macios/blob/fc55e4306f79491fd269ca2495c6a859799cb1c6/src/UIKit/UIView.cs#L121

like image 65
SushiHangover Avatar answered Dec 20 '22 15:12

SushiHangover


Looks like you might be able to use one of the AnimateNotify or AnimateNotifyAsync method overloads as that passes back UICompletionHandler with a bool:

UIView.AnimateNotify(10, () => { }, finished => { });

OR

await UIView.AnimateNotifyAsync(10, () => { }, finished => { });
like image 24
hvaughan3 Avatar answered Dec 20 '22 17:12

hvaughan3