Skip to content

Commit 66cc8a4

Browse files
bundyovakrilovdtopuzovvtrifonov
authored
fix(button-android): use setMinWidth to set TextView widgets min-width (#7804)
* fix: setMinimumWidth does not really set the minWidth for TextView widgets * chore: fix versions * refactor(android): default minWidth/Height values for button * reafctor: reset minWidth when view is in flexbox for backcompat * refactor: ensure back-compatible layout for btns * chore: cut 6.5.0 release (#8443) * release: cut 6.5.0 release * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com> Co-authored-by: vakrilov <alexander.vakrilov@telerik.com> Co-authored-by: Dimitar Topuzov <dtopuzov@gmail.com> Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
1 parent 1f04469 commit 66cc8a4

12 files changed

Lines changed: 152 additions & 80 deletions

File tree

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# [6.5.0](https://github.com/NativeScript/NativeScript/compare/6.4.2...6.5.0) (2020-03-18)
2+
3+
4+
### Bug Fixes
5+
6+
* Fix issue for view not being removed from its parent ([#8432](https://github.com/NativeScript/NativeScript/issues/8432)) ([e081340](https://github.com/NativeScript/NativeScript/commit/e081340665605c54530587cc0cce9bc339585557))
7+
* **d.ts:** Update iOS typings iOS 13.2 ([#8430](https://github.com/NativeScript/NativeScript/issues/8430)) ([18a9b1a](https://github.com/NativeScript/NativeScript/commit/18a9b1aea89ee9defee990ace7d2409327a47a28))
8+
* **bottom-nav:** Android TabStripItems not aligned correctly when one of the image is smaller ([#8414](https://github.com/NativeScript/NativeScript/issues/8414))([9830be7](https://github.com/NativeScript/NativeScript/commit/9830be7230355638ace604145a3e3fad393c2a93))
9+
* **tabs:** delay loadView when animation runs ([#8353](https://github.com/NativeScript/NativeScript/issues/8353)) ([e649a6c](https://github.com/NativeScript/NativeScript/commit/e649a6cfd618c86a1dc7fa84e3197dfb78c3bc74))
10+
11+
12+
### Features
13+
14+
* **tabs:** Tabs styling improvements ([#8366](https://github.com/NativeScript/NativeScript/pull/8366))([4589431](https://github.com/NativeScript/NativeScript/commit/458943111e909fcdad47d12e7ee4bcd9732f4e90))
15+
* **tabs:** Added selectedItemColor and unSelectedItemColor to the TabStrip ([#8435](https://github.com/NativeScript/NativeScript/issues/8435))([243dc98](https://github.com/NativeScript/NativeScript/commit/243dc98005d43617872da5cfc010e76178aa7f97))
16+
* **gestures:** add locationX and locationY to double tap event data ([#8338](https://github.com/NativeScript/NativeScript/pull/8338))([5ff78e2](https://github.com/NativeScript/NativeScript/commit/5ff78e2ad2612259bff36d3aaf5a0292309f5a78))
17+
* **tabs:** Added iconClass property to TabStripItem ([#8439](https://github.com/NativeScript/NativeScript/issues/8439))([270988d](https://github.com/NativeScript/NativeScript/commit/270988d26e1eeab97b4e5781451388e3a0a347e3))
18+
19+
120
## [6.4.2](https://github.com/NativeScript/NativeScript/compare/6.4.1...6.4.2) (2020-02-27)
221

322

api-reports/NativeScript.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,8 @@ export abstract class ViewBase extends Observable {
28962896
public _goToVisualState(state: string): void;
28972897
public id: string;
28982898
// (undocumented)
2899+
public _ignoreFlexMinWidthHeightReset: boolean;
2900+
// (undocumented)
28992901
_inheritStyleScope(styleScope: any /* StyleScope */): void;
29002902
initNativeView(): void;
29012903
// (undocumented)

nativescript-core/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@
4141
"ios": "6.0.0",
4242
"android": "6.0.0"
4343
},
44-
"hooks": [{
45-
"name": "nativescript-core",
46-
"type": "before-checkForChanges",
47-
"script": "cli-hooks/before-checkForChanges.js",
48-
"inject": true
49-
}]
44+
"hooks": [
45+
{
46+
"name": "nativescript-core",
47+
"type": "before-checkForChanges",
48+
"script": "cli-hooks/before-checkForChanges.js",
49+
"inject": true
50+
}
51+
]
5052
},
5153
"snapshot": {
5254
"android": {
@@ -58,4 +60,4 @@
5860
}
5961
}
6062
}
61-
}
63+
}

nativescript-core/ui/button/button.android.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
ButtonBase, PseudoClassHandler,
33
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty,
4-
Length, zIndexProperty, textAlignmentProperty, TextAlignment
4+
Length, zIndexProperty, textAlignmentProperty, TextAlignment, layout,
5+
minWidthProperty, minHeightProperty
56
} from "./button-common";
67
import { profile } from "../../profiling";
78
import { TouchGestureEventData, GestureTypes, TouchAction } from "../gestures";
@@ -111,6 +112,18 @@ export class Button extends ButtonBase {
111112
}
112113
}
113114

115+
[minWidthProperty.getDefault](): Length {
116+
const dips = org.nativescript.widgets.ViewHelper.getMinWidth(this.nativeViewProtected);
117+
118+
return { value: dips, unit: "px" };
119+
}
120+
121+
[minHeightProperty.getDefault](): Length {
122+
const dips = org.nativescript.widgets.ViewHelper.getMinHeight(this.nativeViewProtected);
123+
124+
return { value: dips, unit: "px" };
125+
}
126+
114127
[paddingTopProperty.getDefault](): Length {
115128
return { value: this._defaultPaddingTop, unit: "px" };
116129
}
@@ -177,3 +190,5 @@ export class Button extends ButtonBase {
177190
return 4; // 4dp @dimen/button_pressed_z_material
178191
}
179192
}
193+
194+
Button.prototype._ignoreFlexMinWidthHeightReset = true;

nativescript-core/ui/core/view-base/view-base.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,17 @@ export abstract class ViewBase extends Observable {
432432
* @private
433433
*/
434434
public recycleNativeView: "always" | "never" | "auto";
435+
435436
/**
436437
* @private
437438
*/
438439
public _isPaddingRelative: boolean;
440+
441+
/**
442+
* @private
443+
*/
444+
public _ignoreFlexMinWidthHeightReset: boolean;
445+
439446
public _styleScope: any;
440447

441448
/**

nativescript-core/ui/core/view-base/view-base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
227227
_oldTop: number;
228228
_oldRight: number;
229229
_oldBottom: number;
230+
_ignoreFlexMinWidthHeightReset: boolean;
230231

231232
public effectiveMinWidth: number;
232233
public effectiveMinHeight: number;

nativescript-core/ui/core/view/view.android.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export class View extends ViewCommon {
389389
this.nativeViewProtected.setClickable(this._isClickable);
390390
}
391391
}
392-
392+
393393
this._manager = null;
394394
this._rootManager = null;
395395
super.onUnloaded();
@@ -982,17 +982,17 @@ export class View extends ViewCommon {
982982

983983
[minWidthProperty.setNative](value: Length) {
984984
if (this.parent instanceof CustomLayoutView && this.parent.nativeViewProtected) {
985-
this.parent._setChildMinWidthNative(this);
985+
this.parent._setChildMinWidthNative(this, value);
986986
} else {
987-
this._setMinWidthNative(this.minWidth);
987+
this._setMinWidthNative(value);
988988
}
989989
}
990990

991991
[minHeightProperty.setNative](value: Length) {
992992
if (this.parent instanceof CustomLayoutView && this.parent.nativeViewProtected) {
993-
this.parent._setChildMinHeightNative(this);
993+
this.parent._setChildMinHeightNative(this, value);
994994
} else {
995-
this._setMinHeightNative(this.minHeight);
995+
this._setMinHeightNative(value);
996996
}
997997
}
998998

@@ -1050,16 +1050,15 @@ export class CustomLayoutView extends ContainerView implements CustomLayoutViewD
10501050
}
10511051

10521052
public _updateNativeLayoutParams(child: View): void {
1053-
this._setChildMinWidthNative(child);
1054-
this._setChildMinHeightNative(child);
1053+
// noop
10551054
}
10561055

1057-
public _setChildMinWidthNative(child: View): void {
1058-
child._setMinWidthNative(child.minWidth);
1056+
public _setChildMinWidthNative(child: View, value: Length): void {
1057+
child._setMinWidthNative(value);
10591058
}
10601059

1061-
public _setChildMinHeightNative(child: View): void {
1062-
child._setMinHeightNative(child.minHeight);
1060+
public _setChildMinHeightNative(child: View, value: Length): void {
1061+
child._setMinHeightNative(value);
10631062
}
10641063

10651064
public _removeViewFromNativeVisualTree(child: ViewCommon): void {

nativescript-core/ui/core/view/view.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,11 +796,11 @@ export class CustomLayoutView extends ContainerView {
796796
/**
797797
* @private
798798
*/
799-
_setChildMinWidthNative(child: View): void;
799+
_setChildMinWidthNative(child: View, value: Length): void;
800800
/**
801801
* @private
802802
*/
803-
_setChildMinHeightNative(child: View): void;
803+
_setChildMinHeightNative(child: View, value: Length): void;
804804
//@endprivate
805805
}
806806

nativescript-core/ui/layouts/flexbox-layout/flexbox-layout.android.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
flexShrinkProperty, FlexShrink,
88
flexWrapBeforeProperty, FlexWrapBefore,
99
alignSelfProperty, AlignSelf,
10-
flexDirectionProperty, flexWrapProperty, justifyContentProperty, alignItemsProperty, alignContentProperty
10+
flexDirectionProperty, flexWrapProperty, justifyContentProperty, alignItemsProperty, alignContentProperty,
11+
minWidthProperty, minHeightProperty,
12+
CssProperty
1113
} from "./flexbox-layout-common";
1214

1315
export * from "./flexbox-layout-common";
@@ -137,6 +139,11 @@ export class FlexboxLayout extends FlexboxLayoutBase {
137139
public _updateNativeLayoutParams(child: View): void {
138140
super._updateNativeLayoutParams(child);
139141

142+
// NOTE: If minWidth/Height is not set, the next code will clear the default native values for minWidth/Height.
143+
// Flex box will not respect the button default min width. Keeping this behavior for back-compatibility.
144+
this._setChildMinWidthNative(child, child.minWidth);
145+
this._setChildMinHeightNative(child, child.minHeight);
146+
140147
const lp = <org.nativescript.widgets.FlexboxLayout.LayoutParams>child.nativeViewProtected.getLayoutParams();
141148
const style = child.style;
142149
lp.order = style.order;
@@ -147,22 +154,30 @@ export class FlexboxLayout extends FlexboxLayoutBase {
147154
child.nativeViewProtected.setLayoutParams(lp);
148155
}
149156

150-
public _setChildMinWidthNative(child: View): void {
151-
child._setMinWidthNative(0);
157+
public _setChildMinWidthNative(child: View, value: Length): void {
158+
// Check needed to maintain back-compat after https://github.com/NativeScript/NativeScript/pull/7804
159+
if (!child._ignoreFlexMinWidthHeightReset) {
160+
child._setMinWidthNative(0);
161+
}
162+
152163
const nativeView = child.nativeViewProtected;
153164
const lp = nativeView.getLayoutParams();
154165
if (lp instanceof widgetLayoutParams) {
155-
lp.minWidth = Length.toDevicePixels(child.style.minWidth, 0);
166+
lp.minWidth = Length.toDevicePixels(value, 0);
156167
nativeView.setLayoutParams(lp);
157168
}
158169
}
159170

160-
public _setChildMinHeightNative(child: View): void {
161-
child._setMinHeightNative(0);
171+
public _setChildMinHeightNative(child: View, value: Length): void {
172+
// Check needed to maintain back-compat after https://github.com/NativeScript/NativeScript/pull/7804
173+
if (!child._ignoreFlexMinWidthHeightReset) {
174+
child._setMinHeightNative(0);
175+
}
176+
162177
const nativeView = child.nativeViewProtected;
163178
const lp = nativeView.getLayoutParams();
164179
if (lp instanceof widgetLayoutParams) {
165-
lp.minHeight = Length.toDevicePixels(child.style.minHeight, 0);
180+
lp.minHeight = Length.toDevicePixels(value, 0);
166181
nativeView.setLayoutParams(lp);
167182
}
168183
}

tns-core-modules-package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
"android": "5.0.0"
2323
}
2424
}
25-
}
25+
}

0 commit comments

Comments
 (0)