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
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; | |||
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 would eliminate these two extra variables. And revert the rest of the statements back to using lp.gravity and lp.weight as all you have done is added additional memory usage (which has to be GC'd) for no purpose and now have mixed values throughout below. You assign lp.gravity from gravity on line 872. This just confuses the source for people who later read it.
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; | |||
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.
Same comment as above.
| // 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 |
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.
What is 3, 1, 5, 7. Definitely would be better to create the const at the top so that the code is easier to read.
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
The text was updated successfully, but these errors were encountered: