Cancel page transition animation programmatically in NativeScript - nativescript

How can I cancel the page transition animation programmatically in nativeScript?

You can pass animated: false in NavigationOptions to disable the transition programmatically:
this.routerExtensions.navigate(["PATH"], {
animated: false
});
This is possible by injecting the routerExtensions instance via the constructor of your component:
constructor(private routerExtensions: RouterExtensions)
For more information see the {N} docu about specifiying a page transition.

Related

How to programatically scroll CollectionView after its rendering

I want to programatically scroll CollectionView after its rendering however, I can't seem to find the lifecycle hook to call the scroll function in.
Calling the scroll function in OnAppearing hook is out of the question because that hook exists only in ContentPage and my CollectionView exists in a LazyView that gets initialized after clicking a button on a page.
private void ScrollToItemAtPosition(int idx) {
PhotoCollection.ScrollTo(idx, position: ScrollToPosition.Center);
}
Any ideas? Thanks!

Hide action bar in NativeScript Angular

From NativeScript official documentation:
Тhе actionBarVisibility is a property that controls the visibility of the Navigation Bar in iOS and the Action Bar in Android for the current Frame. It should be set directly to the Frame and has three option values auto, never, always.
<Frame id="my-frame-id" actionBarVisibility="never" defaultPage="home/home-page"/>
But I found no Frame tag in NativeScript Angular.
Where can I found it? Or how do I hide action bar in NativeScript Angular?
You can add the actionBarVisibility to the page-router-outlet element in the app.component.html like the snippet below:
<page-router-outlet actionBarVisibility="never"></page-router-outlet>
To hide it for specific pages you can set the actionBarHidden property of the Page class like the snippet below:
import { Page } from '#nativescript/core';
#Component({
...
})
export class MyComponent {
constructor(private page: Page) {
page.actionBarHidden = true;
}
}

Nativescript swipe gesture not working on Android with ScrollView

I am using a swipe gesture to turn pages. It works great on ios. However, the Android version isn't working where there is a scrollview in play.
I am using Nativescript Pro UI to have a side-drawer. I want to put the gesture on the
Inside of the tkMainContent there is a scrollview.
Swipe doesn't even log a console.log event when I swipe inside the scrollview area. Is there a way to get it to work for Android?
Here is my typescript code:
let cbView = this.contentbody.nativeElement;
cbView.on('swipe', (args: SwipeGestureEventData) =>{
console.log("Swipe Direction: " + args.direction);
let topNextView = cbView.getViewById('topNext');
let topBackView = cbView.getViewById('topBack');
this.playerService.setIsBusyLoading(false);
if(args.direction === 1) {
topBackView.notify({eventName: 'tap', object: topBackView});
}
if(args.direction === 2) {
topNextView.notify({eventName: 'tap', object: topNextView});
}
});
}
As I said I"m not getting Swipe Direction 2 when swiping on Android. If I swipe above where I have the scrollview start, such as in the heading of my document, then it picks up the swipe.

How to disable scroll in Webview?

Is there a way i can disable scroll in webview?
For instance
<WebView rc="https://www.npmjs.com/package/nativescript-
openurl" height="300" tap="ontapvw" ></WebView>
Please find the native script playground link attached:
https://play.nativescript.org/?template=play-js&id=hh7ITB&v=2
You can disable the scroll by accessnig the native WebView and apoplying a native solution (direct access to the native APIs is one of the greatest advantages of nativeScript as this allows you to work with native solutions)
Example for Android
XML
<WebView loaded="onWebViewLoaded" src="https://www.npmjs.com/package/nativescript-openurl" height="300" ></WebView>
JavaScript
function onWebViewLoaded(args) {
let wv = args.object;
console.log(wv);
if(isAndroid) {
let webViewAndroid = wv.nativeView;
console.log(webViewAndroid);
// Hide the scrollbars, but not disable scrolling:
webViewAndroid.setVerticalScrollBarEnabled(false);
webViewAndroid.setHorizontalScrollBarEnabled(false);
// Disable scrolling
let myListener = new android.view.View.OnTouchListener({
onTouch: function (view, event) {
return (event.getAction() == android.view.MotionEvent.ACTION_MOVE);
}
})
webViewAndroid.setOnTouchListener(myListener);
}
}
exports.onWebViewLoaded = onWebViewLoaded;
Playground demo can be found here

Capture touch events in Xamarin.Forms for Android

I am creating an app that allows the user to drag and drop to put one image on top of another using Xamarin.Forms.
On iOS I managed to hack together a workable gesture recognizer renderer by creating a custom ContentView and a custom renderer for it, which then attaches native gesture recognizers to itself based on the GestureRecognizers elements. To do that I disable the default EventTracker and implement my own, with overridden GetNativeRecognizer method
in the custom renderer:
public InteractiveContentViewRenderer () : base ()
{
AutoTrack = false;
events = new InteractiveEventTracker (this);
}
in the custom event tracker:
public InteractiveEventTracker (IVisualElementRenderer renderer) : base (renderer)
{
this.Renderer = renderer;
}
protected override MonoTouch.UIKit.UIGestureRecognizer GetNativeRecognizer (Xamarin.Forms.IGestureRecognizer recognizer)
{
var gestureRecognizer = base.GetNativeRecognizer (recognizer);
if (gestureRecognizer == null) {
// here I find my own native recognizer and return it
}
}
On Android, however, so far I haven't figured out how to achieve the same thing. There's no EventTracker in Android, I think I'll have to implement some Android View for this to work but I haven't figured it out so far.
Has anyone managed to hack together touch events in Xamarin.Forms for Android? I'd like to know at least the basic structure of the hack?
Read this: http://blog.twintechs.com/cross-platform-compositional-gesture-advanced-xamarin-forms-techniques-for-flexible-and-performant-cross-platform-apps-part-4
There's a lot about custom gestures in Xamarin.Forms
The source is here: https://github.com/twintechs/TwinTechsFormsLib/tree/master/TwinTechsForms/TwinTechsForms.Droid/TwinTechs/Gestures

Resources