CSSNodeCopyStyle API for Java and C#

Summary: Add CopyStyle API for Java and C#

Reviewed By: emilsjolander

Differential Revision: D4189954

fbshipit-source-id: 10759fdb27bf67350d3151614f7815aa09bf7e04
This commit is contained in:
Kazuki Sakamoto
2016-11-17 09:10:47 -08:00
committed by Facebook Github Bot
parent 191ac98b89
commit 0bb2955c5c
8 changed files with 52 additions and 1 deletions

View File

@@ -90,6 +90,11 @@ namespace Facebook.CSSLayout
} }
} }
public void CopyStyle(CSSNode srcNode)
{
Native.CSSNodeCopyStyle(_cssNode, srcNode._cssNode);
}
public CSSDirection StyleDirection public CSSDirection StyleDirection
{ {
get get

View File

@@ -80,6 +80,9 @@ namespace Facebook.CSSLayout
[return: MarshalAs(UnmanagedType.I1)] [return: MarshalAs(UnmanagedType.I1)]
public static extern bool CSSValueIsUndefined(float value); public static extern bool CSSValueIsUndefined(float value);
[DllImport(DllName)]
public static extern void CSSNodeCopyStyle(IntPtr dstNode, IntPtr srcNode);
#region CSS_NODE_PROPERTY #region CSS_NODE_PROPERTY
[DllImport(DllName)] [DllImport(DllName)]

View File

@@ -215,13 +215,26 @@ namespace Facebook.CSSLayout
Assert.AreEqual(parent.Print(), "{layout: {width: 100, height: 120, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 100, height: 120, children: [\n {layout: {width: 35, height: 45, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 35, height: 45, },\n {layout: {width: 30, height: 40, top: 45, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 30, height: 40, },\n]},\n"); Assert.AreEqual(parent.Print(), "{layout: {width: 100, height: 120, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 100, height: 120, children: [\n {layout: {width: 35, height: 45, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 35, height: 45, },\n {layout: {width: 30, height: 40, top: 45, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 30, height: 40, },\n]},\n");
} }
[Test]
public void TestCopyStyle()
{
CSSNode node0 = new CSSNode();
Assert.IsTrue(CSSConstants.IsUndefined(node0.StyleMaxHeight));
CSSNode node1 = new CSSNode();
node1.StyleMaxHeight = 100;
node0.CopyStyle(node1);
Assert.AreEqual(100, node0.StyleMaxHeight);
}
#if !UNITY_EDITOR
private void ForceGC() private void ForceGC()
{ {
GC.Collect(GC.MaxGeneration); GC.Collect(GC.MaxGeneration);
GC.WaitForPendingFinalizers(); GC.WaitForPendingFinalizers();
} }
#if !UNITY_EDITOR
[Test] [Test]
public void TestDestructor() public void TestDestructor()
{ {

View File

@@ -190,6 +190,12 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
jni_CSSNodeMarkLayoutSeen(mNativePointer); jni_CSSNodeMarkLayoutSeen(mNativePointer);
} }
private native void jni_CSSNodeCopyStyle(long dstNativePointer, long srcNativePointer);
@Override
public void copyStyle(CSSNode srcNode) {
jni_CSSNodeCopyStyle(mNativePointer, srcNode.mNativePointer);
}
private native int jni_CSSNodeStyleGetDirection(long nativePointer); private native int jni_CSSNodeStyleGetDirection(long nativePointer);
@Override @Override
public CSSDirection getStyleDirection() { public CSSDirection getStyleDirection() {

View File

@@ -37,6 +37,7 @@ public interface CSSNodeAPI<CSSNodeType extends CSSNodeAPI> {
void dirty(); void dirty();
void markLayoutSeen(); void markLayoutSeen();
boolean valuesEqual(float f1, float f2); boolean valuesEqual(float f1, float f2);
void copyStyle(CSSNodeType srcNode);
CSSDirection getStyleDirection(); CSSDirection getStyleDirection();
void setDirection(CSSDirection direction); void setDirection(CSSDirection direction);
CSSFlexDirection getFlexDirection(); CSSFlexDirection getFlexDirection();

View File

@@ -222,6 +222,11 @@ public class CSSNodeDEPRECATED implements CSSNodeAPI<CSSNodeDEPRECATED> {
return FloatUtil.floatsEqual(f1, f2); return FloatUtil.floatsEqual(f1, f2);
} }
@Override
public void copyStyle(CSSNodeDEPRECATED srcNode) {
throw new UnsupportedOperationException("copyStyle is not implemented");
}
/** /**
* Get this node's direction, as defined in the style. * Get this node's direction, as defined in the style.
*/ */

View File

@@ -187,6 +187,10 @@ void jni_CSSNodeMarkLayoutSeen(alias_ref<jobject>, jlong nativePointer) {
CSSNodeSetHasNewLayout(_jlong2CSSNodeRef(nativePointer), false); CSSNodeSetHasNewLayout(_jlong2CSSNodeRef(nativePointer), false);
} }
void jni_CSSNodeCopyStyle(alias_ref<jobject>, jlong dstNativePointer, jlong srcNativePointer) {
CSSNodeCopyStyle(_jlong2CSSNodeRef(dstNativePointer), _jlong2CSSNodeRef(srcNativePointer));
}
#define CSS_NODE_JNI_STYLE_PROP(javatype, type, name) \ #define CSS_NODE_JNI_STYLE_PROP(javatype, type, name) \
javatype jni_CSSNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer) { \ javatype jni_CSSNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer) { \
return (javatype) CSSNodeStyleGet##name(_jlong2CSSNodeRef(nativePointer)); \ return (javatype) CSSNodeStyleGet##name(_jlong2CSSNodeRef(nativePointer)); \
@@ -257,6 +261,7 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
CSSMakeNativeMethod(jni_CSSNodeIsDirty), CSSMakeNativeMethod(jni_CSSNodeIsDirty),
CSSMakeNativeMethod(jni_CSSNodeMarkLayoutSeen), CSSMakeNativeMethod(jni_CSSNodeMarkLayoutSeen),
CSSMakeNativeMethod(jni_CSSNodeSetHasMeasureFunc), CSSMakeNativeMethod(jni_CSSNodeSetHasMeasureFunc),
CSSMakeNativeMethod(jni_CSSNodeCopyStyle),
CSSMakeNativeMethod(jni_CSSNodeStyleGetDirection), CSSMakeNativeMethod(jni_CSSNodeStyleGetDirection),
CSSMakeNativeMethod(jni_CSSNodeStyleSetDirection), CSSMakeNativeMethod(jni_CSSNodeStyleSetDirection),

View File

@@ -12,6 +12,7 @@ package com.facebook.csslayout;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class CSSNodeTest { public class CSSNodeTest {
@@ -71,4 +72,16 @@ public class CSSNodeTest {
assertEquals(CSSLogLevel.VERBOSE, mLogLevel); assertEquals(CSSLogLevel.VERBOSE, mLogLevel);
assertEquals("Flexbox", mLogMessage); assertEquals("Flexbox", mLogMessage);
} }
@Test
public void testCopyStyle() {
final CSSNode node0 = new CSSNode();
assertTrue(CSSConstants.isUndefined(node0.getStyleMaxHeight()));
final CSSNode node1 = new CSSNode();
node1.setStyleMaxHeight(100);
node0.copyStyle(node1);
assertEquals(100, (int) node0.getStyleMaxHeight());
}
} }