-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(android): refactor to make less calls to native #9119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(android): refactor to make less calls to native #9119
Conversation
@@ -860,30 +863,32 @@ export class View extends ViewCommon { | |||
[horizontalAlignmentProperty.setNative](value: HorizontalAlignment) { | |||
const nativeView = this.nativeViewProtected; | |||
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams(); | |||
const gravity = lp.gravity; | |||
const weight = lp.weight; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact I would not. I forgot a if lp.gravity which makes 2 calls to native accesser. Need to fix this. The idea is to make sure we don't access those native variables multiple times => multiple jni calls
@@ -898,30 +903,32 @@ export class View extends ViewCommon { | |||
[verticalAlignmentProperty.setNative](value: VerticalAlignment) { | |||
const nativeView = this.nativeViewProtected; | |||
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams(); | |||
const gravity = lp.gravity; | |||
const height = lp.height; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
// 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); | ||
if (lp.weight < 0) { | ||
lp.gravity = 3 | (gravity & VERTICAL_GRAVITY_MASK); // android.view.Gravity.LEFT |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember i copied the way it was done somewhere else. And I didn't want to unecessarly create global module variables.
But sure I ll change it
This PR simplifies the android code a bit to make less calls to android native constants. Thus less JNI bridge calls =>faster