Skip to content

Commit 08008f0

Browse files
committed
fix(all): component reusage
1 parent 9f32d0e commit 08008f0

File tree

28 files changed

+284
-249
lines changed

28 files changed

+284
-249
lines changed

core/src/components/backdrop/backdrop.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ export class Backdrop implements ComponentInterface {
3939
*/
4040
@Event() ionBackdropTap!: EventEmitter<void>;
4141

42-
componentDidLoad() {
42+
connectedCallback() {
4343
if (this.stopPropagation) {
4444
this.blocker.block();
4545
}
4646
}
4747

48-
componentDidUnload() {
49-
this.blocker.destroy();
48+
disconnectedCallback() {
49+
this.blocker.unblock();
5050
}
5151

5252
@Listen('touchstart', { passive: false, capture: true })

core/src/components/content/content.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class Content implements ComponentInterface {
2424
private cTop = -1;
2525
private cBottom = -1;
2626
private scrollEl!: HTMLElement;
27+
private mode = getIonMode(this);
2728

2829
// Detail is used in a hot loop in the scroll event, by allocating it here
2930
// V8 will be able to inline any read/write to it since it's a monomorphic class.
@@ -102,18 +103,11 @@ export class Content implements ComponentInterface {
102103
*/
103104
@Event() ionScrollEnd!: EventEmitter<ScrollBaseDetail>;
104105

105-
componentWillLoad() {
106-
if (this.forceOverscroll === undefined) {
107-
const mode = getIonMode(this);
108-
this.forceOverscroll = mode === 'ios' && isPlatform(window, 'mobile');
109-
}
110-
}
111-
112106
componentDidLoad() {
113107
this.resize();
114108
}
115109

116-
componentDidUnload() {
110+
disconnectedCallback() {
117111
this.onScrollEnd();
118112
}
119113

@@ -125,6 +119,13 @@ export class Content implements ComponentInterface {
125119
}
126120
}
127121

122+
private shouldForceOverscroll() {
123+
const { forceOverscroll, mode } = this;
124+
return forceOverscroll === undefined
125+
? mode === 'ios' && isPlatform(window, 'mobile')
126+
: forceOverscroll;
127+
}
128+
128129
private resize() {
129130
if (this.fullscreen) {
130131
readTask(this.readDimensions.bind(this));
@@ -299,9 +300,9 @@ export class Content implements ComponentInterface {
299300
}
300301

301302
render() {
303+
const { scrollX, scrollY } = this;
302304
const mode = getIonMode(this);
303-
const { scrollX, scrollY, forceOverscroll } = this;
304-
305+
const forceOverscroll = this.shouldForceOverscroll();
305306
const transitionShadow = (mode === 'ios' && config.getBoolean('experimentalTransitionShadow', false));
306307

307308
this.resize();
@@ -312,7 +313,7 @@ export class Content implements ComponentInterface {
312313
...createColorClasses(this.color),
313314
[mode]: true,
314315
'content-sizing': hostContext('ion-popover', this.el),
315-
'overscroll': !!this.forceOverscroll,
316+
'overscroll': forceOverscroll,
316317
}}
317318
style={{
318319
'--offset-top': `${this.cTop}px`,
@@ -324,7 +325,7 @@ export class Content implements ComponentInterface {
324325
'inner-scroll': true,
325326
'scroll-x': scrollX,
326327
'scroll-y': scrollY,
327-
'overscroll': (scrollX || scrollY) && !!forceOverscroll
328+
'overscroll': (scrollX || scrollY) && forceOverscroll
328329
}}
329330
ref={el => this.scrollEl = el!}
330331
onScroll={ev => this.onScroll(ev)}

core/src/components/infinite-scroll/infinite-scroll.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class InfiniteScroll implements ComponentInterface {
7676
*/
7777
@Event() ionInfinite!: EventEmitter<void>;
7878

79-
async componentDidLoad() {
79+
async connectedCallback() {
8080
const contentEl = this.el.closest('ion-content');
8181
if (contentEl) {
8282
this.scrollEl = await contentEl.getScrollElement();
@@ -92,7 +92,7 @@ export class InfiniteScroll implements ComponentInterface {
9292
}
9393
}
9494

95-
componentDidUnload() {
95+
disconnectedCallback() {
9696
this.enableScrollEvents(false);
9797
this.scrollEl = undefined;
9898
}

core/src/components/input/input.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class Input implements ComponentInterface {
6666
/**
6767
* If `true`, the value will be cleared after focus upon edit. Defaults to `true` when `type` is `"password"`, `false` for all other types.
6868
*/
69-
@Prop({ mutable: true }) clearOnEdit?: boolean;
69+
@Prop() clearOnEdit?: boolean;
7070

7171
/**
7272
* Set the amount of time, in milliseconds, to wait to trigger the `ionChange` event after each keystroke.
@@ -217,22 +217,18 @@ export class Input implements ComponentInterface {
217217
*/
218218
@Event() ionStyle!: EventEmitter<StyleEventDetail>;
219219

220-
componentWillLoad() {
221-
// By default, password inputs clear after focus when they have content
222-
if (this.clearOnEdit === undefined && this.type === 'password') {
223-
this.clearOnEdit = true;
224-
}
220+
connectedCallback() {
225221
this.emitStyle();
226-
}
227-
228-
componentDidLoad() {
229222
this.debounceChanged();
230-
231-
this.ionInputDidLoad.emit();
223+
document.dispatchEvent(new CustomEvent('ionInputDidLoad', {
224+
detail: this.el
225+
}));
232226
}
233227

234-
componentDidUnload() {
235-
this.ionInputDidUnload.emit();
228+
disconnectedCallback() {
229+
document.dispatchEvent(new CustomEvent('ionInputDidUnload', {
230+
detail: this.el
231+
}));
236232
}
237233

238234
/**
@@ -254,6 +250,13 @@ export class Input implements ComponentInterface {
254250
return Promise.resolve(this.nativeInput!);
255251
}
256252

253+
private shouldClearOnEdit() {
254+
const { type, clearOnEdit } = this;
255+
return (clearOnEdit === undefined)
256+
? type === 'password'
257+
: clearOnEdit;
258+
}
259+
257260
private getValue(): string {
258261
return this.value || '';
259262
}
@@ -294,7 +297,7 @@ export class Input implements ComponentInterface {
294297
}
295298

296299
private onKeydown = () => {
297-
if (this.clearOnEdit) {
300+
if (this.shouldClearOnEdit()) {
298301
// Did the input value change after it was blurred and edited?
299302
if (this.didBlurAfterEdit && this.hasValue()) {
300303
// Clear the input
@@ -326,7 +329,7 @@ export class Input implements ComponentInterface {
326329

327330
private focusChanged() {
328331
// If clearOnEdit is enabled and the input blurred but has a value, set a flag
329-
if (this.clearOnEdit && !this.hasFocus && this.hasValue()) {
332+
if (this.shouldClearOnEdit() && !this.hasFocus && this.hasValue()) {
330333
this.didBlurAfterEdit = true;
331334
}
332335
}

core/src/components/item-sliding/item-sliding.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class ItemSliding implements ComponentInterface {
6464
*/
6565
@Event() ionDrag!: EventEmitter;
6666

67-
async componentDidLoad() {
67+
async connectedCallback() {
6868
this.item = this.el.querySelector('ion-item');
6969
await this.updateOptions();
7070

@@ -81,7 +81,7 @@ export class ItemSliding implements ComponentInterface {
8181
this.disabledChanged();
8282
}
8383

84-
componentDidUnload() {
84+
disconnectedCallback() {
8585
if (this.gesture) {
8686
this.gesture.destroy();
8787
this.gesture = undefined;

core/src/components/menu/menu.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class Menu implements ComponentInterface, MenuI {
137137
*/
138138
@Event() protected ionMenuChange!: EventEmitter<MenuChangeEventDetail>;
139139

140-
async componentWillLoad() {
140+
async connectedCallback() {
141141
if (this.type === undefined) {
142142
this.type = config.get('menuType', this.mode === 'ios' ? 'reveal' : 'overlay');
143143
}
@@ -170,6 +170,8 @@ export class Menu implements ComponentInterface, MenuI {
170170
// register this menu with the app's menu controller
171171
menuCtrl!._register(this);
172172

173+
this.updateState();
174+
173175
this.gesture = (await import('../../utils/gesture')).createGesture({
174176
el: document,
175177
gestureName: 'menu-swipe',
@@ -181,14 +183,13 @@ export class Menu implements ComponentInterface, MenuI {
181183
onMove: ev => this.onMove(ev),
182184
onEnd: ev => this.onEnd(ev),
183185
});
184-
this.updateState();
185186
}
186187

187-
componentDidLoad() {
188+
async componentDidLoad() {
188189
this.ionMenuChange.emit({ disabled: this.disabled, open: this._isOpen });
189190
}
190191

191-
componentDidUnload() {
192+
disconnectedCallback() {
192193
this.blocker.destroy();
193194
this.menuCtrl!._unregister(this);
194195
if (this.animation) {

core/src/components/picker-column/picker-column.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class PickerColumnCmp implements ComponentInterface {
4747
this.refresh();
4848
}
4949

50-
componentWillLoad() {
50+
async connectedCallback() {
5151
let pickerRotateFactor = 0;
5252
let pickerScaleFactor = 0.81;
5353

@@ -60,9 +60,7 @@ export class PickerColumnCmp implements ComponentInterface {
6060

6161
this.rotateFactor = pickerRotateFactor;
6262
this.scaleFactor = pickerScaleFactor;
63-
}
6463

65-
async componentDidLoad() {
6664
// get the height of one option
6765
const colEl = this.optsEl;
6866
if (colEl) {
@@ -88,7 +86,7 @@ export class PickerColumnCmp implements ComponentInterface {
8886
}, 250);
8987
}
9088

91-
componentDidUnload() {
89+
disconnectedCallback() {
9290
cancelAnimationFrame(this.rafId);
9391
clearTimeout(this.tmrId);
9492
if (this.gesture) {

0 commit comments

Comments
 (0)