mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 22:37:14 +08:00
Small changes to State objects to support Android
Summary: Small changes to State objects to support Android. See following diffs. Reviewed By: mdvacca Differential Revision: D14663470 fbshipit-source-id: 878f4dc39265991a7b8ff54ca80bdb862f1dd3de
This commit is contained in:
committed by
Facebook Github Bot
parent
5d0d50cc44
commit
1592acd4a9
@@ -27,6 +27,8 @@ class ConcreteState : public State {
|
||||
using Shared = std::shared_ptr<const ConcreteState>;
|
||||
using Data = DataT;
|
||||
|
||||
virtual ~ConcreteState() = default;
|
||||
|
||||
ConcreteState(Data &&data, StateCoordinator::Shared stateCoordinator)
|
||||
: State(std::move(stateCoordinator)), data_(std::move(data)) {}
|
||||
|
||||
@@ -80,6 +82,15 @@ class ConcreteState : public State {
|
||||
priority);
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
const folly::dynamic getDynamic() const override {
|
||||
return data_.getDynamic();
|
||||
}
|
||||
void updateState(folly::dynamic data) const override {
|
||||
updateState(std::move(Data(data)));
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
DataT data_;
|
||||
};
|
||||
|
||||
@@ -7,11 +7,16 @@
|
||||
|
||||
#include "State.h"
|
||||
|
||||
#include <glog/logging.h>
|
||||
#include <react/core/ShadowNode.h>
|
||||
#include <react/core/State.h>
|
||||
#include <react/core/StateTarget.h>
|
||||
#include <react/core/StateUpdate.h>
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <folly/dynamic.h>
|
||||
#endif
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
@@ -26,5 +31,19 @@ const State::Shared &State::getCommitedState() const {
|
||||
return stateCoordinator_->getTarget().getShadowNode().getState();
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
const folly::dynamic State::getDynamic() const {
|
||||
LOG(FATAL)
|
||||
<< "State::getDynamic should never be called (some virtual method of a concrete implementation should be called instead)";
|
||||
abort();
|
||||
return folly::dynamic::object();
|
||||
}
|
||||
void State::updateState(folly::dynamic data) const {
|
||||
LOG(FATAL)
|
||||
<< "State::updateState should never be called (some virtual method of a concrete implementation should be called instead).";
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <folly/dynamic.h>
|
||||
#include <react/core/StateCoordinator.h>
|
||||
|
||||
namespace facebook {
|
||||
@@ -26,6 +27,11 @@ class State {
|
||||
State(StateCoordinator::Shared stateCoordinator);
|
||||
virtual ~State() = default;
|
||||
|
||||
#ifdef ANDROID
|
||||
virtual const folly::dynamic getDynamic() const;
|
||||
virtual void updateState(folly::dynamic data) const;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
StateCoordinator::Shared stateCoordinator_;
|
||||
|
||||
|
||||
30
ReactCommon/fabric/core/state/StateData.cpp
Normal file
30
ReactCommon/fabric/core/state/StateData.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "StateData.h"
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <folly/dynamic.h>
|
||||
#endif
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
#ifdef ANDROID
|
||||
StateData::~StateData() {
|
||||
// This needs to be here or the linker will complain:
|
||||
// https://gcc.gnu.org/wiki/VerboseDiagnostics#missing_vtable
|
||||
}
|
||||
const folly::dynamic StateData::getDynamic() const {
|
||||
assert(false); // TODO: get rid of this?
|
||||
return folly::dynamic::object();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -9,15 +9,32 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <folly/dynamic.h>
|
||||
#endif
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/*
|
||||
* Dummy type that is used as a placeholder for state data for nodes that
|
||||
* don't have a state.
|
||||
* Base class for state data.
|
||||
* Must be used to provide getDynamic for Android.
|
||||
*/
|
||||
struct StateData {
|
||||
class StateData {
|
||||
public:
|
||||
using Shared = std::shared_ptr<void>;
|
||||
|
||||
StateData() {}
|
||||
|
||||
#ifdef ANDROID
|
||||
StateData(folly::dynamic data) {}
|
||||
|
||||
// Destructor must either be virtual or protected if we have any
|
||||
// virtual methods
|
||||
virtual ~StateData();
|
||||
|
||||
virtual const folly::dynamic getDynamic() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
||||
Reference in New Issue
Block a user