Xamarin Forms - How to detect any gesture - xamarin.forms

I have a view in my Xamarin forms application where I need to detect if the user is interacting with the screen or not, and go back to the previous view afteer some time if there is no activity.
Is there a simple way to detect it from my ViewModel?
Otherwise, detecting the scrolling on a ListView can be enough. But the ListView has no "Scrolled" event... Maybe with a GestureRecognizer ?
What can I do ?

This was interesting so I tried it on a project I am working on
I added this to the scrollview which contains all the views in my page but you can add it to any view you want:
<ScrollView.GestureRecognizers>
<TapGestureRecognizer Command="{Binding HelpClickedCommand}" NumberOfTapsRequired="1" />
</ScrollView.GestureRecognizers>
It's working fine and the command is fired when you tab on the screen but not when you swipe or scroll.
I think the new update of Xamarin will include the Swipe gesture but for now, many people implemented the swipe using pan gesture and some other simple gestures.
Here is a nice article I found with sample code in GitHub and I am sure that I found a nice example with all gestures. If I found it I will update you
Gesture Recognizers with Xamarin.Forms

Related

Possible to implement draggable view with Xamarin Forms without using native Andriod/IOS code?

Is it possible to implement a draggable view with Xamarin View? Is there basically an event that I can use that gets triggered when a finger is pressed on the screen, then moved and then released without having to use native Android/iOS code? I don't mean a swipe event, I know this exists. I am looking for a event so I can let the user be able to drag a rectangle across the screen for example.
Looked for it on the internet, but can only seem to find just normal Touch, Swipe and Tap events. (Although I found it is possible using native Android/IOS code.

Xamarin Forms - Prevent webview from loosing focus on iOS

I'm trying to create an editor using Xamarin Forms.
The editor is a webview with content editable and a toolbar below.
You can check my current implementation here.
It works well on Android, when i tap on the button, it executes the javascript on the webview,the keyboard remains open and the webview doesn't loose focus.
On iOS the webview looses focus and the keyboard closes.
Like this:
Any idea on how can i solve this ?
What i tried so far:
Attach to the buttons an effect that calls ResignFirstResponder.
On the content editable, call focus when bluring.

How to achieve Tinder Style or stack based card swipe animation using xamarin forms across all platforms

After doing enough research, i could able to achieve it using Xamarin forms.
Android it was little tricky as it was not triggering "GestureStatus.Completed" in OnPanUpdated event when user does a swipe to certain area, but android triggers the Tap gesture event at this instance instead of Pan gesture event. So need to handle code separately for Android by collecting the coordinates of the card till where it was swiped.
Also to note for android, i have used a additional extra layout with opacity 0.0 upon the top card in the existing stack, with this we can get a smooth transition when user does the panning or swiping. Practically user swipes a extra layout with visible==true but with opacity 0.0, based on this extra transparent layout movements we will receive events in Tap or Pan gesture methods and we can move the actual top card in the existing stack which is under the transparent layout.
In iPhone and Windows Phone it triggers GestureStatus.Running and GestureStatus.Completed perfectly, so no need to create a hack extra layer. Code snippet is pasted below.
Android sample code to achieve panning or swiping smoothly:
'
private AbsoluteLayout createGestureSupportlayout()
{
AbsoluteLayout gestureSupportlayout = new AbsoluteLayout();
gestureSupportlayout.WidthRequest = frameWidth;
gestureSupportlayout.HeightRequest = frameHeight;
gestureSupportlayout.VerticalOptions = LayoutOptions.Center;
gestureSupportlayout.HorizontalOptions = LayoutOptions.Center;
gestureSupportlayout.Opacity = 0.0;
//In andriod, make Gesture support layout visible if invoices are present
gestureSupportlayout.SetBinding(IsVisibleProperty, "GestureSupportLayoutVisible");
return gestureSupportlayout;
}
'
You can use this plugin: SwipeCardView is a lightweight MVVM friendly user control that brings Tinder-style swipe card view into Xamarin.Forms applications.
In your view xaml:
<swipeCardView:SwipeCardView
ItemsSource="{Binding ViewModelItems}"
SwipedLeftCommand="{Binding SwipedLeftCommand}"
SwipedRightCommand="{Binding SwipedRightCommand}"
TopItem="{Binding TopItem}">
<swipeCardView:SwipeCardView.ItemTemplate>
<DataTemplate x:Name="SomeTemplate">
<!-- Template -->
</DataTemplate>
</swipeCardView:SwipeCardView.ItemTemplate>
</swipeCardView:SwipeCardView>
For a detailed explanation of design, implementation and usage of this library, check my blog post: Create Tinder-like UI in Xamarin Forms using SwipeCardView.
Another framework for this is https://github.com/robinmanuelthiel/swipecards

UWP Desktop mouse won't trigger the gesture

Do we have a way to activate mouse gesture on UWP Desktop for a computer that does not have touch capability? On IOS (in the simulator) we can use the mouse to do PullToRefresh or CellSwipe on Listview.
I use Xamarin.forms
The problem here is that the ListView control in Xamarin.Forms doesn't Support PullToRefresh or CellSwipe on UWP. So you have to implement these functionalities by yourself and you can use the code provided by Shubham Sahu in the comments or you take a look at third pary libraries like Syncfusion. They provide also a ListView Control which is already able to handle PullToRefresh or CellSwipe on UWP.

Gesture Events and StageWebView

Greetings! I have a Flex 4.5 Mobile project rolling, and I've hit a pretty crazy snag. I'm using a StageWebView object to render web pages, embedded within the rest of my spark layouts. I'm trying to add a gesture event to the component that contains the StageWebView, but since the StageWebView object doesn't belong to the Flex stack (it inherits from EventDispatcher, not UIComponent) all of my events seem to be getting eaten. Any mouse based event (click, gesture, etc) doesn't seem to register, and I'm not sure how to get around it. The gesture events work if I use the area where the browser is not rendered. How can I get the gesture event from the outer SkinnableContainer?
StageWebView Reference:
http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/media/StageWebView.html
UIComponent Wrapped StageWebView:
http://soenkerohde.com/2010/11/air-mobile-stagewebview-uicomponent/
Thanks!
I guess you might have to wire up the gesture events yourself, just doing a quick digging in UIComponent.as, it has these:
[Event(name="touchInteractionStarting", type="mx.events.TouchInteractionEvent")]
[Event(name="touchInteractionStart", type="mx.events.TouchInteractionEvent")]
[Event(name="touchInteractionEnd", type="mx.events.TouchInteractionEvent")]
it's not a bug, from what i understand any mouse interaction over a stagewebview means an interaction with the html currently loaded in itself. you should capture events there and trigger it back to the swf.
surely there are some jquery plugins or something that have gestures to help achieving that.
it's a bit of a bummer that you cant overlay stuff over them though.

Resources