Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged

Conversation

farfromrefug
Copy link
Collaborator

This PR simplifies the android code a bit to make less calls to android native constants. Thus less JNI bridge calls =>faster

@cla-bot cla-bot bot added the cla: yes label Dec 30, 2020
@@ -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.

Copy link
Collaborator Author

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.

// 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.

Copy link
Collaborator Author

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

@NathanWalker NathanWalker added this to the 8.1 milestone Jul 12, 2021
@NathanWalker NathanWalker changed the base branch from master to release/8.1.0 August 11, 2021 18:31
@NathanWalker NathanWalker merged commit bca4d95 into NativeScript:release/8.1.0 Aug 11, 2021
@farfromrefug farfromrefug deleted the faster_android_alignments branch August 11, 2021 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants