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>
This commit is contained in:
Bundyo (Kamen Bundev)
2020-03-26 13:07:04 +02:00
committed by GitHub
parent 1f04469fb3
commit 66cc8a477e
12 changed files with 152 additions and 80 deletions

View File

@ -41,12 +41,14 @@
"ios": "6.0.0",
"android": "6.0.0"
},
"hooks": [{
"name": "nativescript-core",
"type": "before-checkForChanges",
"script": "cli-hooks/before-checkForChanges.js",
"inject": true
}]
"hooks": [
{
"name": "nativescript-core",
"type": "before-checkForChanges",
"script": "cli-hooks/before-checkForChanges.js",
"inject": true
}
]
},
"snapshot": {
"android": {
@ -58,4 +60,4 @@
}
}
}
}
}

View File

@ -1,7 +1,8 @@
import {
ButtonBase, PseudoClassHandler,
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty,
Length, zIndexProperty, textAlignmentProperty, TextAlignment
Length, zIndexProperty, textAlignmentProperty, TextAlignment, layout,
minWidthProperty, minHeightProperty
} from "./button-common";
import { profile } from "../../profiling";
import { TouchGestureEventData, GestureTypes, TouchAction } from "../gestures";
@ -111,6 +112,18 @@ export class Button extends ButtonBase {
}
}
[minWidthProperty.getDefault](): Length {
const dips = org.nativescript.widgets.ViewHelper.getMinWidth(this.nativeViewProtected);
return { value: dips, unit: "px" };
}
[minHeightProperty.getDefault](): Length {
const dips = org.nativescript.widgets.ViewHelper.getMinHeight(this.nativeViewProtected);
return { value: dips, unit: "px" };
}
[paddingTopProperty.getDefault](): Length {
return { value: this._defaultPaddingTop, unit: "px" };
}
@ -177,3 +190,5 @@ export class Button extends ButtonBase {
return 4; // 4dp @dimen/button_pressed_z_material
}
}
Button.prototype._ignoreFlexMinWidthHeightReset = true;

View File

@ -432,10 +432,17 @@ export abstract class ViewBase extends Observable {
* @private
*/
public recycleNativeView: "always" | "never" | "auto";
/**
* @private
*/
public _isPaddingRelative: boolean;
/**
* @private
*/
public _ignoreFlexMinWidthHeightReset: boolean;
public _styleScope: any;
/**

View File

@ -227,6 +227,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
_oldTop: number;
_oldRight: number;
_oldBottom: number;
_ignoreFlexMinWidthHeightReset: boolean;
public effectiveMinWidth: number;
public effectiveMinHeight: number;

View File

@ -389,7 +389,7 @@ export class View extends ViewCommon {
this.nativeViewProtected.setClickable(this._isClickable);
}
}
this._manager = null;
this._rootManager = null;
super.onUnloaded();
@ -982,17 +982,17 @@ export class View extends ViewCommon {
[minWidthProperty.setNative](value: Length) {
if (this.parent instanceof CustomLayoutView && this.parent.nativeViewProtected) {
this.parent._setChildMinWidthNative(this);
this.parent._setChildMinWidthNative(this, value);
} else {
this._setMinWidthNative(this.minWidth);
this._setMinWidthNative(value);
}
}
[minHeightProperty.setNative](value: Length) {
if (this.parent instanceof CustomLayoutView && this.parent.nativeViewProtected) {
this.parent._setChildMinHeightNative(this);
this.parent._setChildMinHeightNative(this, value);
} else {
this._setMinHeightNative(this.minHeight);
this._setMinHeightNative(value);
}
}
@ -1050,16 +1050,15 @@ export class CustomLayoutView extends ContainerView implements CustomLayoutViewD
}
public _updateNativeLayoutParams(child: View): void {
this._setChildMinWidthNative(child);
this._setChildMinHeightNative(child);
// noop
}
public _setChildMinWidthNative(child: View): void {
child._setMinWidthNative(child.minWidth);
public _setChildMinWidthNative(child: View, value: Length): void {
child._setMinWidthNative(value);
}
public _setChildMinHeightNative(child: View): void {
child._setMinHeightNative(child.minHeight);
public _setChildMinHeightNative(child: View, value: Length): void {
child._setMinHeightNative(value);
}
public _removeViewFromNativeVisualTree(child: ViewCommon): void {

View File

@ -796,11 +796,11 @@ export class CustomLayoutView extends ContainerView {
/**
* @private
*/
_setChildMinWidthNative(child: View): void;
_setChildMinWidthNative(child: View, value: Length): void;
/**
* @private
*/
_setChildMinHeightNative(child: View): void;
_setChildMinHeightNative(child: View, value: Length): void;
//@endprivate
}

View File

@ -7,7 +7,9 @@ import {
flexShrinkProperty, FlexShrink,
flexWrapBeforeProperty, FlexWrapBefore,
alignSelfProperty, AlignSelf,
flexDirectionProperty, flexWrapProperty, justifyContentProperty, alignItemsProperty, alignContentProperty
flexDirectionProperty, flexWrapProperty, justifyContentProperty, alignItemsProperty, alignContentProperty,
minWidthProperty, minHeightProperty,
CssProperty
} from "./flexbox-layout-common";
export * from "./flexbox-layout-common";
@ -137,6 +139,11 @@ export class FlexboxLayout extends FlexboxLayoutBase {
public _updateNativeLayoutParams(child: View): void {
super._updateNativeLayoutParams(child);
// NOTE: If minWidth/Height is not set, the next code will clear the default native values for minWidth/Height.
// Flex box will not respect the button default min width. Keeping this behavior for back-compatibility.
this._setChildMinWidthNative(child, child.minWidth);
this._setChildMinHeightNative(child, child.minHeight);
const lp = <org.nativescript.widgets.FlexboxLayout.LayoutParams>child.nativeViewProtected.getLayoutParams();
const style = child.style;
lp.order = style.order;
@ -147,22 +154,30 @@ export class FlexboxLayout extends FlexboxLayoutBase {
child.nativeViewProtected.setLayoutParams(lp);
}
public _setChildMinWidthNative(child: View): void {
child._setMinWidthNative(0);
public _setChildMinWidthNative(child: View, value: Length): void {
// Check needed to maintain back-compat after https://github.com/NativeScript/NativeScript/pull/7804
if (!child._ignoreFlexMinWidthHeightReset) {
child._setMinWidthNative(0);
}
const nativeView = child.nativeViewProtected;
const lp = nativeView.getLayoutParams();
if (lp instanceof widgetLayoutParams) {
lp.minWidth = Length.toDevicePixels(child.style.minWidth, 0);
lp.minWidth = Length.toDevicePixels(value, 0);
nativeView.setLayoutParams(lp);
}
}
public _setChildMinHeightNative(child: View): void {
child._setMinHeightNative(0);
public _setChildMinHeightNative(child: View, value: Length): void {
// Check needed to maintain back-compat after https://github.com/NativeScript/NativeScript/pull/7804
if (!child._ignoreFlexMinWidthHeightReset) {
child._setMinHeightNative(0);
}
const nativeView = child.nativeViewProtected;
const lp = nativeView.getLayoutParams();
if (lp instanceof widgetLayoutParams) {
lp.minHeight = Length.toDevicePixels(child.style.minHeight, 0);
lp.minHeight = Length.toDevicePixels(value, 0);
nativeView.setLayoutParams(lp);
}
}