Added iosSwipeBackNavigationEnabled

This commit is contained in:
vakrilov
2016-10-04 13:31:17 +03:00
parent 702b7eadd3
commit 53a60e2553
3 changed files with 57 additions and 9 deletions

View File

@ -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) {
(<proxy.PropertyMetadata>actionBarHiddenProperty.metadata).onSetNativeValue = onActionBarHiddenPropertyChanged;
const iosSwipeBackNavigationEnabledProperty = new Property("isoSwipeBackNavigationEnabled", "Page", new proxy.PropertyMetadata(true));
function iosSwipeBackNavigationEnabledPropertyChanged(data: PropertyChangeData) {
const page = <Page>data.object;
if (page.isLoaded) {
page._updateSwipeBackNavigationEnabled(data.newValue);
}
}
(<proxy.PropertyMetadata>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));

View File

@ -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).
*/

View File

@ -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);