【问题标题】:How to use Page Transition in NativeScript如何在 NativeScript 中使用页面转换
【发布时间】:2016-10-25 18:26:18
【问题描述】:

我正在尝试使用来自routerExtensions 的页面转换,但没有成功。 (2.3.0)

我在js中试过:

this.routerExtensions.navigate(
    [
        'myPage'
    ], 
    {
        animated: true, 
        transition: 
        {
            name: 'flip', 
            duration: 2000, 
            curve: 'linear'
        }
    } 
);

我在 xml 中尝试过:

<Button text="Goto myPage" [nsRouterLink]="['/myPage']" pageTransition="flip"></Button>

当我导航到“myPage”但没有动画时,这两种方式都有效。 是否需要更改设置以“启用”动画,或者我是否遗漏了一些明显的东西?

【问题讨论】:

  • 我知道这是一个老问题,但我想知道您是否设法解决了这个问题?我在 2020 年面临同样的问题。
  • 2021 年的我。有人有答案吗?
  • 我发现它在儿童路线中不起作用

标签: angular2-nativescript


【解决方案1】:

根据所提供的上下文,很难准确地说出它为什么不起作用。

您真正需要做的就是:

设置您要路由到的组件:

app-routing.module.ts

const routes: Routes = [
  { path: '', pathMatch: 'full', redirectTo: '/home' },
  { path: 'home', component: HomeComponent },
  { path: 'about', component: AboutComponent },
  { path: 'contact', component: ContactComponent },
];

使用您的router-outlet 在组件中注入本机路由器扩展

app.component.ts

import { RouterExtensions } from "@nativescript/angular/router";

@Component({
    selector: "ns-app",
    templateUrl: "./app.component.html"
})
export class AppComponent {
  constructor(private routerExtensions: RouterExtensions) {}

  public navigate(link: string): void {
    this.routerExtensions.navigate([link], {
      animated: true,
      transition: { name: 'slide' }
    });
  }
}

当然还有办法调用这个方法 app.component.ts

<StackLayout>
  <FlexboxLayout>
    <Button text="Home" (tap)="navigate('home')"></Button>
    <Button text="About" (tap)="navigate('about')"></Button>
    <Button text="Contact" (tap)="navigate('contact')"></Button>
  </FlexboxLayout>
  <StackLayout>
    <page-router-outlet actionBarVisibility="never"></page-router-outlet>
  </StackLayout>
</StackLayout>

我已经在https://github.com/gsavchenko/nativescript-page-transitions 设置了一个工作存储库来演示这一点。这些也可以在不使用 nativescript 本地路由 API 的角度实现。

干杯, 如果还有其他问题,请告诉我。

【讨论】:

【解决方案2】:

看看 nativescript 的 Groceries 应用,它是所有 nativescript 组件的绝佳资源 - https://github.com/NativeScript/sample-Groceries。你可以在里面找到他们给的转场动画。

祝你好运。如果需要任何帮助,请询问。

【讨论】:

  • 我正在寻找页面过渡动画。不仅仅是页面加载事件上的动画。这不是在回答我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-19
  • 1970-01-01
  • 2021-02-12
  • 2019-12-19
  • 2022-06-21
相关资源
最近更新 更多