Skip to content

Commit

Permalink
perf(reorder): reorder icon is display: none by default
Browse files Browse the repository at this point in the history
references #7651
  • Loading branch information
manucorporat committed Aug 20, 2016
1 parent bac9b81 commit 26441ec
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
12 changes: 7 additions & 5 deletions src/components/item/item-reorder.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// --------------------------------------------------

ion-reorder {
display: flex;
display: none;

flex: 1;
align-items: center;
Expand All @@ -28,10 +28,12 @@ ion-reorder {
}
}

.reorder-enabled {
ion-reorder {
transform: translate3d(0, 0, 0);
}
.reorder-enabled ion-reorder {
display: flex;
}

.reorder-visible ion-reorder {
transform: translate3d(0, 0, 0);
}

.reorder-list-active {
Expand Down
19 changes: 14 additions & 5 deletions src/components/item/item-reorder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Directive, ElementRef, EventEmitter, forwardRef, Input, NgZone, Renderer, Inject, Optional, Output } from '@angular/core';

import { Content } from '../content/content';
import { CSS } from '../../util/dom';
import { CSS, zoneRafFrames } from '../../util/dom';
import { Item } from './item';
import { ItemReorderGesture } from '../item/item-reorder-gesture';
import { isTrueProperty } from '../../util/util';
Expand Down Expand Up @@ -128,10 +128,13 @@ export interface ReorderIndexes {
selector: 'ion-list[reorder],ion-item-group[reorder]',
host: {
'[class.reorder-enabled]': '_enableReorder',
'[class.reorder-visible]': '_visibleReorder',

}
})
export class ItemReorder {
private _enableReorder: boolean = false;
private _visibleReorder: boolean = false;
private _reorderGesture: ItemReorderGesture;
private _lastToIndex: number = -1;
private _element: HTMLElement;
Expand Down Expand Up @@ -166,15 +169,21 @@ export class ItemReorder {
return this._enableReorder;
}
set reorder(val: boolean) {
this._enableReorder = isTrueProperty(val);
let enabled = isTrueProperty(val);

if (!this._enableReorder) {
this._reorderGesture && this._reorderGesture.destroy();
if (!enabled && this._reorderGesture) {
this._reorderGesture.destroy();
this._reorderGesture = null;

} else if (!this._reorderGesture) {
this._visibleReorder = false;
setTimeout(() => this._enableReorder = false, 400);

} else if (enabled && !this._reorderGesture) {
console.debug('enableReorderItems');
this._reorderGesture = new ItemReorderGesture(this);

this._enableReorder = true;
zoneRafFrames(2, () => this._visibleReorder = true);
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/util/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ export function rafFrames(framesToWait: number, callback: Function) {
}
}

// TODO: DRY rafFrames and zoneRafFrames
export function zoneRafFrames(framesToWait: number, callback: Function) {

This comment has been minimized.

Copy link
@manucorporat

manucorporat Aug 21, 2016

Author Contributor

maybe... renaming rafFrames() to nativeRafFrames()
and zoneRafFrames() to rafFrames()?

framesToWait = Math.ceil(framesToWait);

if (framesToWait < 2) {
raf(callback);

} else {
setTimeout(() => {
raf(callback);
}, (framesToWait - 1) * 16.6667);
}
}

export let CSS: {
transform?: string,
transition?: string,
Expand Down
10 changes: 4 additions & 6 deletions src/util/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core';

import { Config } from '../config/config';
import { Form } from './form';
import { hasFocusedTextInput, nativeRaf, rafFrames, nativeTimeout } from './dom';
import { hasFocusedTextInput, nativeRaf, zoneRafFrames, nativeTimeout } from './dom';
import { Key } from './key';

/**
Expand Down Expand Up @@ -86,11 +86,9 @@ export class Keyboard {
function checkKeyboard() {
console.debug('keyboard isOpen', self.isOpen());
if (!self.isOpen() || checks > pollingChecksMax) {
rafFrames(30, () => {
self._zone.run(() => {
console.debug('keyboard closed');
callback();
});
zoneRafFrames(30, () => {
console.debug('keyboard closed');
callback();
});

} else {
Expand Down

0 comments on commit 26441ec

Please sign in to comment.