Files
react-native/ReactCommon/fabric/components/switch/androidswitch/AndroidSwitchComponentDescriptor.h
T
Oleksandr Melnykov d0dd1aed29 Integrate AndroidSwitch into Fabric on Android
Summary:
In this diff we integrate the Switch component on Android in Fabric. Since the component has a custom measure function, we need to write some C++ to call the measure method in Java.

The component isn't fully functional yet (setNativeProps isn't supported in Fabric) and has some problems with measuring itself. I will fix the component in the next diffs in this stack.

Reviewed By: JoshuaGross

Differential Revision: D17571258

fbshipit-source-id: be4e201495b9b197ddec44ee3484357bfb6225a8
2019-10-03 03:15:20 -07:00

54 lines
1.6 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 "AndroidSwitchMeasurementsManager.h"
#include "AndroidSwitchShadowNode.h"
#include <react/core/ConcreteComponentDescriptor.h>
namespace facebook {
namespace react {
/*
* Descriptor for <AndroidSwitch> component.
*/
class AndroidSwitchComponentDescriptor final
: public ConcreteComponentDescriptor<AndroidSwitchShadowNode> {
public:
AndroidSwitchComponentDescriptor(
EventDispatcher::Weak eventDispatcher,
ContextContainer::Shared const &contextContainer)
: ConcreteComponentDescriptor(eventDispatcher),
measurementsManager_(std::make_shared<AndroidSwitchMeasurementsManager>(
contextContainer)) {}
void adopt(UnsharedShadowNode shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode);
assert(std::dynamic_pointer_cast<AndroidSwitchShadowNode>(shadowNode));
auto androidSwitchShadowNode =
std::static_pointer_cast<AndroidSwitchShadowNode>(shadowNode);
// `AndroidSwitchShadowNode` uses `AndroidSwitchMeasurementsManager` to
// provide measurements to Yoga.
androidSwitchShadowNode->setAndroidSwitchMeasurementsManager(
measurementsManager_);
// All `AndroidSwitchShadowNode`s must have leaf Yoga nodes with properly
// setup measure function.
androidSwitchShadowNode->enableMeasurement();
}
private:
const std::shared_ptr<AndroidSwitchMeasurementsManager> measurementsManager_;
};
} // namespace react
} // namespace facebook