diff --git a/tns-core-modules/ui/page/page-common.ts b/tns-core-modules/ui/page/page-common.ts index fa9fd28ef..4de793fc7 100644 --- a/tns-core-modules/ui/page/page-common.ts +++ b/tns-core-modules/ui/page/page-common.ts @@ -1,9 +1,9 @@ -import {ContentView} from "ui/content-view"; +import { ContentView } from "ui/content-view"; import view = require("ui/core/view"); import dts = require("ui/page"); import styleScope = require("../styling/style-scope"); -import {ActionBar} from "ui/action-bar"; -import {PropertyMetadataSettings, PropertyChangeData, Property, ValueSource} from "ui/core/dependency-observable"; +import { ActionBar } from "ui/action-bar"; +import { PropertyMetadataSettings, PropertyChangeData, Property, ValueSource } from "ui/core/dependency-observable"; import * as style from "../styling/style"; import * as fileSystemModule from "file-system"; import * as frameModule from "ui/frame"; @@ -41,9 +41,21 @@ function onActionBarHiddenPropertyChanged(data: PropertyChangeData) { (actionBarHiddenProperty.metadata).onSetNativeValue = onActionBarHiddenPropertyChanged; +const iosSwipeBackNavigationEnabledProperty = new Property("isoSwipeBackNavigationEnabled", "Page", new proxy.PropertyMetadata(true)); + +function iosSwipeBackNavigationEnabledPropertyChanged(data: PropertyChangeData) { + const page = data.object; + if (page.isLoaded) { + page._updateSwipeBackNavigationEnabled(data.newValue); + } +} + +(iosSwipeBackNavigationEnabledProperty.metadata).onSetNativeValue = iosSwipeBackNavigationEnabledPropertyChanged; + export class Page extends ContentView implements dts.Page { public static backgroundSpanUnderStatusBarProperty = backgroundSpanUnderStatusBarProperty; public static actionBarHiddenProperty = actionBarHiddenProperty; + public static iosSwipeBackNavigationEnabledProperty = iosSwipeBackNavigationEnabledProperty; public static navigatingToEvent = "navigatingTo"; public static navigatedToEvent = "navigatedTo"; public static navigatingFromEvent = "navigatingFrom"; @@ -97,10 +109,22 @@ export class Page extends ContentView implements dts.Page { this._setValue(Page.actionBarHiddenProperty, value); } + get iosSwipeBackNavigationEnabled(): boolean { + return this._getValue(Page.iosSwipeBackNavigationEnabledProperty); + } + + set iosSwipeBackNavigationEnabled(value: boolean) { + this._setValue(Page.iosSwipeBackNavigationEnabledProperty, value); + } + public _updateActionBar(hidden: boolean) { // } + public _updateSwipeBackNavigationEnabled(hidden: boolean) { + // + } + get navigationContext(): any { return this._navigationContext; } @@ -197,9 +221,9 @@ export class Page extends ContentView implements dts.Page { public onNavigatingTo(context: any, isBackNavigation: boolean, bindingContext?: any) { this._navigationContext = context; - + //https://github.com/NativeScript/NativeScript/issues/731 - if (!isBackNavigation && !types.isNullOrUndefined(bindingContext)){ + if (!isBackNavigation && !types.isNullOrUndefined(bindingContext)) { this.bindingContext = bindingContext; } this.notify(this.createNavigatedData(Page.navigatingToEvent, isBackNavigation)); diff --git a/tns-core-modules/ui/page/page.d.ts b/tns-core-modules/ui/page/page.d.ts index 7b6db0ae6..42afeb915 100644 --- a/tns-core-modules/ui/page/page.d.ts +++ b/tns-core-modules/ui/page/page.d.ts @@ -61,6 +61,11 @@ declare module "ui/page" { */ public static actionBarHiddenProperty: dependencyObservable.Property; + /** + * Dependency property used to control if swipe back navigation in IOS is enabled. Default value: true + */ + public static isoSwipeBackNavigationEnabledProperty: dependencyObservable.Property; + /** * String value used when hooking to showingModally event. */ @@ -101,6 +106,11 @@ declare module "ui/page" { */ actionBarHidden: boolean; + /** + * Used to control if swipe back navigation in IOS is enabled. Default value: true + */ + iosSwipeBackNavigationEnabled: boolean; + /** * A valid css string which will be applied for all nested UI components (based on css rules). */ diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index 2a6e401f2..bb34a3176 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -1,9 +1,9 @@ import pageCommon = require("./page-common"); -import {View} from "ui/core/view"; +import { View } from "ui/core/view"; import trace = require("trace"); import uiUtils = require("ui/utils"); -import {device} from "platform"; -import {DeviceType} from "ui/enums"; +import { device } from "platform"; +import { DeviceType } from "ui/enums"; import * as utils from "utils/utils"; import getter = utils.ios.getter; @@ -216,7 +216,12 @@ class UIViewControllerImpl extends UIViewController { frame.ios.controller.delegate = this[DELEGATE]; // Workaround for disabled backswipe on second custom native transition - this.navigationController.interactivePopGestureRecognizer.delegate = this.navigationController; + if (frame.canGoBack()) { + this.navigationController.interactivePopGestureRecognizer.delegate = this.navigationController; + this.navigationController.interactivePopGestureRecognizer.enabled = page.iosSwipeBackNavigationEnabled; + } else { + this.navigationController.interactivePopGestureRecognizer.enabled = false; + } frame._processNavigationQueue(page); } @@ -424,6 +429,15 @@ export class Page extends pageCommon.Page { } } + public _updateSwipeBackNavigationEnabled(enabled: boolean) { + const navController = this._ios.navigationController; + if (this.frame && navController && navController.interactivePopGestureRecognizer) { + // Make sure we don't set true if cannot go back + enabled = enabled && this.frame.canGoBack(); + navController.interactivePopGestureRecognizer.enabled = enabled; + } + } + public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number) { let width = utils.layout.getMeasureSpecSize(widthMeasureSpec); let widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);