Expose methods of persistent yoga for Java

Summary: This diff extends the JNI version of yoga in order to allow Java instances of the YogaConfig class to receive a callback when a Yoga node is cloned.

Reviewed By: priteshrnandgaonkar

Differential Revision: D6918605

fbshipit-source-id: e424c78680c04e21154ebe21405671c4e90f6529
This commit is contained in:
David Vacca
2018-02-14 09:31:10 -08:00
committed by Facebook Github Bot
parent 3ec41b656f
commit b1222bf83e
4 changed files with 153 additions and 13 deletions

View File

@@ -23,6 +23,7 @@ public class YogaConfig {
long mNativePointer;
private YogaLogger mLogger;
private YogaNodeClonedFunction mNodeClonedFunction;
private native long jni_YGConfigNew();
public YogaConfig() {
@@ -80,4 +81,17 @@ public class YogaConfig {
public YogaLogger getLogger() {
return mLogger;
}
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);
}
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public interface YogaNodeClonedFunction {
@DoNotStrip
void onNodeCloned(YogaNode oldNode, YogaNode newNode, YogaNode parent, int childIndex);
}