mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Apply gravity in android if LayoutParams have gravity field. (#3814)
ActionBar titleView aligments are applied only if no alignment are set to titleView and after view is added to visual tree otherwise they were reset in addView method
This commit is contained in:
@ -61,10 +61,18 @@ export class ActionBarBase extends View implements ActionBarDefinition {
|
||||
|
||||
this._titleView = value;
|
||||
|
||||
if (this._titleView) {
|
||||
this._titleView.style[horizontalAlignmentProperty.cssName] = "center";
|
||||
this._titleView.style[verticalAlignmentProperty.cssName] = "middle";
|
||||
this._addView(this._titleView);
|
||||
if (value) {
|
||||
// Addview will reset CSS properties so we first add it then set aligments with lowest priority.
|
||||
this._addView(value);
|
||||
const style = value.style;
|
||||
|
||||
if (!horizontalAlignmentProperty.isSet(style)) {
|
||||
style[horizontalAlignmentProperty.cssName] = "center";
|
||||
}
|
||||
|
||||
if (!verticalAlignmentProperty.isSet(style)) {
|
||||
style[verticalAlignmentProperty.cssName] = "middle";
|
||||
}
|
||||
}
|
||||
|
||||
this.update();
|
||||
|
@ -370,15 +370,53 @@ export class View extends ViewCommon {
|
||||
get [horizontalAlignmentProperty.native](): HorizontalAlignment {
|
||||
return <HorizontalAlignment>org.nativescript.widgets.ViewHelper.getHorizontalAlignment(this.nativeView);
|
||||
}
|
||||
set [horizontalAlignmentProperty.native](value: HorizontalAlignment) {
|
||||
org.nativescript.widgets.ViewHelper.setHorizontalAlignment(this.nativeView, value);
|
||||
set [horizontalAlignmentProperty.native](value: HorizontalAlignment) {
|
||||
const nativeView = this.nativeView;
|
||||
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
|
||||
// Set only if params gravity exists.
|
||||
if (lp.gravity !== undefined) {
|
||||
switch (value) {
|
||||
case "left":
|
||||
lp.gravity = android.view.Gravity.LEFT | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
||||
break;
|
||||
case "center":
|
||||
lp.gravity = android.view.Gravity.CENTER_HORIZONTAL | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
||||
break;
|
||||
case "right":
|
||||
lp.gravity = android.view.Gravity.RIGHT | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
||||
break;
|
||||
case "stretch":
|
||||
lp.gravity = android.view.Gravity.FILL_HORIZONTAL | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
||||
break;
|
||||
}
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
||||
get [verticalAlignmentProperty.native](): VerticalAlignment {
|
||||
return <VerticalAlignment>org.nativescript.widgets.ViewHelper.getVerticalAlignment(this.nativeView);
|
||||
}
|
||||
set [verticalAlignmentProperty.native](value: VerticalAlignment) {
|
||||
org.nativescript.widgets.ViewHelper.setVerticalAlignment(this.nativeView, value);
|
||||
const nativeView = this.nativeView;
|
||||
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
|
||||
// Set only if params gravity exists.
|
||||
if (lp.gravity !== undefined) {
|
||||
switch (value) {
|
||||
case "top":
|
||||
lp.gravity = android.view.Gravity.TOP | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
||||
break;
|
||||
case "middle":
|
||||
lp.gravity = android.view.Gravity.CENTER_VERTICAL | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
||||
break;
|
||||
case "bottom":
|
||||
lp.gravity = android.view.Gravity.BOTTOM | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
||||
break;
|
||||
case "stretch":
|
||||
lp.gravity = android.view.Gravity.FILL_VERTICAL | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
||||
break;
|
||||
}
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
||||
get [rotateProperty.native](): number {
|
||||
|
Reference in New Issue
Block a user