Skip to content

Commit d3c73dc

Browse files
committed
fix: some shape fixes
1 parent 2140ffc commit d3c73dc

File tree

5 files changed

+61
-20
lines changed

5 files changed

+61
-20
lines changed

src/button/button.android.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,19 @@ export class Button extends ButtonBase {
9090
const color = !value || value instanceof Color ? value : new Color(value);
9191
this.nativeViewProtected.setRippleColor(color ? getColorStateList(color.android) : null);
9292
}
93+
defaultAppearanceModel;
9394
[shapeProperty.setNative](shape: string) {
9495
const appearanceModel = themer.getShape(shape);
95-
this.nativeViewProtected.setShapeAppearanceModel(appearanceModel);
96+
if (!shape) {
97+
if (this.defaultAppearanceModel) {
98+
this.nativeViewProtected.setShapeAppearanceModel(this.defaultAppearanceModel);
99+
}
100+
} else {
101+
if (!this.defaultAppearanceModel) {
102+
this.defaultAppearanceModel = this.nativeViewProtected.getShapeAppearanceModel();
103+
}
104+
this.nativeViewProtected.setShapeAppearanceModel(appearanceModel);
105+
}
96106
}
97107

98108
getDefaultElevation(): number {

src/cardview/cardview.android.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,19 @@ export class CardView extends CardViewBase {
323323
}
324324
}
325325
}
326-
326+
defaultAppearanceModel;
327327
[shapeProperty.setNative](shape: string) {
328328
const appearanceModel = themer.getShape(shape);
329-
this.nativeViewProtected.setShapeAppearanceModel(appearanceModel);
329+
if (!shape) {
330+
if (this.defaultAppearanceModel) {
331+
this.nativeViewProtected.setShapeAppearanceModel(this.defaultAppearanceModel);
332+
}
333+
} else {
334+
if (!this.defaultAppearanceModel) {
335+
this.defaultAppearanceModel = this.nativeViewProtected.getShapeAppearanceModel();
336+
}
337+
this.nativeViewProtected.setShapeAppearanceModel(appearanceModel);
338+
}
330339
}
331340

332341
[elevationProperty.setNative](value: number) {

src/core/index.android.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import { Application, Background, Button, Color, Length, View, androidDynamicElevationOffsetProperty, androidElevationProperty, backgroundInternalProperty, profile, PercentLength } from '@nativescript/core';
1+
import {
2+
Application,
3+
Background,
4+
Button,
5+
Color,
6+
Length,
7+
PercentLength,
8+
View,
9+
androidDynamicElevationOffsetProperty,
10+
androidElevationProperty,
11+
backgroundInternalProperty,
12+
profile
13+
} from '@nativescript/core';
214
import { createRippleDrawable, createStateListAnimator, getAttrColor, getColorStateList, handleClearFocus, isPostLollipop, isPostLollipopMR1, isPostMarshmallow } from './android/utils';
315
import { CornerFamily, applyMixins } from './index.common';
416
import { cssProperty, dynamicElevationOffsetProperty, elevationProperty, rippleColorProperty } from './cssproperties';
@@ -133,7 +145,7 @@ export class Themer {
133145
builder.setAllCornerSizes(PercentLength.toDevicePixels(options.cornerSize));
134146
}
135147
} else {
136-
builder.setAllCornerSizes(options.cornerSize);
148+
builder.setAllCornerSizes(PercentLength.toDevicePixels(options.cornerSize));
137149
}
138150
}
139151
if (options.cornerSizeBottomLeft !== undefined) {
@@ -144,7 +156,7 @@ export class Themer {
144156
builder.setBottomLeftCornerSize(PercentLength.toDevicePixels(options.cornerSizeBottomLeft));
145157
}
146158
} else {
147-
builder.setBottomLeftCornerSize(options.cornerSizeBottomLeft);
159+
builder.setBottomLeftCornerSize(PercentLength.toDevicePixels(options.cornerSizeBottomLeft));
148160
}
149161
}
150162
if (options.cornerSizeBottomRight !== undefined) {
@@ -155,7 +167,7 @@ export class Themer {
155167
builder.setBottomRightCornerSize(PercentLength.toDevicePixels(options.cornerSizeBottomRight));
156168
}
157169
} else {
158-
builder.setBottomRightCornerSize(options.cornerSizeBottomRight);
170+
builder.setBottomRightCornerSize(PercentLength.toDevicePixels(options.cornerSizeBottomRight));
159171
}
160172
}
161173
if (options.cornerSizeTopRight !== undefined) {
@@ -166,7 +178,7 @@ export class Themer {
166178
builder.setTopRightCornerSize(PercentLength.toDevicePixels(options.cornerSizeTopRight));
167179
}
168180
} else {
169-
builder.setTopRightCornerSize(options.cornerSizeTopRight);
181+
builder.setTopRightCornerSize(PercentLength.toDevicePixels(options.cornerSizeTopRight));
170182
}
171183
}
172184
if (options.cornerSizeTopLeft !== undefined) {
@@ -177,7 +189,7 @@ export class Themer {
177189
builder.setTopLeftCornerSize(PercentLength.toDevicePixels(options.cornerSizeTopLeft));
178190
}
179191
} else {
180-
builder.setTopLeftCornerSize(options.cornerSizeTopLeft);
192+
builder.setTopLeftCornerSize(PercentLength.toDevicePixels(options.cornerSizeTopLeft));
181193
}
182194
}
183195
this._shapes[key] = builder.build();

