Files
react-native/ReactCommon/react/renderer/core/State.h
T
David Vacca 91b3f5d48a Implement and integrate Mapbuffer
Summary:
This diff contains the code from the 35 diff stack  - D27210587

This diff implement and integrates Mapbuffer into Fabric text measure system

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D27241836

fbshipit-source-id: f40a780df0723f27da440f709a8676cfcca63953
2021-03-24 03:52:31 -07:00

115 lines
3.0 KiB
C++
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 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
#ifdef ANDROID
#include <folly/dynamic.h>
#include <react/renderer/mapbuffer/MapBuffer.h>
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
#endif
#include <react/renderer/core/ShadowNodeFamily.h>
namespace facebook {
namespace react {
/*
* An abstract interface of State.
* State is used to control and continuously advance a single vision of some
* state (arbitrary data) associated with a family of shadow nodes.
*/
class State {
public:
using Shared = std::shared_ptr<const State>;
static size_t constexpr initialRevisionValue = 1;
protected:
/*
* Constructors are protected to make calling them directly with
* type-erasured arguments impossible.
*/
explicit State(StateData::Shared const &data, State const &state);
explicit State(
StateData::Shared const &data,
ShadowNodeFamily::Shared const &family);
public:
virtual ~State() = default;
/*
  * Returns a momentary value of the most recently committed state
  * associated with a family of nodes which this state belongs to.
  * Sequential calls might return different values.
*/
State::Shared getMostRecentState() const;
/*
* Returns the most recent state (same as `getMostRecentState()` method)
* if this state is obsolete, otherwise returns `nullptr`.
*/
State::Shared getMostRecentStateIfObsolete() const;
/*
* Returns a revision number of the `State` object.
* The number is being automatically assigned during the creation of `State`
* objects.
* Revision `0` represents a case when we don't have any info about state
* object (actual State instances cannot have it).
* Revision `1` represents a newly created initial state object.
*/
size_t getRevision() const;
#ifdef ANDROID
virtual folly::dynamic getDynamic() const = 0;
virtual MapBuffer getMapBuffer() const = 0;
virtual void updateState(folly::dynamic data) const = 0;
#endif
protected:
friend class ShadowNodeFamily;
friend class UIManager;
/*
* Returns a shared pointer to data.
* To be used by `UIManager` only.
*/
StateData::Shared const &getDataPointer() const {
return data_;
}
/*
* A family of a node with this state is associated.
* Must be a weak pointer to avoid retain cycle among `State`, `ShadowNode`,
* and `ShadowNodeFamily` instances.
*/
ShadowNodeFamily::Weak family_;
/*
* Type-erasured pointer to arbitrary component-specific data held by the
* `State`.
*/
StateData::Shared data_;
/*
* Indicates that the state was committed once and then was replaced by a
* newer one.
* To be used by `StateCoordinator` only.
* Protected by mutex inside `StateCoordinator`.
*/
mutable bool isObsolete_{false};
/*
* Revision of the State object.
*/
size_t revision_;
};
} // namespace react
} // namespace facebook