Create YogaValue instances in Java, not C++

Summary:
@public

Passing primitive data via JNI is more efficient than passing objects.

Here, we avoid creating `YogaValue` (Java) instances via JNI, and rather pass a `long` back to Java. The instance is then created by extracting the necessary bytes on the Java side.

Reviewed By: foghina

Differential Revision: D14576755

fbshipit-source-id: 22d09ad50c3ac6c49b0a797a0dad639ea4829df9
This commit is contained in:
David Aurelio
2019-03-22 10:31:18 -07:00
committed by Facebook Github Bot
parent 5bb2265083
commit ca46c67e9e
6 changed files with 67 additions and 48 deletions

View File

@@ -1,9 +1,8 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
package com.facebook.yoga;
@@ -401,6 +400,21 @@ public class YogaNodeStylePropertiesTest {
}
}
@Test
public void testNegativeMarginAssignment() {
final YogaNode node = createNode();
for (YogaEdge edge : YogaEdge.values()) {
node.setMargin(edge, -25);
assertEquals(new YogaValue(-25, YogaUnit.POINT), node.getMargin(edge));
node.setMarginPercent(edge, -5);
assertEquals(new YogaValue(-5, YogaUnit.PERCENT), node.getMargin(edge));
node.setMarginAuto(edge);
assertEquals(YogaValue.AUTO, node.getMargin(edge));
}
}
@Test
public void testMarginPointAffectsLayout() {
final YogaNode node = style().margin(YogaEdge.TOP, 42).node();