Skip to content

Commit

Permalink
fix(picker): does not scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Mar 20, 2018
1 parent 7dbd42f commit b49a45d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 54 deletions.
2 changes: 0 additions & 2 deletions core/src/components/input-shims/input-shims.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ export class InputShims {

@Listen('body:ionInputDidLoad')
protected onInputDidLoad(event: any) {
// TODO: remove if fixed: https://github.com/ionic-team/stencil/issues/576
if (this.didLoad) {
this.registerInput(event.detail);
}
}

@Listen('body:ionInputDidUnload')
protected onInputDidUnload(event: any) {
// TODO: remove if fixed: https://github.com/ionic-team/stencil/issues/576
if (this.didLoad) {
this.unregisterInput(event.detail);
}
Expand Down
2 changes: 0 additions & 2 deletions core/src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,6 @@ export class Menu {
private afterAnimation(isOpen: boolean): boolean {
assert(this.isAnimating, '_before() should be called while animating');

// TODO: this._app.setEnabled(false, 100);

// keep opening/closing the menu disabled for a touch more yet
// only add listeners/css if it's enabled and isOpen
// and only remove listeners/css if it's not open
Expand Down
86 changes: 36 additions & 50 deletions core/src/components/picker-column/picker-column.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Element, Prop } from '@stencil/core';
import { DomController, GestureDetail, PickerColumn, PickerColumnOption } from '../../index';
import { clamp } from '../../utils/helpers';
import { hapticSelectionChanged } from '../../utils';


@Component({
Expand All @@ -25,8 +26,6 @@ export class PickerColumnCmp {
private velocity: number;
private y = 0;

private activeBlock: string;

@Element() private el: HTMLElement;

@Prop({ context: 'dom' }) dom: DomController;
Expand All @@ -53,18 +52,10 @@ export class PickerColumnCmp {
// get the height of one option
this.optHeight = (colEl.firstElementChild ? colEl.firstElementChild.clientHeight : 0);

// TODO block goback-swipe and menu-swipe
// this.activeBlock = 'goback-swipe menu-swipe';

this.refresh();
}

componentDidUnload() {
// TODO block goback-swipe and menu-swipe
// this.activeBlock = 'goback-swipe menu-swipe';
}

optClick(ev: Event, index: number) {
private optClick(ev: Event, index: number) {
if (!this.velocity) {
ev.preventDefault();
ev.stopPropagation();
Expand All @@ -73,7 +64,7 @@ export class PickerColumnCmp {
}
}

setSelected(selectedIndex: number, duration: number) {
private setSelected(selectedIndex: number, duration: number) {
// if there is a selected index, then figure out it's y position
// if there isn't a selected index, then just use the top y position
const y = (selectedIndex > -1) ? ((selectedIndex * this.optHeight) * -1) : 0;
Expand All @@ -84,7 +75,7 @@ export class PickerColumnCmp {
this.update(y, duration, true, true);
}

update(y: number, duration: number, saveY: boolean, emitChange: boolean) {
private update(y: number, duration: number, saveY: boolean, emitChange: boolean) {
// ensure we've got a good round number :)
y = Math.round(y);

Expand Down Expand Up @@ -184,8 +175,7 @@ export class PickerColumnCmp {
}
}


decelerate() {
private decelerate() {
let y = 0;

if (isNaN(this.y) || !this.optHeight) {
Expand Down Expand Up @@ -235,11 +225,10 @@ export class PickerColumnCmp {

const currentIndex = Math.max(Math.abs(Math.round(y / this.optHeight)), 0);

// TODO
// if (currentIndex !== this.lastTempIndex) {
// // Trigger a haptic event for physical feedback that the index has changed
// this._haptic.gestureSelectionChanged();
// }
if (currentIndex !== this.lastTempIndex) {
// Trigger a haptic event for physical feedback that the index has changed
hapticSelectionChanged();
}
this.lastTempIndex = currentIndex;
}

Expand All @@ -248,15 +237,15 @@ export class PickerColumnCmp {
return true;
}

onDragStart(detail: GestureDetail): boolean {
private onDragStart(detail: GestureDetail): boolean {
console.debug('picker, onDragStart', detail, this.startY);

// We have to prevent default in order to block scrolling under the picker
// but we DO NOT have to stop propagation, since we still want
// some "click" events to capture
if (detail.event) {
// TODO this errors
// detail.event.preventDefault();
detail.event.preventDefault();
detail.event.stopPropagation();
}

// remember where the pointer started from
Expand All @@ -282,14 +271,12 @@ export class PickerColumnCmp {
return true;
}

onDragMove(detail: GestureDetail) {
private onDragMove(detail: GestureDetail) {
if (detail.event) {
detail.event.preventDefault();
detail.event.stopPropagation();
}

console.debug('picker, onDragMove', detail);

const currentY = detail.currentY;
this.pos.push(currentY, Date.now());

Expand Down Expand Up @@ -322,7 +309,7 @@ export class PickerColumnCmp {
}
}

onDragEnd(detail: GestureDetail) {
private onDragEnd(detail: GestureDetail) {
if (this.startY === null) {
return;
}
Expand Down Expand Up @@ -373,7 +360,7 @@ export class PickerColumnCmp {
this.decelerate();
}

refresh() {
private refresh() {
let min = this.col.options.length - 1;
let max = 0;
const options = this.col.options;
Expand Down Expand Up @@ -407,8 +394,7 @@ export class PickerColumnCmp {
render() {
const col = this.col;

const options = this.col.options
.map(o => {
const options = this.col.options.map(o => {
if (typeof o === 'string') {
o = { text: o };
}
Expand All @@ -427,28 +413,28 @@ export class PickerColumnCmp {
}

results.push(
<ion-gesture {...{
'canStart': this.canStart.bind(this),
'onStart': this.onDragStart.bind(this),
'onMove': this.onDragMove.bind(this),
'onEnd': this.onDragEnd.bind(this),
'gestureName': 'picker-swipe',
'gesturePriority': 10,
'type': 'pan',
'direction': 'y',
'maxAngle': 20,
'threshold': 10,
'attachTo': 'parent',
'block': this.activeBlock
}}></ion-gesture>,
<ion-gesture
canStart={this.canStart.bind(this)}
onStart={this.onDragStart.bind(this)}
onMove={this.onDragMove.bind(this)}
onEnd={this.onDragEnd.bind(this)}
gestureName='picker-swipe'
gesturePriority={10}
type='pan'
direction='y'
passive={false}
maxAngle={20}
threshold={10}
attachTo='parent'
></ion-gesture>,
<div class='picker-opts' style={{maxWidth: col.optionsWidth}}>
{options.map((o, index) =>
<button
class={{'picker-opt': true, 'picker-opt-disabled': o.disabled}}
disable-activated
onClick={() => this.optClick(event, index)}>
{o.text}
</button>
<button
class={{'picker-opt': true, 'picker-opt-disabled': o.disabled}}
disable-activated
onClick={() => this.optClick(event, index)}>
{o.text}
</button>
)}
</div>
);
Expand Down

0 comments on commit b49a45d

Please sign in to comment.