Skip to content

Commit

Permalink
fix(gestures): adds hybrid disable scroll assistance
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Nov 15, 2016
1 parent 2348d22 commit f9a2424
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
26 changes: 24 additions & 2 deletions src/components/app/app-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Config } from '../../config/config';
import { Ion } from '../ion';
import { OverlayPortal } from '../nav/overlay-portal';
import { Platform } from '../../platform/platform';

import { UIEventManager } from '../../util/ui-event-manager';
export const AppRootToken = new OpaqueToken('USERROOT');

/**
Expand All @@ -23,6 +23,8 @@ export const AppRootToken = new OpaqueToken('USERROOT');
})
export class IonicApp extends Ion implements OnInit {

private _stopScrollPlugin: any;
private _events: UIEventManager = new UIEventManager(false);
@ViewChild('viewport', {read: ViewContainerRef}) _viewport: ViewContainerRef;

@ViewChild('modalPortal', { read: OverlayPortal }) _modalPortal: OverlayPortal;
Expand All @@ -45,6 +47,7 @@ export class IonicApp extends Ion implements OnInit {
super(config, elementRef, renderer);
// register with App that this is Ionic's appRoot component. tada!
app._appRoot = this;
this._stopScrollPlugin = window['IonicStopScroll'];
}

ngOnInit() {
Expand Down Expand Up @@ -109,7 +112,26 @@ export class IonicApp extends Ion implements OnInit {
* @private
*/
_disableScroll(shouldDisableScroll: boolean) {
this.setElementClass('disable-scroll', shouldDisableScroll);
this._events.unlistenAll();

if (shouldDisableScroll) {
var callback = function (e) { e.preventDefault(); };
var pages = this.getNativeElement().querySelectorAll('.ion-page');
for (var i = 0; i < pages.length; ++i) {
this._events.listen(pages[i], 'touchstart', callback, true);
}
this.stopScroll().then();
}
}

stopScroll(): Promise<boolean> {
if (this._stopScrollPlugin) {
return new Promise((resolve, reject) => {
this._stopScrollPlugin.stop(() => resolve(true));
});
} else {
return Promise.resolve(false);
}
}

}
Expand Down
6 changes: 3 additions & 3 deletions src/components/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class App {
private _title: string = '';
private _titleSrv: Title = new Title();
private _rootNav: NavController = null;
private _canDisableScroll: boolean;
private _disableScrollAssist: boolean;

/**
* @private
Expand Down Expand Up @@ -71,7 +71,7 @@ export class App {
// listen for hardware back button events
// register this back button action with a default priority
_platform.registerBackButtonAction(this.navPop.bind(this));
this._canDisableScroll = _config.get('canDisableScroll', false);
this._disableScrollAssist = _config.getBoolean('disableScrollAssist', false);
}

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ export class App {
* scrolling is enabled. When set to `true`, scrolling is disabled.
*/
setScrollDisabled(disableScroll: boolean) {
if (this._canDisableScroll) {
if (this._disableScrollAssist) {
this._appRoot._disableScroll(disableScroll);
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/components/content/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ ion-content.js-scroll > .scroll-content {
will-change: initial;
}

.disable-scroll .ion-page .scroll-content {
pointer-events: none;
}


// Fixed Content (ion-fixed and ion-fab)
// --------------------------------------------------
Expand Down
10 changes: 2 additions & 8 deletions src/components/menu/menu-gestures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Menu } from './menu';
import { SlideEdgeGesture } from '../../gestures/slide-edge-gesture';
import { SlideData } from '../../gestures/slide-gesture';
import { assign } from '../../util/util';
import { GestureController, GesturePriority } from '../../gestures/gesture-controller';
import { GestureController, GesturePriority, DisableScroll } from '../../gestures/gesture-controller';
import { NativeRafDebouncer } from '../../util/debouncer';

/**
Expand All @@ -25,6 +25,7 @@ export class MenuContentGesture extends SlideEdgeGesture {
debouncer: new NativeRafDebouncer(),
gesture: gestureCtrl.create('menu-swipe', {
priority: GesturePriority.MenuSwipe,
disableScroll: DisableScroll.DuringCapture
})
}, options));
}
Expand Down Expand Up @@ -52,13 +53,6 @@ export class MenuContentGesture extends SlideEdgeGesture {
let z = (this.menu.side === 'right' ? slide.min : slide.max);
let stepValue = (slide.distance / z);

console.debug('menu gesture, onSlide', this.menu.side,
'distance', slide.distance,
'min', slide.min,
'max', slide.max,
'z', z,
'stepValue', stepValue);

this.menu.swipeProgress(stepValue);
}

Expand Down
1 change: 1 addition & 0 deletions src/platform/platform-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const PLATFORM_CONFIGS: {[key: string]: PlatformConfig} = {
swipeBackThreshold: 40,
tapPolyfill: isIOSDevice,
virtualScrollEventAssist: !(window.indexedDB),
disableScrollAssist: isIOSDevice,
},
isMatch(p: Platform) {
return p.isPlatformMatch('ios', ['iphone', 'ipad', 'ipod'], ['windows phone']);
Expand Down

0 comments on commit f9a2424

Please sign in to comment.