Add the ability to attach data to a java CSSNode

Summary: The C version already has this ability via the same name 'context'. This can be used to attach arbitrary data about your view hierarchy to a CSSNode. Previously this could only be done in java via subclassing CSSNode.

Reviewed By: lucasr

Differential Revision: D3662065

fbshipit-source-id: 560a768092f17381e99b349d08bd4a8b365541be
This commit is contained in:
Emil Sjolander
2016-08-04 08:20:07 -07:00
committed by Facebook Github Bot 9
parent b32d384337
commit 9278ff462e
3 changed files with 24 additions and 0 deletions

View File

@@ -63,6 +63,7 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
private @Nullable MeasureFunction mMeasureFunction = null; private @Nullable MeasureFunction mMeasureFunction = null;
private LayoutState mLayoutState = LayoutState.DIRTY; private LayoutState mLayoutState = LayoutState.DIRTY;
private boolean mIsTextNode = false; private boolean mIsTextNode = false;
private Object mData;
@Override @Override
public void init() { public void init() {
@@ -621,6 +622,16 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
} }
} }
@Override
public void setData(Object data) {
mData = data;
}
@Override
public Object getData() {
return mData;
}
/** /**
* Resets this instance to its default state. This method is meant to be used when * Resets this instance to its default state. This method is meant to be used when
* recycling {@link CSSNode} instances. * recycling {@link CSSNode} instances.

View File

@@ -88,6 +88,8 @@ public interface CSSNodeAPI<CSSNodeType extends CSSNodeAPI> {
void setDefaultPadding(int spacingType, float padding); void setDefaultPadding(int spacingType, float padding);
CSSOverflow getOverflow(); CSSOverflow getOverflow();
void setOverflow(CSSOverflow overflow); void setOverflow(CSSOverflow overflow);
void setData(Object data);
Object getData();
void init(); void init();
void reset(); void reset();
} }

View File

@@ -33,6 +33,7 @@ public class CSSNodeJNI implements CSSNodeAPI<CSSNodeJNI> {
private List<CSSNodeJNI> mChildren; private List<CSSNodeJNI> mChildren;
private MeasureFunction mMeasureFunction; private MeasureFunction mMeasureFunction;
private int mNativePointer; private int mNativePointer;
private Object mData;
private void assertNativeInstance() { private void assertNativeInstance() {
if (mNativePointer == 0) { if (mNativePointer == 0) {
@@ -718,4 +719,14 @@ public class CSSNodeJNI implements CSSNodeAPI<CSSNodeJNI> {
public boolean valuesEqual(float f1, float f2) { public boolean valuesEqual(float f1, float f2) {
return FloatUtil.floatsEqual(f1, f2); return FloatUtil.floatsEqual(f1, f2);
} }
@Override
public void setData(Object data) {
mData = data;
}
@Override
public Object getData() {
return mData;
}
} }