NativeScript 4.1的发行说明显示,当使用带有Angular的NativeScript时,模态视图现在也支持导航 .
我尝试了示例项目https://github.com/NativeScript/nativescript-sdk-examples-ng,但似乎在使用带有Angular的NativeScript时模态导航仍然存在一些问题 .
你能帮我解决这个问题或者说明一个更好的例子吗?非常感谢!
如何重现:
-
确保已安装NativeScript 4.1
-
克隆示例并在iPhone或iPhone模拟器中运行它
git clone https://github.com/NativeScript/nativescript-sdk-examples-ng cd nativescript-sdk-examples-ng / tns运行ios --emulator
-
将显示“NativeScript代码示例”列表
-
向下滚动到“模态页面”行并点击它 - >页面将显示“模态页面”
-
点击行"Modal page navigation" - >页面"Modal page navigation"将显示
-
点击按钮"SHOW MODAL" - >页面"MODAL VIEW"将显示为从底部滑入的模态视图
-
点击按钮"Next page" - >页面"Second Modal Page"将会显示
-
点击按钮"CLOSE MODAL" - >模态视图将通过滑动返回底部消失,页面"Modal page navigation"将再次可见
-
点击左上角的后退按钮 - >页面"Modal page navigation"消失到右侧,页面"Modal page"再次可见并且 the following error is logged in the terminal 但是预计不会出现此错误:
CONSOLE ERROR文件:///app/tns_modules/@angular/core/bundles/core.umd.js:1590:24:错误错误:未捕获(在承诺中):错误:当前在页面返回导航中 - 应该重新附加组件激活的activateWith @ file:///app/tns_modules/nativescript-angular/router/page-router-outlet.js:212:28 [angular] activateRoutes @ file:/// app / tns_modules / @ angular / router / bundles / router .umd.js:4269:52 [angular] file:///app/tns_modules/@angular/router/bundles/router.umd.js:4221:33 [angular] forEach @ [native code] [angular] activateChildRoutes @ file:///app/tns_modules/@angular/router/bundles/router.umd.js:4220:36 [angular] activateRoutes @ file:///app/tns_modules/@angular/router/bundles/router.umd . js:4241:41 [angular] file:///app/tns_modules/@angular/router/bundles/router.umd.js:4221:33 [angular] forEach @ [native code] [angular] activateChildRoutes @ file:/ //app/tns_modules/@angular/router/bundles/router.umd.js:4220:36 [angular] activate @ file:///app/tns_modules/@angular/router/bundles/router.umd.js:4142 :33 [角] fil
- 点按任意行,例如"Modal page navigation" - >预计例如页面"Modal page navigation"将再次显示, but the UI does not change. 相反,例如攻丝"Modal page example" the following same error as above is logged on terminal again.
所以似乎路由器不再起作用 .
解决方法:在文件nativescript-sdk-examples-ng / app / modal-page / modal-page-navigation / second-modal-view-content.component.ts替换
onClose(): void {
this._params.closeCallback("return value");
}
同
onClose(): void {
this.router.back();
setTimeout(() => {
this._params.closeCallback("return value");
}, 1000);
}
解决方法将首先在模态视图中返回一页,然后关闭模态视图 . 由于等待1秒钟,用户可以看到这种不期望的行为 . 没有等待足够长的时间,解决方法将无法工作(例如100毫秒似乎不够) .
非常感谢您的帮助!