mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 11:41:20 +08:00
fix(picker): does not scroll
This commit is contained in:
@ -52,7 +52,6 @@ export class InputShims {
|
|||||||
|
|
||||||
@Listen('body:ionInputDidLoad')
|
@Listen('body:ionInputDidLoad')
|
||||||
protected onInputDidLoad(event: any) {
|
protected onInputDidLoad(event: any) {
|
||||||
// TODO: remove if fixed: https://github.com/ionic-team/stencil/issues/576
|
|
||||||
if (this.didLoad) {
|
if (this.didLoad) {
|
||||||
this.registerInput(event.detail);
|
this.registerInput(event.detail);
|
||||||
}
|
}
|
||||||
@ -60,7 +59,6 @@ export class InputShims {
|
|||||||
|
|
||||||
@Listen('body:ionInputDidUnload')
|
@Listen('body:ionInputDidUnload')
|
||||||
protected onInputDidUnload(event: any) {
|
protected onInputDidUnload(event: any) {
|
||||||
// TODO: remove if fixed: https://github.com/ionic-team/stencil/issues/576
|
|
||||||
if (this.didLoad) {
|
if (this.didLoad) {
|
||||||
this.unregisterInput(event.detail);
|
this.unregisterInput(event.detail);
|
||||||
}
|
}
|
||||||
|
@ -362,8 +362,6 @@ export class Menu {
|
|||||||
private afterAnimation(isOpen: boolean): boolean {
|
private afterAnimation(isOpen: boolean): boolean {
|
||||||
assert(this.isAnimating, '_before() should be called while animating');
|
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
|
// keep opening/closing the menu disabled for a touch more yet
|
||||||
// only add listeners/css if it's enabled and isOpen
|
// only add listeners/css if it's enabled and isOpen
|
||||||
// and only remove listeners/css if it's not open
|
// and only remove listeners/css if it's not open
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Component, Element, Prop } from '@stencil/core';
|
import { Component, Element, Prop } from '@stencil/core';
|
||||||
import { DomController, GestureDetail, PickerColumn, PickerColumnOption } from '../../index';
|
import { DomController, GestureDetail, PickerColumn, PickerColumnOption } from '../../index';
|
||||||
import { clamp } from '../../utils/helpers';
|
import { clamp } from '../../utils/helpers';
|
||||||
|
import { hapticSelectionChanged } from '../../utils';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -25,8 +26,6 @@ export class PickerColumnCmp {
|
|||||||
private velocity: number;
|
private velocity: number;
|
||||||
private y = 0;
|
private y = 0;
|
||||||
|
|
||||||
private activeBlock: string;
|
|
||||||
|
|
||||||
@Element() private el: HTMLElement;
|
@Element() private el: HTMLElement;
|
||||||
|
|
||||||
@Prop({ context: 'dom' }) dom: DomController;
|
@Prop({ context: 'dom' }) dom: DomController;
|
||||||
@ -53,18 +52,10 @@ export class PickerColumnCmp {
|
|||||||
// get the height of one option
|
// get the height of one option
|
||||||
this.optHeight = (colEl.firstElementChild ? colEl.firstElementChild.clientHeight : 0);
|
this.optHeight = (colEl.firstElementChild ? colEl.firstElementChild.clientHeight : 0);
|
||||||
|
|
||||||
// TODO block goback-swipe and menu-swipe
|
|
||||||
// this.activeBlock = 'goback-swipe menu-swipe';
|
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUnload() {
|
private optClick(ev: Event, index: number) {
|
||||||
// TODO block goback-swipe and menu-swipe
|
|
||||||
// this.activeBlock = 'goback-swipe menu-swipe';
|
|
||||||
}
|
|
||||||
|
|
||||||
optClick(ev: Event, index: number) {
|
|
||||||
if (!this.velocity) {
|
if (!this.velocity) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
@ -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 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
|
// if there isn't a selected index, then just use the top y position
|
||||||
const y = (selectedIndex > -1) ? ((selectedIndex * this.optHeight) * -1) : 0;
|
const y = (selectedIndex > -1) ? ((selectedIndex * this.optHeight) * -1) : 0;
|
||||||
@ -84,7 +75,7 @@ export class PickerColumnCmp {
|
|||||||
this.update(y, duration, true, true);
|
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 :)
|
// ensure we've got a good round number :)
|
||||||
y = Math.round(y);
|
y = Math.round(y);
|
||||||
|
|
||||||
@ -184,8 +175,7 @@ export class PickerColumnCmp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private decelerate() {
|
||||||
decelerate() {
|
|
||||||
let y = 0;
|
let y = 0;
|
||||||
|
|
||||||
if (isNaN(this.y) || !this.optHeight) {
|
if (isNaN(this.y) || !this.optHeight) {
|
||||||
@ -235,11 +225,10 @@ export class PickerColumnCmp {
|
|||||||
|
|
||||||
const currentIndex = Math.max(Math.abs(Math.round(y / this.optHeight)), 0);
|
const currentIndex = Math.max(Math.abs(Math.round(y / this.optHeight)), 0);
|
||||||
|
|
||||||
// TODO
|
if (currentIndex !== this.lastTempIndex) {
|
||||||
// if (currentIndex !== this.lastTempIndex) {
|
// Trigger a haptic event for physical feedback that the index has changed
|
||||||
// // Trigger a haptic event for physical feedback that the index has changed
|
hapticSelectionChanged();
|
||||||
// this._haptic.gestureSelectionChanged();
|
}
|
||||||
// }
|
|
||||||
this.lastTempIndex = currentIndex;
|
this.lastTempIndex = currentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,15 +237,15 @@ export class PickerColumnCmp {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onDragStart(detail: GestureDetail): boolean {
|
private onDragStart(detail: GestureDetail): boolean {
|
||||||
console.debug('picker, onDragStart', detail, this.startY);
|
console.debug('picker, onDragStart', detail, this.startY);
|
||||||
|
|
||||||
// We have to prevent default in order to block scrolling under the picker
|
// 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
|
// but we DO NOT have to stop propagation, since we still want
|
||||||
// some "click" events to capture
|
// some "click" events to capture
|
||||||
if (detail.event) {
|
if (detail.event) {
|
||||||
// TODO this errors
|
detail.event.preventDefault();
|
||||||
// detail.event.preventDefault();
|
detail.event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
// remember where the pointer started from
|
// remember where the pointer started from
|
||||||
@ -282,14 +271,12 @@ export class PickerColumnCmp {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onDragMove(detail: GestureDetail) {
|
private onDragMove(detail: GestureDetail) {
|
||||||
if (detail.event) {
|
if (detail.event) {
|
||||||
detail.event.preventDefault();
|
detail.event.preventDefault();
|
||||||
detail.event.stopPropagation();
|
detail.event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug('picker, onDragMove', detail);
|
|
||||||
|
|
||||||
const currentY = detail.currentY;
|
const currentY = detail.currentY;
|
||||||
this.pos.push(currentY, Date.now());
|
this.pos.push(currentY, Date.now());
|
||||||
|
|
||||||
@ -322,7 +309,7 @@ export class PickerColumnCmp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDragEnd(detail: GestureDetail) {
|
private onDragEnd(detail: GestureDetail) {
|
||||||
if (this.startY === null) {
|
if (this.startY === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -373,7 +360,7 @@ export class PickerColumnCmp {
|
|||||||
this.decelerate();
|
this.decelerate();
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh() {
|
private refresh() {
|
||||||
let min = this.col.options.length - 1;
|
let min = this.col.options.length - 1;
|
||||||
let max = 0;
|
let max = 0;
|
||||||
const options = this.col.options;
|
const options = this.col.options;
|
||||||
@ -407,8 +394,7 @@ export class PickerColumnCmp {
|
|||||||
render() {
|
render() {
|
||||||
const col = this.col;
|
const col = this.col;
|
||||||
|
|
||||||
const options = this.col.options
|
const options = this.col.options.map(o => {
|
||||||
.map(o => {
|
|
||||||
if (typeof o === 'string') {
|
if (typeof o === 'string') {
|
||||||
o = { text: o };
|
o = { text: o };
|
||||||
}
|
}
|
||||||
@ -427,28 +413,28 @@ export class PickerColumnCmp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
results.push(
|
results.push(
|
||||||
<ion-gesture {...{
|
<ion-gesture
|
||||||
'canStart': this.canStart.bind(this),
|
canStart={this.canStart.bind(this)}
|
||||||
'onStart': this.onDragStart.bind(this),
|
onStart={this.onDragStart.bind(this)}
|
||||||
'onMove': this.onDragMove.bind(this),
|
onMove={this.onDragMove.bind(this)}
|
||||||
'onEnd': this.onDragEnd.bind(this),
|
onEnd={this.onDragEnd.bind(this)}
|
||||||
'gestureName': 'picker-swipe',
|
gestureName='picker-swipe'
|
||||||
'gesturePriority': 10,
|
gesturePriority={10}
|
||||||
'type': 'pan',
|
type='pan'
|
||||||
'direction': 'y',
|
direction='y'
|
||||||
'maxAngle': 20,
|
passive={false}
|
||||||
'threshold': 10,
|
maxAngle={20}
|
||||||
'attachTo': 'parent',
|
threshold={10}
|
||||||
'block': this.activeBlock
|
attachTo='parent'
|
||||||
}}></ion-gesture>,
|
></ion-gesture>,
|
||||||
<div class='picker-opts' style={{maxWidth: col.optionsWidth}}>
|
<div class='picker-opts' style={{maxWidth: col.optionsWidth}}>
|
||||||
{options.map((o, index) =>
|
{options.map((o, index) =>
|
||||||
<button
|
<button
|
||||||
class={{'picker-opt': true, 'picker-opt-disabled': o.disabled}}
|
class={{'picker-opt': true, 'picker-opt-disabled': o.disabled}}
|
||||||
disable-activated
|
disable-activated
|
||||||
onClick={() => this.optClick(event, index)}>
|
onClick={() => this.optClick(event, index)}>
|
||||||
{o.text}
|
{o.text}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user