Skip to content

Platform specific page transitions. #389

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

Closed
m-abs opened this issue Aug 8, 2016 · 4 comments
Closed

Platform specific page transitions. #389

m-abs opened this issue Aug 8, 2016 · 4 comments

Comments

@m-abs
Copy link
Contributor

m-abs commented Aug 8, 2016

Thank you for adding page transitions to the router.

Could you also add platform specific page transitions?
{N}'s NavigationEntry have three transition parameters:
https://docs.nativescript.org/api-reference/interfaces/_ui_frame_.navigationentry.html#transition

  • transition
  • transitionAndroid
  • transitionIOS

In the current implementation nativescript-angular only supports transition, so if we want to set another transition for iOS than we want for Android we can't do that.

@NickIliev
Copy link

NickIliev commented Aug 8, 2016

Hello @m-abs ,

You can use Angular-2 directives (like *ngIf, ngSwitch or custom ones) to create your own platform-specific controls.
e.g. with custom directive

my-page.component.ts

import {Component, Directive, ViewContainerRef, TemplateRef, Inject} from '@angular/core';
import {Device, platformNames} from "platform";
import {DEVICE} from "nativescript-angular/platform-providers";

@Directive({ selector: "[ifAndroid]" })
export class IfAndroidDirective {
    constructor( @Inject(DEVICE) device: Device, container: ViewContainerRef, templateRef: TemplateRef<Object>) {
        if (device.os === platformNames.android) {
            container.createEmbeddedView(templateRef);
        }
    }
}

@Directive({ selector: "[ifIos]" })
export class IfIosDirective {
    constructor( @Inject(DEVICE) device: Device, container: ViewContainerRef, templateRef: TemplateRef<Object>) {
        if (device.os === platformNames.ios) {
            container.createEmbeddedView(templateRef);
        }
    }
}

@Component({
    selector: ' my-page.component',
    directives: [IfIosDirective, IfAndroidDirective],
    templateUrl: " my-page.component.html",
})

export class CreateCustomDirectiveExampleComponent{

}

my-page.component.html

<Button *ifAndroid [nsRouterLink]="yourLink" pageTransition="explode" ></Button >
<Button *ifIos [nsRouterLink]="yourLink" pageTransition="curl" ></Button >

Another example with the usage of *ngIf can also be applicable for your case (with a little modification to set the specific page transition).

@m-abs
Copy link
Contributor Author

m-abs commented Aug 8, 2016

Hi @NickIliev

Thank you for your suggestion.

Unfortunately it only covers using the [nsRouterLink]-directive for navigating. It doesn't cover using the RouterExtensions-class directly.

@vakrilov
Copy link
Contributor

In code you can do:

import {isAndroid, isIOS} from "platform";

And pass different transitions based on the isAndroid and isIOS variables.

@m-abs
Copy link
Contributor Author

m-abs commented Aug 15, 2016

That's a good idea, thank you.

@m-abs m-abs closed this as completed Aug 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants