Files
yoga/yoga/event/event.h
Sidharth Guglani a130ac2f9c pass measure callback data from c++ to java
Summary:
Passing Measure callback data - width, widthMeasureMode, height, heightMeasureMode, measuredWidth and measuredHeight along with NodeMeasure event
This data is then propagated to java layer in this diff

Reviewed By: davidaurelio

Differential Revision: D15697523

fbshipit-source-id: 615463da237175ff88abef3f6528b55333ccd915
2019-06-12 00:33:31 -07:00

105 lines
2.0 KiB
C++

/*
* 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.
*/
#pragma once
#include <functional>
#include <vector>
#include "../YGEnums.h"
struct YGConfig;
struct YGNode;
namespace facebook {
namespace yoga {
struct Event {
enum Type {
NodeAllocation,
NodeDeallocation,
NodeLayout,
LayoutPassStart,
LayoutPassEnd,
NodeMeasure,
};
class Data;
using Subscriber = void(const YGNode&, Type, Data);
using Subscribers = std::vector<std::function<Subscriber>>;
template <Type E>
struct TypedData {};
class Data {
const void* data_;
public:
template <Type E>
Data(const TypedData<E>& data) : data_{&data} {}
template <Type E>
const TypedData<E>& get() const {
return *static_cast<const TypedData<E>*>(data_);
};
};
static void reset();
static void subscribe(std::function<Subscriber>&& subscriber);
template <Type E>
static void publish(const YGNode& node, const TypedData<E>& eventData = {}) {
publish(node, E, Data{eventData});
}
template <Type E>
static void publish(const YGNode* node, const TypedData<E>& eventData = {}) {
publish<E>(*node, eventData);
}
private:
static void publish(const YGNode&, Type, const Data&);
};
template <>
struct Event::TypedData<Event::NodeAllocation> {
YGConfig* config;
};
template <>
struct Event::TypedData<Event::NodeDeallocation> {
YGConfig* config;
};
template <>
struct Event::TypedData<Event::LayoutPassStart> {
void* layoutContext;
};
template <>
struct Event::TypedData<Event::LayoutPassEnd> {
void* layoutContext;
};
template <>
struct Event::TypedData<Event::NodeMeasure> {
void* layoutContext;
float width;
YGMeasureMode widthMeasureMode;
float height;
YGMeasureMode heightMeasureMode;
float measuredWidth;
float measuredHeight;
};
template <>
struct Event::TypedData<Event::NodeLayout> {
bool performLayout;
void* layoutContext;
};
} // namespace yoga
} // namespace facebook