src/core/index.ios.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ function cornerTreatment(cornerFamily: CornerFamily, cornerSize: number | CoreTy
4545
}
4646
} else {
4747
if (cornerFamily === CornerFamily.ROUNDED) {
48-
corner = MDCCornerTreatment.cornerWithCut(cornerSize);
48+
corner = MDCCornerTreatment.cornerWithRadius(PercentLength.toDevicePixels(cornerSize));
4949
} else {
50-
corner = MDCCornerTreatment.cornerWithRadius(cornerSize);
50+
corner = MDCCornerTreatment.cornerWithCut(PercentLength.toDevicePixels(cornerSize));
5151
}
5252
}
5353
return corner;
@@ -177,18 +177,18 @@ export class Themer {
177177
shapeCategory.topLeftCorner = corner;
178178
shapeCategory.topRightCorner = corner;
179179
}
180-
if (options.cornerFamilyBottomLeft && options.cornerSizeBottomLeft !== undefined) {
181-
shapeCategory.bottomLeftCorner = cornerTreatment(options.cornerFamilyBottomLeft, options.cornerSizeBottomLeft);
180+
if (options.cornerSizeBottomLeft !== undefined) {
181+
shapeCategory.bottomLeftCorner = cornerTreatment(options.cornerFamilyBottomLeft || options.cornerFamily, options.cornerSizeBottomLeft);
182182
}
183-
if (options.cornerFamilyBottomRight && options.cornerSizeBottomRight !== undefined) {
184-
shapeCategory.bottomRightCorner = cornerTreatment(options.cornerFamilyBottomRight, options.cornerSizeBottomRight);
183+
if (options.cornerSizeBottomRight !== undefined) {
184+
shapeCategory.bottomRightCorner = cornerTreatment(options.cornerFamilyBottomRight || options.cornerFamily, options.cornerSizeBottomRight);
185185
}
186186

187-
if (options.cornerFamilyTopLeft && options.cornerSizeTopLeft !== undefined) {
188-
shapeCategory.topLeftCorner = cornerTreatment(options.cornerFamilyTopLeft, options.cornerSizeTopLeft);
187+
if (options.cornerSizeTopLeft !== undefined) {
188+
shapeCategory.topLeftCorner = cornerTreatment(options.cornerFamilyTopLeft || options.cornerFamily, options.cornerSizeTopLeft);
189189
}
190-
if (options.cornerFamilyTopRight && options.cornerSizeTopRight !== undefined) {
191-
shapeCategory.topRightCorner = cornerTreatment(options.cornerFamilyTopRight, options.cornerSizeTopRight);
190+
if (options.cornerSizeTopRight !== undefined) {
191+
shapeCategory.topRightCorner = cornerTreatment(options.cornerFamilyTopRight || options.cornerFamily, options.cornerSizeTopRight);
192192
}
193193
shapeScheme.smallComponentShape = shapeCategory;
194194
shapeScheme.mediumComponentShape = shapeCategory;

src/floatingactionbutton/floatingactionbutton.android.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,18 @@ export class FloatingActionButton extends FloatingActionButtonBase {
107107
this.nativeViewProtected.shrink();
108108
}
109109
}
110+
defaultAppearanceModel;
110111
[shapeProperty.setNative](shape: string) {
111112
const appearanceModel = themer.getShape(shape);
112-
this.nativeViewProtected.setShapeAppearanceModel(appearanceModel);
113+
if (!shape) {
114+
if (this.defaultAppearanceModel) {
115+
this.nativeViewProtected.setShapeAppearanceModel(this.defaultAppearanceModel);
116+
}
117+
} else {
118+
if (!this.defaultAppearanceModel) {
119+
this.defaultAppearanceModel = this.nativeViewProtected.getShapeAppearanceModel();
120+
}
121+
this.nativeViewProtected.setShapeAppearanceModel(appearanceModel);
122+
}
113123
}
114124
}

0 commit comments

Comments
 (0)