2017-06-15 07:36:33 -07:00
|
|
|
/*
|
2017-03-01 09:19:55 -08:00
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-03-01 09:19:55 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.facebook.yoga;
|
|
|
|
|
|
|
|
import com.facebook.proguard.annotations.DoNotStrip;
|
|
|
|
import com.facebook.soloader.SoLoader;
|
|
|
|
|
|
|
|
@DoNotStrip
|
|
|
|
public class YogaConfig {
|
|
|
|
|
2018-01-12 04:44:21 -08:00
|
|
|
public static int SPACING_TYPE = 1;
|
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
static {
|
2018-03-01 04:00:28 -08:00
|
|
|
if (YogaConstants.shouldUseFastMath) {
|
|
|
|
SoLoader.loadLibrary("yogafastmath");
|
|
|
|
} else {
|
|
|
|
SoLoader.loadLibrary("yoga");
|
|
|
|
}
|
2017-03-01 09:19:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
long mNativePointer;
|
2017-05-03 09:22:35 -07:00
|
|
|
private YogaLogger mLogger;
|
2018-02-14 09:31:10 -08:00
|
|
|
private YogaNodeClonedFunction mNodeClonedFunction;
|
2017-03-01 09:19:55 -08:00
|
|
|
|
|
|
|
private native long jni_YGConfigNew();
|
|
|
|
public YogaConfig() {
|
|
|
|
mNativePointer = jni_YGConfigNew();
|
|
|
|
if (mNativePointer == 0) {
|
|
|
|
throw new IllegalStateException("Failed to allocate native memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private native void jni_YGConfigFree(long nativePointer);
|
|
|
|
@Override
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
try {
|
|
|
|
jni_YGConfigFree(mNativePointer);
|
|
|
|
} finally {
|
|
|
|
super.finalize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private native void jni_YGConfigSetExperimentalFeatureEnabled(
|
|
|
|
long nativePointer,
|
|
|
|
int feature,
|
|
|
|
boolean enabled);
|
|
|
|
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
|
|
|
|
jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
|
|
|
|
}
|
2017-03-29 03:06:17 -07:00
|
|
|
|
|
|
|
private native void jni_YGConfigSetUseWebDefaults(long nativePointer, boolean useWebDefaults);
|
|
|
|
public void setUseWebDefaults(boolean useWebDefaults) {
|
|
|
|
jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
|
|
|
|
}
|
2017-04-26 12:20:02 -07:00
|
|
|
|
|
|
|
private native void jni_YGConfigSetPointScaleFactor(long nativePointer, float pixelsInPoint);
|
|
|
|
public void setPointScaleFactor(float pixelsInPoint) {
|
|
|
|
jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
|
|
|
|
}
|
2017-04-28 06:13:51 -07:00
|
|
|
|
|
|
|
private native void jni_YGConfigSetUseLegacyStretchBehaviour(long nativePointer, boolean useLegacyStretchBehaviour);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
|
|
|
}
|
2017-05-03 09:22:35 -07:00
|
|
|
|
2018-03-14 08:37:55 -07:00
|
|
|
private native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
|
|
|
long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
|
|
|
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
|
|
|
}
|
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
private native void jni_YGConfigSetLogger(long nativePointer, Object logger);
|
|
|
|
public void setLogger(YogaLogger logger) {
|
|
|
|
mLogger = logger;
|
|
|
|
jni_YGConfigSetLogger(mNativePointer, logger);
|
|
|
|
}
|
|
|
|
|
|
|
|
public YogaLogger getLogger() {
|
|
|
|
return mLogger;
|
|
|
|
}
|
2018-02-14 09:31:10 -08:00
|
|
|
|
|
|
|
private native void jni_YGConfigSetHasNodeClonedFunc(long nativePointer, boolean hasClonedFunc);
|
|
|
|
|
|
|
|
public void setOnNodeCloned(YogaNodeClonedFunction nodeClonedFunction) {
|
|
|
|
mNodeClonedFunction = nodeClonedFunction;
|
|
|
|
jni_YGConfigSetHasNodeClonedFunc(mNativePointer, nodeClonedFunction != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@DoNotStrip
|
|
|
|
public final void onNodeCloned(
|
|
|
|
YogaNode oldNode, YogaNode newNode, YogaNode parent, int childIndex) {
|
|
|
|
mNodeClonedFunction.onNodeCloned(oldNode, newNode, parent, childIndex);
|
|
|
|
}
|
2017-03-01 09:19:55 -08:00
|
|
|
}
|