mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Added iosSwipeBackNavigationEnabled
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
10
tns-core-modules/ui/page/page.d.ts
vendored
10
tns-core-modules/ui/page/page.d.ts
vendored
@ -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).
|
||||
*/
|
||||
|
@ -216,7 +216,12 @@ class UIViewControllerImpl extends UIViewController {
|
||||
frame.ios.controller.delegate = this[DELEGATE];
|
||||
|
||||
// Workaround for disabled backswipe on second custom native transition
|
||||
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);
|
||||
|
Reference in New Issue
Block a user