Skip to content

Default transition of Frame is not used when using NsRouterLink #1784

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
flore2003 opened this issue Apr 18, 2019 · 4 comments · Fixed by #1787
Closed

Default transition of Frame is not used when using NsRouterLink #1784

flore2003 opened this issue Apr 18, 2019 · 4 comments · Fixed by #1787

Comments

@flore2003
Copy link
Contributor

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 5.3.1
  • Cross-platform modules: 5.3.1
  • Android Runtime: 5.3.1
  • iOS Runtime: 5.3.1
  • NativeScript-Angular: 5.3.1
  • Angular: 7.2.9

Describe the bug
When setting the static defaultTransition property on the Frame class, the transition is not used, when navigation is initiated by tapping on an nsRouterLink that does not specify any transition using the [transition] input.

To Reproduce
Set Frame.defaultTransition to any valid NavigationTransition object. Tap on a button that has a nsRouterLink directive with no explicitly set transition. The default transition is not applied to this navigation.

Expected behavior
The default transition specified by setting Frame.defaultTransition should be used when there is no explicitly set transition on an nsRouterLink.

Additional context
This is due to NsRouterLink returning an empty object for the transition in the getTransition method (https://github.com/NativeScript/nativescript-angular/blob/master/nativescript-angular/router/ns-router-link.ts#L117) when no transition is explicitly set. In this case, the transition input defaults to true, which leads the getTransition method to return an empty object for the transition property. As the Frame checks whether the transition property is undefined to decide whether to use the default transition, this leads to the default transition not being used.

@flore2003
Copy link
Contributor Author

As soon as this bug is validated, I could create a PR for this. Should be relatively easy to fix.

For now I have monkey-patched this issue like this:

import { Frame } from 'tns-core-modules/ui/frame';
import { NSRouterLink } from 'nativescript-angular/router/ns-router-link';

// Monkey-patch NS router link to not set empty transition
const originalGetTransition = NSRouterLink.prototype['getTransition'];
NSRouterLink.prototype['getTransition'] = function() {
    const transition = originalGetTransition.apply(this);
    return {
        ...transition,
        transition: (transition.transition && Object.keys(transition.transition).length === 0)
            ? undefined
            : transition.transition
    };
};

// Set default transition
Frame.defaultTransition = {
    name: 'slideBottom',
    duration: 500
};

@tsonevn
Copy link
Contributor

tsonevn commented Apr 19, 2019

Hi @flore2003,
I tested the described scenario and indeed the Frame.defaultTransition will not be applied while navigating via nsRouterLink. I will mark it as a bug. As you have mentioned above, you can make a new PR. Our developers will review it and provide some additional comments on the PR if it is needed.

@flore2003
Copy link
Contributor Author

flore2003 commented Apr 26, 2019

@tsonevn I added the PR, is there anything left to do on my part or will you just review the PR now?

@VladimirAmiorkov
Copy link
Contributor

HI @flore2003 ,

Thank you for your contribution, I am currently reviewing your PR. You can follow the discussion there, if anything needs to change I will update you there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants