Split YogaConfig into interface and actual implementation
Summary: Split YogaConfig into the same way YogaNode is split today. Into an abstract class defining the interface, and actual JNI implementation Reviewed By: SidharthGuglani Differential Revision: D17266404 fbshipit-source-id: 3d5d6aa65c55cfa61d47c662d140cdce6dcb0ea1
This commit is contained in:
committed by
Facebook Github Bot
parent
21f814b2a6
commit
9100019c0a
@@ -6,78 +6,35 @@
|
|||||||
*/
|
*/
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.soloader.SoLoader;
|
public abstract class YogaConfig {
|
||||||
|
|
||||||
public class YogaConfig {
|
|
||||||
|
|
||||||
public static int SPACING_TYPE = 1;
|
public static int SPACING_TYPE = 1;
|
||||||
|
|
||||||
private long mNativePointer;
|
public abstract void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled);
|
||||||
private YogaLogger mLogger;
|
|
||||||
private YogaNodeCloneFunction mYogaNodeCloneFunction;
|
|
||||||
|
|
||||||
public YogaConfig() {
|
public abstract void setUseWebDefaults(boolean useWebDefaults);
|
||||||
mNativePointer = YogaNative.jni_YGConfigNew();
|
|
||||||
if (mNativePointer == 0) {
|
|
||||||
throw new IllegalStateException("Failed to allocate native memory");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public abstract void setPrintTreeFlag(boolean enable);
|
||||||
protected void finalize() throws Throwable {
|
|
||||||
try {
|
|
||||||
YogaNative.jni_YGConfigFree(mNativePointer);
|
|
||||||
} finally {
|
|
||||||
super.finalize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
|
|
||||||
YogaNative.jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUseWebDefaults(boolean useWebDefaults) {
|
|
||||||
YogaNative.jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrintTreeFlag(boolean enable) {
|
|
||||||
YogaNative.jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPointScaleFactor(float pixelsInPoint) {
|
|
||||||
YogaNative.jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public abstract void setPointScaleFactor(float pixelsInPoint);
|
||||||
/**
|
/**
|
||||||
* Yoga previously had an error where containers would take the maximum space possible instead of the minimum
|
* Yoga previously had an error where containers would take the maximum space possible instead of the minimum
|
||||||
* like they are supposed to. In practice this resulted in implicit behaviour similar to align-self: stretch;
|
* like they are supposed to. In practice this resulted in implicit behaviour similar to align-self: stretch;
|
||||||
* Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour.
|
* Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour.
|
||||||
*/
|
*/
|
||||||
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
|
public abstract void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour);
|
||||||
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this flag is set then yoga would diff the layout without legacy flag and would set a bool in
|
* If this flag is set then yoga would diff the layout without legacy flag and would set a bool in
|
||||||
* YogaNode(mDoesLegacyStretchFlagAffectsLayout) with true if the layouts were different and false
|
* YogaNode(mDoesLegacyStretchFlagAffectsLayout) with true if the layouts were different and false
|
||||||
* if not
|
* if not
|
||||||
*/
|
*/
|
||||||
public void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
public abstract void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||||
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) {
|
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||||
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
|
||||||
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLogger(YogaLogger logger) {
|
public abstract void setLogger(YogaLogger logger);
|
||||||
mLogger = logger;
|
|
||||||
YogaNative.jni_YGConfigSetLogger(mNativePointer, logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
public YogaLogger getLogger() {
|
public abstract YogaLogger getLogger();
|
||||||
return mLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
long getNativePointer() {
|
abstract long getNativePointer();
|
||||||
return mNativePointer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,6 @@ package com.facebook.yoga;
|
|||||||
|
|
||||||
public abstract class YogaConfigFactory {
|
public abstract class YogaConfigFactory {
|
||||||
public static YogaConfig create() {
|
public static YogaConfig create() {
|
||||||
return new YogaConfig();
|
return new YogaConfigJNIFinalizer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
76
java/com/facebook/yoga/YogaConfigJNIBase.java
Normal file
76
java/com/facebook/yoga/YogaConfigJNIBase.java
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.facebook.soloader.SoLoader;
|
||||||
|
|
||||||
|
public abstract class YogaConfigJNIBase extends YogaConfig {
|
||||||
|
|
||||||
|
protected long mNativePointer;
|
||||||
|
private YogaLogger mLogger;
|
||||||
|
private YogaNodeCloneFunction mYogaNodeCloneFunction;
|
||||||
|
|
||||||
|
private YogaConfigJNIBase(long nativePointer) {
|
||||||
|
if (nativePointer == 0) {
|
||||||
|
throw new IllegalStateException("Failed to allocate native memory");
|
||||||
|
}
|
||||||
|
mNativePointer = nativePointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
YogaConfigJNIBase() {
|
||||||
|
this(YogaNative.jni_YGConfigNew());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
|
||||||
|
YogaNative.jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseWebDefaults(boolean useWebDefaults) {
|
||||||
|
YogaNative.jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrintTreeFlag(boolean enable) {
|
||||||
|
YogaNative.jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPointScaleFactor(float pixelsInPoint) {
|
||||||
|
YogaNative.jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Yoga previously had an error where containers would take the maximum space possible instead of the minimum
|
||||||
|
* like they are supposed to. In practice this resulted in implicit behaviour similar to align-self: stretch;
|
||||||
|
* Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour.
|
||||||
|
*/
|
||||||
|
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
|
||||||
|
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this flag is set then yoga would diff the layout without legacy flag and would set a bool in
|
||||||
|
* YogaNode(mDoesLegacyStretchFlagAffectsLayout) with true if the layouts were different and false
|
||||||
|
* if not
|
||||||
|
*/
|
||||||
|
public void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||||
|
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) {
|
||||||
|
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||||
|
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogger(YogaLogger logger) {
|
||||||
|
mLogger = logger;
|
||||||
|
YogaNative.jni_YGConfigSetLogger(mNativePointer, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public YogaLogger getLogger() {
|
||||||
|
return mLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getNativePointer() {
|
||||||
|
return mNativePointer;
|
||||||
|
}
|
||||||
|
}
|
30
java/com/facebook/yoga/YogaConfigJNIFinalizer.java
Normal file
30
java/com/facebook/yoga/YogaConfigJNIFinalizer.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public class YogaConfigJNIFinalizer extends YogaConfigJNIBase {
|
||||||
|
public YogaConfigJNIFinalizer() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
try {
|
||||||
|
freeNatives();
|
||||||
|
} finally {
|
||||||
|
super.finalize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void freeNatives() {
|
||||||
|
if (mNativePointer != 0) {
|
||||||
|
long nativePointer = mNativePointer;
|
||||||
|
mNativePointer = 0;
|
||||||
|
YogaNative.jni_YGConfigFree(nativePointer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user