moved PtrJNode map to YGJtypes.h and passing layout context as data in LayoutPassEnd Event
Summary: Move PtrJNodeMap to header file so that it can be accessed in events subscribers outside yoga Reviewed By: davidaurelio Differential Revision: D15602627 fbshipit-source-id: bb5bd5bbf8dcb279f5f87a4fd7287909d4e895d8
This commit is contained in:
committed by
Facebook Github Bot
parent
195c166efe
commit
8b17459254
@@ -75,34 +75,6 @@ const short int LAYOUT_BORDER_START_INDEX = 14;
|
|||||||
|
|
||||||
bool useBatchingForLayoutOutputs;
|
bool useBatchingForLayoutOutputs;
|
||||||
|
|
||||||
class PtrJNodeMap {
|
|
||||||
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
|
|
||||||
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
|
||||||
alias_ref<JNodeArray> javaNodes_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
PtrJNodeMap() : ptrsToIdxs_{}, javaNodes_{} {}
|
|
||||||
PtrJNodeMap(
|
|
||||||
alias_ref<JArrayLong> nativePointers,
|
|
||||||
alias_ref<JNodeArray> javaNodes)
|
|
||||||
: javaNodes_{javaNodes} {
|
|
||||||
auto pin = nativePointers->pinCritical();
|
|
||||||
auto ptrs = pin.get();
|
|
||||||
for (size_t i = 0, n = pin.size(); i < n; ++i) {
|
|
||||||
ptrsToIdxs_[(YGNodeRef) ptrs[i]] = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local_ref<JYogaNode> ref(YGNodeRef node) {
|
|
||||||
auto idx = ptrsToIdxs_.find(node);
|
|
||||||
if (idx == ptrsToIdxs_.end()) {
|
|
||||||
return local_ref<JYogaNode>{};
|
|
||||||
} else {
|
|
||||||
return javaNodes_->getElement(idx->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
union YGNodeContext {
|
union YGNodeContext {
|
||||||
|
@@ -6,6 +6,11 @@
|
|||||||
*/
|
*/
|
||||||
#include <fb/fbjni.h>
|
#include <fb/fbjni.h>
|
||||||
#include <yoga/YGValue.h>
|
#include <yoga/YGValue.h>
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
using namespace facebook::jni;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
|
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
|
||||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNIBase;";
|
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNIBase;";
|
||||||
@@ -28,3 +33,31 @@ struct JYogaLogger : public facebook::jni::JavaClass<JYogaLogger> {
|
|||||||
facebook::jni::alias_ref<JYogaLogLevel>,
|
facebook::jni::alias_ref<JYogaLogLevel>,
|
||||||
jstring);
|
jstring);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PtrJNodeMap {
|
||||||
|
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
|
||||||
|
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
||||||
|
alias_ref<JNodeArray> javaNodes_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PtrJNodeMap() : ptrsToIdxs_{}, javaNodes_{} {}
|
||||||
|
PtrJNodeMap(
|
||||||
|
alias_ref<JArrayLong> nativePointers,
|
||||||
|
alias_ref<JNodeArray> javaNodes)
|
||||||
|
: javaNodes_{javaNodes} {
|
||||||
|
auto pin = nativePointers->pinCritical();
|
||||||
|
auto ptrs = pin.get();
|
||||||
|
for (size_t i = 0, n = pin.size(); i < n; ++i) {
|
||||||
|
ptrsToIdxs_[(YGNodeRef) ptrs[i]] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local_ref<JYogaNode> ref(YGNodeRef node) {
|
||||||
|
auto idx = ptrsToIdxs_.find(node);
|
||||||
|
if (idx == ptrsToIdxs_.end()) {
|
||||||
|
return local_ref<JYogaNode>{};
|
||||||
|
} else {
|
||||||
|
return javaNodes_->getElement(idx->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@@ -4093,7 +4093,7 @@ void YGNodeCalculateLayoutWithContext(
|
|||||||
marker = nullptr;
|
marker = nullptr;
|
||||||
|
|
||||||
#ifdef YG_ENABLE_EVENTS
|
#ifdef YG_ENABLE_EVENTS
|
||||||
Event::publish<Event::LayoutPassEnd>(node);
|
Event::publish<Event::LayoutPassEnd>(node, {layoutContext});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we
|
// We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we
|
||||||
|
@@ -71,5 +71,10 @@ struct Event::TypedData<Event::NodeDeallocation> {
|
|||||||
YGConfig* config;
|
YGConfig* config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Event::TypedData<Event::LayoutPassEnd> {
|
||||||
|
void* layoutContext;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace yoga
|
} // namespace yoga
|
||||||
} // namespace facebook
|
} // namespace facebook
|
||||||
|
Reference in New Issue
Block a user