mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
perf(gesture): lazy loaded dynamic ES module
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { Component, Element, Event, EventEmitter, Prop, State, Watch } from '@stencil/core';
|
||||
import { Component, Element, Event, EventEmitter, Prop, QueueApi, State, Watch } from '@stencil/core';
|
||||
|
||||
import { CheckboxInput, CheckedInputChangeEvent, Color, GestureDetail, Mode, StyleEvent } from '../../interface';
|
||||
import { CheckboxInput, CheckedInputChangeEvent, Color, Gesture, GestureDetail, Mode, StyleEvent } from '../../interface';
|
||||
import { hapticSelection } from '../../utils/haptic';
|
||||
import { deferEvent, renderHiddenInput } from '../../utils/helpers';
|
||||
import { createColorClasses, hostContext } from '../../utils/theme';
|
||||
@ -18,9 +18,12 @@ export class Toggle implements CheckboxInput {
|
||||
private inputId = `ion-tg-${toggleIds++}`;
|
||||
private nativeInput!: HTMLInputElement;
|
||||
private pivotX = 0;
|
||||
private gesture?: Gesture;
|
||||
|
||||
@Element() el!: HTMLElement;
|
||||
|
||||
@Prop({ context: 'queue' }) queue!: QueueApi;
|
||||
|
||||
@State() activated = false;
|
||||
@State() keyFocus = false;
|
||||
|
||||
@ -86,18 +89,20 @@ export class Toggle implements CheckboxInput {
|
||||
}
|
||||
|
||||
@Watch('disabled')
|
||||
emitStyle() {
|
||||
disabledChanged() {
|
||||
this.ionStyle.emit({
|
||||
'interactive-disabled': this.disabled,
|
||||
});
|
||||
if (this.gesture) {
|
||||
this.gesture.disabled = this.disabled;
|
||||
}
|
||||
}
|
||||
|
||||
componentWillLoad() {
|
||||
this.ionStyle = deferEvent(this.ionStyle);
|
||||
this.emitStyle();
|
||||
}
|
||||
|
||||
componentDidLoad() {
|
||||
async componentDidLoad() {
|
||||
const parentItem = this.nativeInput.closest('ion-item');
|
||||
if (parentItem) {
|
||||
const itemLabel = parentItem.querySelector('ion-label');
|
||||
@ -106,6 +111,18 @@ export class Toggle implements CheckboxInput {
|
||||
this.nativeInput.setAttribute('aria-labelledby', itemLabel.id);
|
||||
}
|
||||
}
|
||||
|
||||
this.gesture = (await import('../../utils/gesture/gesture')).create({
|
||||
el: this.el,
|
||||
queue: this.queue,
|
||||
gestureName: 'toggle',
|
||||
gesturePriority: 30,
|
||||
threshold: 0,
|
||||
onStart: this.onDragStart.bind(this),
|
||||
onMove: this.onDragMove.bind(this),
|
||||
onEnd: this.onDragEnd.bind(this),
|
||||
});
|
||||
this.disabledChanged();
|
||||
}
|
||||
|
||||
private onDragStart(detail: GestureDetail) {
|
||||
@ -172,22 +189,9 @@ export class Toggle implements CheckboxInput {
|
||||
renderHiddenInput(this.el, this.name, this.value, this.disabled);
|
||||
|
||||
return [
|
||||
<ion-gesture
|
||||
onStart={this.onDragStart.bind(this)}
|
||||
onMove={this.onDragMove.bind(this)}
|
||||
onEnd={this.onDragEnd.bind(this)}
|
||||
gestureName="toggle"
|
||||
passive={false}
|
||||
gesturePriority={30}
|
||||
direction="x"
|
||||
threshold={0}
|
||||
attachTo="parent"
|
||||
disabled={this.disabled}
|
||||
tabIndex={-1}>
|
||||
<div class="toggle-icon">
|
||||
<div class="toggle-inner"/>
|
||||
</div>
|
||||
</ion-gesture>,
|
||||
<div class="toggle-icon">
|
||||
<div class="toggle-inner"/>
|
||||
</div>,
|
||||
<input
|
||||
type="checkbox"
|
||||
onChange={this.onChange.bind(this)}
|
||||
|
Reference in New Issue
Block a user