Skip to content

Commit 9b78aeb

Browse files
danbucholtzadamdbradley
authored andcommitted
fix(click-block): fix for the click block logic
fix for the click block logic
1 parent 1570d2b commit 9b78aeb

File tree

3 files changed

+82
-7
lines changed

3 files changed

+82
-7
lines changed

src/components/app/app.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,23 @@ export class App {
5353
* while views transition, a modal slides up, an action-sheet
5454
* slides up, etc. After the transition completes it is set back to `true`.
5555
* @param {boolean} isEnabled
56-
* @param {boolean} fallback When `isEnabled` is set to `false`, this argument
56+
* @param {number} duration When `isEnabled` is set to `false`, this argument
5757
* is used to set the maximum number of milliseconds that app will wait until
5858
* it will automatically enable the app again. It's basically a fallback incase
5959
* something goes wrong during a transition and the app wasn't re-enabled correctly.
6060
*/
6161
setEnabled(isEnabled: boolean, duration: number = 700) {
6262
this._disTime = (isEnabled ? 0 : Date.now() + duration);
63-
63+
const CLICK_BLOCK_BUFFER_IN_MILLIS = 64;
6464
if (this._clickBlock) {
65-
if (duration > 32) {
66-
// only do a click block if the duration is longer than XXms
67-
this._clickBlock.show(true, duration + 64);
68-
69-
} else {
65+
if ( isEnabled || duration <= 32 ) {
66+
// disable the click block if it's enabled, or the duration is tiny
7067
this._clickBlock.show(false, 0);
7168
}
69+
else {
70+
// show the click block for duration + some number
71+
this._clickBlock.show(true, duration + CLICK_BLOCK_BUFFER_IN_MILLIS);
72+
}
7273
}
7374
}
7475

src/components/app/test/app.spec.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,77 @@ describe('IonicApp', () => {
8383
expect(app.getActiveNav()).toBeNull();
8484
expect(app.getRootNav()).toBeNull();
8585
});
86+
});
87+
88+
describe('setEnabled', () => {
89+
it('should disable click block when app is enabled', () => {
90+
// arrange
91+
let mockClickBlock = {
92+
show: () => {}
93+
};
94+
95+
spyOn(mockClickBlock, 'show');
96+
97+
app._clickBlock = mockClickBlock;
98+
99+
// act
100+
app.setEnabled(true);
101+
102+
// assert
103+
expect(mockClickBlock.show).toHaveBeenCalledWith(false, 0);
104+
});
105+
106+
it('should disable click block when app is disabled but duration of less than 32 passed', () => {
107+
// arrange
108+
let mockClickBlock = {
109+
show: () => {}
110+
};
111+
112+
spyOn(mockClickBlock, 'show');
113+
114+
app._clickBlock = mockClickBlock;
115+
116+
// act
117+
app.setEnabled(false, 20);
118+
119+
// assert
120+
expect(mockClickBlock.show).toHaveBeenCalledWith(false, 0);
121+
});
122+
123+
it('should enable click block when false is passed with duration', () => {
124+
// arrange
125+
let mockClickBlock = {
126+
show: () => {}
127+
};
128+
129+
spyOn(mockClickBlock, 'show');
130+
131+
app._clickBlock = mockClickBlock;
132+
133+
// act
134+
app.setEnabled(false, 200);
135+
136+
// assert
137+
expect(mockClickBlock.show).toHaveBeenCalledWith(true, 200 + 64);
138+
});
139+
140+
it('should enable click block when false is passed w/o duration', () => {
141+
// arrange
142+
let mockClickBlock = {
143+
show: () => {}
144+
};
145+
146+
spyOn(mockClickBlock, 'show');
86147

148+
app._clickBlock = mockClickBlock;
149+
150+
// act
151+
app.setEnabled(false);
152+
153+
// assert
154+
// 700 is the default
155+
expect(mockClickBlock.show).toHaveBeenCalledWith(true, 700 + 64);
156+
});
87157
});
88158

89159
var app: App;

src/config/bootstrap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ function setupDom(window: Window, document: Document, config: Config, platform:
160160
bodyEle.classList.add('enable-hover');
161161
}
162162

163+
if (config.get('clickBlock')) {
164+
clickBlock.enable();
165+
}
166+
163167
// run feature detection tests
164168
featureDetect.run(window, document);
165169
}

0 commit comments

Comments
 (0)