Events for native controls in Xamarin Forms? - events

I just checked out consuming native UI iOS/Android controls in Xamarin Forms. One thing I don't understand is what events to specify as triggering an update for bindings. The article mentions UISwitch as an example and specifies the ValueChanged event for triggering updating bindings. But where can I find information about which events can be used for other iOS and Android controls?
As an example I tried UITextView and couldn't find any info on which events is being supported in the official docs. Some experimenting and I found I could use an event called "Changed", but there has to be some docs somewhere for this I guess. Antone know where?

iOS uses the delegate pattern heavily. UITextView uses the UITextViewDelegate - in native iOS you would provide your own delegate that is responsible for responding to events raised by the control

Related

How to implement listView item with longPress event

I need a ListView with long pressed event handler.
When listviewItem is longpressed, an popup should appear for example.
Does anyone knows, if this is possible with xamarin.forms MVVM?
Thanks
There is a known issue about this in xamarin forms, you can check it here: [Enhancement] LongPressGestureRecognizer.
And just as this remark mentioned :
this will probably be in .NET MAUI but won't make it into
Xamarin.Forms anymore. If needed check out the Xamarin Community
Toolkit or other relevant libraries
But there are several workarounds:
You can refer to article: Longpress Event For Image In Xamarin.Forms.
And you can also check thread : How to make long press gesture in Xamarin Forms?

Xamarin Forms - Syncfusion SF Schedule swipe Error - iOS only

I have a Syncfusion schedule used in month view, but once I swipe to go to the next month the app crashes and shows me this error:
"Event registration is overwriting existing delegate. Either just use events or your own delegate: Foundation.NSObject UIKit.UIGestureRecognizer+UIGestureRecognizerDelegate"
This only happens on my iOS project and is fine on Android.
I have no custom renderers associated with the feature.
Would anyone know what is causing this?
iOS controls have some gesture events and if you use those gesture events you can't add gesture recognizes or the app will crash. So it is likely that SF control is using those events.

Xamarin.Forms equivalent to overriding iOS's SendEvent

I'm working on inactivity detection.
I have successfully done so in iOS by subclassing UIApplication and overriding SendEvent as outlined here.
I know I could implement this separately for both iOS and Android, but I'd rather have a cross-platform Forms approach by intercepting all touch events and resetting my timers. I'd rather not have to add a touch event handler to all my pages either.
I was unable to find a cross platform approach. I was able to accomplish this by leaving the timer related information in core Forms project and implement the touch event handlers separately for iOS and Android. I handled the iOS touch events as outlined in the link in the OP, but for Android I took the approach of subclassing Activity due to the presence of the OnUserInteraction() method.
Initially I thought I would have to force Xamarin to use my subclassed Activity for all pages that I use in Xamarin, but I was mistaken. AdamMeaney over on the Xamarin forums was able to help with providing a solution for the Android side of things with regards to subclassing an Android activity. As it turns out, Xamarin only uses one Activity which inherits from Xamarin.Forms.Platform.Android.FormsAppCompatActivity. I used the MainAcitivty provided by Xamarin in the Droid project. From there, overriding the OnUserInteraction() proved to be quite simple:
public override void OnUserInteraction()
{
base.OnUserInteraction();
//Do other stuff
}
It would seem to me that all you really have to do on the platform side is get notified whenever a new touch event occurs. Unless I am missing something it seems you can do all of the timer stuff in the PCL core Forms project and call that code from the platform specific code that runs when a touch is detected.
So if on Android ( I did not verify, but I would assume so) there is a similar way to handle any touch, device wide, then it would seem that all you have to do is implement that event handler, as you did for iOS, and call into your Forms core code to handle the timer(s).
To clarify: On the platform side, just handle the touch events globally and then call into code in the Forms core thus only having to implement the timer functionality once. Or so it would seem unless I am missing something.
If you want to make a feature request for Xamarin Form, please do so at Xamarin's user voice page: xamarin.uservoice.com
I suspect Forms would just have to do as outlined above... handle device wide touches on each platform and then have a virtual method in Forms core code that is called whenever a touch occurs.

Appcelerator controller appear/disapear methods

I'm pretty new to Appcelerator and was wondering what the listeners for the view life cycle are?
For example, if I wanted to detect the iOS viewWillAppear and viewDidDisappear methods, or Androids OnResume, OnPause methods, then how would I do this the "Appcelerator" way?
I've searched around on the web, but only able to find in the Titanium documentation info about the application state such as Active, Suspended, ect. I need a controller, or window, specific listener to react to.
Thanks!
Titanium abstracts those events for you - so you don't have to worry about writing them for iOS/Android each.
Check out the Titanium.App documentation (http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App). You can see what events are available at the app level (of course, each Titanium components has it's own events - but those are at app level).
If I understand your question, the relevant events for you are paused and resumed - when the app goes in the background and then back to foreground.

After assigning GetViewForAnnotation, Xamarin.Forms class doesn't receive Click event

I have a Xamarin.Forms page with a map containing numerous pins. I've built a custom iOS renderer to change the image of the displayed pin.
Once I assign the GetViewForAnnotation delegate, my Xamarin.Forms class no longer receives the "Clicked" event. I can access it through the custom renderer, I do believe, but what I want to do when the user taps the title of the pin is push another Xamarin.Forms page to the navigation stack, and I don't know how to give control back to my Xamarin.Forms app from within my Xamarin.iOS app.
I have a feeling I'll need this type of logic in a few other places... where I need to handle a CustomRenderer event but then pass control back to the Xamarin.Forms app for navigation or other purposes.
So I have a couple directions I'd like to go:
1 - More straightforward - get my "Clicked" event to fire in the Xamarin.Forms app when the map's pin is clicked, even though the iOS app is handling the creation of the pin via a CustomRenderer
2 - More advanced and customizable - pass control back to my Xamarin.Forms app (maybe raise an event related to the Renderer level?)
I'd prefer at this time to just get my Clicked event back, but I'm guessing that may not work once I assign the GetViewForAnnotation event in the CustomRenderer.
From what I read, you can detect the annotation click within your renderer.
Within your renderer in the OnElementChanged you can get access to the View in the Xamarin.Forms PCL it relates to.
A few possibilities to consider going forward:-
a) Use MessagingCenter to convey messaging between interests (see
here).
b) Use the standard event raising, i.e. public event
EventHandler<someEventArgs> OnSomeEvent through your View in your
PCL.
c) Use an ICommand approach on your View in your PCL if your
more MVVM orientated, and invoke this way instead.
Once you have your notification back through your View / Page, depending on where your doing things, you can then do a normal navigation based on the information you have been given from your platform-specific renderer in the PCL.

Resources