Skip to content

Commit d0d85a0

Browse files
committed
fix(speeddial): multiple fixes
1 parent 41c9ea7 commit d0d85a0

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

src/button/button.android.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createStateListAnimator, getColorStateList, getHorizontalGravity, getLa
44
import {
55
Background,
66
Color,
7+
CoreTypes,
78
Font,
89
ImageSource,
910
Length,
@@ -12,8 +13,7 @@ import {
1213
androidElevationProperty,
1314
backgroundInternalProperty,
1415
colorProperty,
15-
profile,
16-
CoreTypes
16+
profile
1717
} from '@nativescript/core';
1818
import { textAlignmentProperty, textTransformProperty } from '@nativescript/core/ui/text-base';
1919
import { ButtonBase, imageSourceProperty, srcProperty } from './button-common';
@@ -165,6 +165,9 @@ export class Button extends ButtonBase {
165165
if (value.borderTopColor) {
166166
view.setStrokeColor(getColorStateList(value.borderTopColor.android));
167167
}
168+
if (value.image) {
169+
this._createImageSourceFromSrc(value.image as any, false);
170+
}
168171
}
169172
}
170173
}
@@ -176,17 +179,34 @@ export class Button extends ButtonBase {
176179
this.nativeTextViewProtected.setGravity(getHorizontalGravity(this.textAlignment) | getVerticalGravity(value));
177180
}
178181

182+
settingImageSourceAsIcon = false;
179183
[imageSourceProperty.setNative](value: ImageSource) {
180184
const nativeView = this.nativeViewProtected;
181185
if (value && value.android) {
182-
const fontSize = this.fontSize || nativeView.getTextSize();
183-
nativeView.setIconSize(Math.min(value.width, Utils.layout.toDevicePixels(fontSize)));
186+
if (this.settingImageSourceAsIcon) {
187+
const fontSize = this.fontSize || nativeView.getTextSize();
188+
nativeView.setIconSize(Math.min(value.width, Utils.layout.toDevicePixels(fontSize)));
189+
// nativeView.setIconGravity(android.view.Gravity.RIGHT);
190+
nativeView.setIconPadding(0);
191+
} else {
192+
// nativeView.setIconGravity(android.view.Gravity.CENTER);
193+
nativeView.setIconPadding(0);
194+
// nativeView.setPadding(0, 0, 0, 0);
195+
nativeView.setIconTint(null);
196+
// nativeView.setText(null);
197+
nativeView.setIconSize(Math.max(Utils.layout.toDevicePixels(this.getMeasuredWidth()), Utils.layout.toDevicePixels(this.getMeasuredHeight())));
198+
}
184199
nativeView.setIcon(new android.graphics.drawable.BitmapDrawable(value.android));
185200
} else {
186201
nativeView.setIcon(null);
187202
}
188203
}
189204

205+
setImageSource(value, asIcon = true) {
206+
this.settingImageSourceAsIcon = asIcon;
207+
this.imageSource = value;
208+
}
209+
190210
[srcProperty.setNative](value: any) {
191211
this._createImageSourceFromSrc(value);
192212
}

src/speeddial/index.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ export class SpeedDialItemButton extends Button {
7878
constructor() {
7979
super();
8080
this.verticalAlignment = 'middle';
81-
this.style['css:font-size'] = 26;
81+
this.style['css:font-size'] = 24;
8282
this.style['css:elevation'] = 6;
83+
this.style['css:padding'] = 2;
8384
// this.style['css:dynamic-elevation-offset'] = 6;
8485
}
8586
getDefaultElevation(): number {
@@ -127,6 +128,10 @@ export class SpeedDialItem extends SpeedDialItemBase {
127128
this.addChild(this.titleView);
128129
this.addChild(this.button);
129130
}
131+
updateAlignment() {
132+
(this as any).columns = this.fabColumns;
133+
this.button.col = this.fabButtonCol;
134+
}
130135
initNativeView() {
131136
super.initNativeView();
132137
this.titleView.on('tap', this.onButtonTap, this);
@@ -226,12 +231,10 @@ export class SpeedDialItem extends SpeedDialItemBase {
226231

227232
//@ts-ignore
228233
get backgroundImage() {
229-
return this.button && this.button.backgroundImage;
234+
return this.button.backgroundImage;
230235
}
231236
set backgroundImage(value: string | LinearGradient) {
232-
if (this.button) {
233-
this.button.backgroundImage = value;
234-
}
237+
this.button.backgroundImage = value;
235238
}
236239
//@ts-ignore
237240
get color() {
@@ -266,7 +269,6 @@ export class SpeedDial extends SpeedDialItemBase {
266269
private _fabsHolder: FlexboxLayout;
267270
rows: string;
268271
columns: string;
269-
rPosition = 'left';
270272
orientation = 'vertical';
271273
isActive = false;
272274
actualActive = false;
@@ -281,7 +283,7 @@ export class SpeedDial extends SpeedDialItemBase {
281283
this.style['css:padding-right'] = 8;
282284
this._fabsHolder = new FlexboxLayout();
283285
this._fabsHolder.row = 2;
284-
this._fabsHolder.horizontalAlignment = this.rPosition as HorizontalAlignment;
286+
this._fabsHolder.horizontalAlignment = this.horizontalAlignment;
285287
this.isPassThroughParentEnabled = true;
286288
if (global.isIOS) {
287289
this._fabsHolder.isPassThroughParentEnabled = true;
@@ -358,10 +360,10 @@ export class SpeedDial extends SpeedDialItemBase {
358360
// }
359361
// }
360362
get isLeft() {
361-
return this.rPosition === 'left';
363+
return this.horizontalAlignment === 'left';
362364
}
363365
get isRight() {
364-
return this.rPosition === 'right';
366+
return this.horizontalAlignment === 'right';
365367
}
366368
onButtonTap(args) {
367369
this.active = !this.active;
@@ -517,6 +519,7 @@ export class SpeedDial extends SpeedDialItemBase {
517519
}
518520
set icon(value: string | ImageSource) {
519521
this._fabMainButton.icon = value;
522+
this._fabMainButton.padding = 0;
520523
}
521524
get buttonClass() {
522525
return this._fabMainButton.buttonClass;
@@ -556,6 +559,13 @@ export class SpeedDial extends SpeedDialItemBase {
556559
}
557560
set horizontalAlignment(value) {
558561
this._fabsHolder.horizontalAlignment = value;
562+
this._fabMainButton.updateAlignment();
563+
this._fabsHolder.eachChild((c) => {
564+
if (c instanceof SpeedDialItem) {
565+
c.updateAlignment();
566+
}
567+
return true;
568+
});
559569
}
560570
//@ts-ignore
561571
// get backgroundColor() {

0 commit comments

Comments
 (0)