Skip to content

Commit 6602ab0

Browse files
committed
fix(speedial): crash fix
1 parent 2edfd80 commit 6602ab0

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

src/speeddial/index.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,31 @@ export class SpeedDialItem extends SpeedDialItemBase {
8383
public actualActive = false;
8484
mTitleView: WeakRef<SpeedDialItemTitle>;
8585
mButton: WeakRef<SpeedDialItemButton>;
86-
fabmenu: WeakRef<SpeedDial>;
86+
mFabmenu: WeakRef<SpeedDial>;
8787

8888
get titleView() {
8989
return this.mTitleView?.get();
9090
}
9191
get button() {
9292
return this.mButton?.get();
9393
}
94+
get fabmenu() {
95+
return this.mFabmenu?.get();
96+
}
9497
constructor(size = 'mini', private isMain = false) {
9598
super();
96-
// this._fabsHolder.isPassThroughParentEnabled = true;
9799
this.isPassThroughParentEnabled = true;
98100
const titleView = new SpeedDialItemTitle();
99101
titleView.notify = this.notifyChildEvent(titleView, titleView.notify);
100102
titleView.col = 1;
101-
titleView.text = this.title;
103+
// titleView.text = this.title;
104+
this.mTitleView = new WeakRef(titleView);
102105
const button = isMain ? new SpeedDialButton() : new SpeedDialItemButton();
103106
button.notify = this.notifyChildEvent(button, button.notify);
104107
button.horizontalAlignment = 'center';
105108
// this.fabButtonTitle.style['css:elevation'] = 4;this.fabButtonTitle.style['css:elevation'] = 2;
106109
button.col = this.fabButtonCol;
110+
this.mButton = new WeakRef(button);
107111
if (size === 'mini') {
108112
// button.style['css:border-radius'] = 20;
109113
button.style['css:width'] = 40;
@@ -118,8 +122,6 @@ export class SpeedDialItem extends SpeedDialItemBase {
118122
(this as any).columns = this.fabColumns;
119123
this.addChild(titleView);
120124
this.addChild(button);
121-
this.mTitleView = new WeakRef(titleView);
122-
this.mButton = new WeakRef(button);
123125
}
124126
updateAlignment() {
125127
(this as any).columns = this.fabColumns;
@@ -141,9 +143,9 @@ export class SpeedDialItem extends SpeedDialItemBase {
141143
(data as any).speeddialItem = this;
142144
if (data.eventName === 'tap') {
143145
if (this.isMain) {
144-
this.fabmenu.get().onButtonTap(data);
146+
this.fabmenu.onButtonTap(data);
145147
} else {
146-
this.fabmenu.get().active = false;
148+
this.fabmenu.active = false;
147149
}
148150
}
149151
superNotifyMethod.call(child, data);
@@ -154,27 +156,27 @@ export class SpeedDialItem extends SpeedDialItemBase {
154156
}
155157
onButtonTap(args) {
156158
if (this.isMain) {
157-
this.fabmenu.get().onButtonTap(args);
159+
this.fabmenu.onButtonTap(args);
158160
} else {
159161
this.notify({ object: this, ...args });
160-
this.fabmenu.get().active = false;
162+
this.fabmenu.active = false;
161163
}
162164
}
163165
get isLeft() {
164-
return this.fabmenu && this.fabmenu.get().isLeft;
166+
return this.mFabmenu && this.fabmenu.isLeft;
165167
}
166168
get isRight() {
167-
return this.fabmenu && this.fabmenu.get().isRight;
169+
return this.mFabmenu && this.fabmenu.isRight;
168170
}
169171
get fabColumns() {
170172
return this.isRight ? '*,auto,60' : '60,auto,*';
171173
}
172174
get active() {
173-
return this.fabmenu && this.fabmenu.get().active;
175+
return this.mFabmenu && this.fabmenu.active;
174176
}
175177
set active(value) {
176-
if (this.fabmenu) {
177-
this.fabmenu.get().active = value;
178+
if (this.mFabmenu) {
179+
this.fabmenu.active = value;
178180
}
179181
}
180182

@@ -258,14 +260,14 @@ export class SpeedDialItem extends SpeedDialItemBase {
258260

259261
@CSSType('MDSpeedDial')
260262
export class SpeedDial extends SpeedDialItemBase {
261-
mFabs: WeakRef<SpeedDialItem>[] = [];
263+
private mFabs: WeakRef<SpeedDialItem>[] = [];
262264
private mFabsHolder: WeakRef<FlexboxLayout>;
265+
private mFabMainButton: WeakRef<SpeedDialItem>;
263266
rows: string;
264267
columns: string;
265268
orientation = 'vertical';
266269
isActive = false;
267270
actualActive = false;
268-
private mFabMainButton: WeakRef<SpeedDialItem>;
269271

270272
get fabsHolder() {
271273
return this.mFabsHolder?.get();
@@ -284,25 +286,25 @@ export class SpeedDial extends SpeedDialItemBase {
284286
this.rows = 'auto,*,auto,auto';
285287
this.style['css:padding-left'] = 8;
286288
this.style['css:padding-right'] = 8;
287-
const fabHolder = new FlexboxLayout();
288-
fabHolder.row = 2;
289-
fabHolder.horizontalAlignment = this.horizontalAlignment;
289+
const fabsHolder = new FlexboxLayout();
290+
fabsHolder.row = 2;
291+
fabsHolder.horizontalAlignment = this.horizontalAlignment;
290292
this.isPassThroughParentEnabled = true;
291293
if (global.isIOS) {
292-
fabHolder.isPassThroughParentEnabled = true;
294+
fabsHolder.isPassThroughParentEnabled = true;
293295
}
294-
fabHolder.flexDirection = this.orientation === 'vertical' ? 'column-reverse' : 'row-reverse';
295-
fabHolder.visibility = 'hidden';
296+
fabsHolder.flexDirection = this.orientation === 'vertical' ? 'column-reverse' : 'row-reverse';
297+
fabsHolder.visibility = 'hidden';
296298
this.backgroundColor = new Color('#00000000');
297299

298300
const fabMainButton = new SpeedDialItem(null, true);
299301
this.prepareItem(fabMainButton, true);
300302
fabMainButton.row = 3;
301303

302-
this.addChild(fabMainButton);
303-
this.addChild(fabHolder);
304-
this.mFabsHolder = new WeakRef(fabHolder);
304+
this.mFabsHolder = new WeakRef(fabsHolder);
305305
this.mFabMainButton = new WeakRef(fabMainButton);
306+
this.addChild(fabMainButton);
307+
this.addChild(fabsHolder);
306308
}
307309

308310
get backDrop() {
@@ -319,7 +321,7 @@ export class SpeedDial extends SpeedDialItemBase {
319321
}
320322

321323
prepareItem(item: SpeedDialItem, isMain = false) {
322-
item.fabmenu = new WeakRef(this);
324+
item.mFabmenu = new WeakRef(this);
323325
const animationData = this.computeAnimationData('hide', item, this.fabs.length, Math.max(this.fabs.length, 1), OPEN_DURATION, isMain);
324326
transformAnimationValues(animationData).forEach((d) => {
325327
const { target, ...others } = d;
@@ -560,7 +562,7 @@ export class SpeedDial extends SpeedDialItemBase {
560562
}
561563
//@ts-ignore
562564
get horizontalAlignment() {
563-
return this.fabsHolder.horizontalAlignment;
565+
return this.fabsHolder?.horizontalAlignment;
564566
}
565567
set horizontalAlignment(value) {
566568
this.fabsHolder.horizontalAlignment = value;

0 commit comments

Comments
 (0)