mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
fix(android): make less calls to native with getters around prop handling (#9119)
This commit is contained in:

committed by
Nathan Walker

parent
2dd2970c7d
commit
a76815b81e
@ -38,6 +38,17 @@ const statePressed = 16842919; // android.R.attr.state_pressed
|
|||||||
const stateEnabled = 16842910; // android.R.attr.state_enabled
|
const stateEnabled = 16842910; // android.R.attr.state_enabled
|
||||||
const styleAnimationDialog = 16973826; // android.R.style.Animation_Dialog
|
const styleAnimationDialog = 16973826; // android.R.style.Animation_Dialog
|
||||||
|
|
||||||
|
const VERTICAL_GRAVITY_MASK = 112; // android.view.Gravity.VERTICAL_GRAVITY_MASK
|
||||||
|
const HORIZONTAL_GRAVITY_MASK = 7; // android.view.Gravity.HORIZONTAL_GRAVITY_MASK
|
||||||
|
const GRAVITY_LEFT = 3; // android.view.Gravity.LEFT
|
||||||
|
const GRAVITY_RIGHT = 5; // android.view.Gravity.RIGHT
|
||||||
|
const GRAVITY_TOP = 48; // android.view.Gravity.TOP
|
||||||
|
const GRAVITY_BOTTOM = 80; // android.view.Gravity.BOTTOM
|
||||||
|
const GRAVITY_CENTER_HORIZONTAL = 1; // android.view.Gravity.CENTER_HORIZONTAL
|
||||||
|
const GRAVITY_FILL_HORIZONTAL = 7; // android.view.Gravity.FILL_HORIZONTAL
|
||||||
|
const GRAVITY_CENTER_VERTICAL = 16; // android.view.Gravity.CENTER_VERTICAL
|
||||||
|
const GRAVITY_FILL_VERTICAL = 112; // android.view.Gravity.FILL_VERTICAL
|
||||||
|
|
||||||
const sdkVersion = lazy(() => parseInt(Device.sdkVersion));
|
const sdkVersion = lazy(() => parseInt(Device.sdkVersion));
|
||||||
|
|
||||||
const modalMap = new Map<number, DialogOptions>();
|
const modalMap = new Map<number, DialogOptions>();
|
||||||
@ -932,30 +943,32 @@ export class View extends ViewCommon {
|
|||||||
[horizontalAlignmentProperty.setNative](value: CoreTypes.HorizontalAlignmentType) {
|
[horizontalAlignmentProperty.setNative](value: CoreTypes.HorizontalAlignmentType) {
|
||||||
const nativeView = this.nativeViewProtected;
|
const nativeView = this.nativeViewProtected;
|
||||||
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
|
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
|
||||||
|
const gravity = lp.gravity;
|
||||||
|
const weight = lp.weight;
|
||||||
// Set only if params gravity exists.
|
// Set only if params gravity exists.
|
||||||
if (lp.gravity !== undefined) {
|
if (gravity !== undefined) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 'left':
|
case 'left':
|
||||||
lp.gravity = android.view.Gravity.LEFT | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
lp.gravity = GRAVITY_LEFT | (gravity & VERTICAL_GRAVITY_MASK);
|
||||||
if (lp.weight < 0) {
|
if (weight < 0) {
|
||||||
lp.weight = -2;
|
lp.weight = -2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'center':
|
case 'center':
|
||||||
lp.gravity = android.view.Gravity.CENTER_HORIZONTAL | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
lp.gravity = GRAVITY_CENTER_HORIZONTAL | (gravity & VERTICAL_GRAVITY_MASK);
|
||||||
if (lp.weight < 0) {
|
if (weight < 0) {
|
||||||
lp.weight = -2;
|
lp.weight = -2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'right':
|
case 'right':
|
||||||
lp.gravity = android.view.Gravity.RIGHT | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
lp.gravity = GRAVITY_RIGHT | (gravity & VERTICAL_GRAVITY_MASK);
|
||||||
if (lp.weight < 0) {
|
if (weight < 0) {
|
||||||
lp.weight = -2;
|
lp.weight = -2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'stretch':
|
case 'stretch':
|
||||||
lp.gravity = android.view.Gravity.FILL_HORIZONTAL | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
lp.gravity = GRAVITY_FILL_HORIZONTAL | (gravity & VERTICAL_GRAVITY_MASK);
|
||||||
if (lp.weight < 0) {
|
if (weight < 0) {
|
||||||
lp.weight = -1;
|
lp.weight = -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -970,30 +983,32 @@ export class View extends ViewCommon {
|
|||||||
[verticalAlignmentProperty.setNative](value: CoreTypes.VerticalAlignmentType) {
|
[verticalAlignmentProperty.setNative](value: CoreTypes.VerticalAlignmentType) {
|
||||||
const nativeView = this.nativeViewProtected;
|
const nativeView = this.nativeViewProtected;
|
||||||
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
|
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
|
||||||
|
const gravity = lp.gravity;
|
||||||
|
const height = lp.height;
|
||||||
// Set only if params gravity exists.
|
// Set only if params gravity exists.
|
||||||
if (lp.gravity !== undefined) {
|
if (gravity !== undefined) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 'top':
|
case 'top':
|
||||||
lp.gravity = android.view.Gravity.TOP | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
lp.gravity = GRAVITY_TOP | (gravity & HORIZONTAL_GRAVITY_MASK);
|
||||||
if (lp.height < 0) {
|
if (height < 0) {
|
||||||
lp.height = -2;
|
lp.height = -2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'middle':
|
case 'middle':
|
||||||
lp.gravity = android.view.Gravity.CENTER_VERTICAL | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
lp.gravity = GRAVITY_CENTER_VERTICAL | (gravity & HORIZONTAL_GRAVITY_MASK);
|
||||||
if (lp.height < 0) {
|
if (height < 0) {
|
||||||
lp.height = -2;
|
lp.height = -2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'bottom':
|
case 'bottom':
|
||||||
lp.gravity = android.view.Gravity.BOTTOM | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
lp.gravity = GRAVITY_BOTTOM | (gravity & HORIZONTAL_GRAVITY_MASK);
|
||||||
if (lp.height < 0) {
|
if (height < 0) {
|
||||||
lp.height = -2;
|
lp.height = -2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'stretch':
|
case 'stretch':
|
||||||
lp.gravity = android.view.Gravity.FILL_VERTICAL | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
lp.gravity = GRAVITY_FILL_VERTICAL | (gravity & HORIZONTAL_GRAVITY_MASK);
|
||||||
if (lp.height < 0) {
|
if (height < 0) {
|
||||||
lp.height = -1;
|
lp.height = -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user