Skip to content

Commit

Permalink
Sending picker size to shadow node
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsocj-cb committed Sep 21, 2022
1 parent 081cf8f commit 2fd7c95
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 41 deletions.
9 changes: 8 additions & 1 deletion RNDateTimePicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |s|
s.homepage = package['homepage']
s.platform = :ios, "11.0"
s.source = { :git => "https://github.com/react-native-community/datetimepicker", :tag => "v#{s.version}" }
s.source_files = "ios/**/*.{h,m,mm}"
s.source_files = "ios/**/*.{h,m,mm,cpp}"
s.requires_arc = true

if fabric_enabled
Expand All @@ -33,6 +33,13 @@ Pod::Spec.new do |s|
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"

s.subspec "cpp" do |ss|
ss.source_files = "cpp/**/*.{cpp,h}"
ss.header_dir = "rndatetimepicker"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/cpp\"" }
end

else
s.exclude_files = "ios/fabric"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateComponentDescriptorH.js
*/

#pragma once

#include "ShadowNodes.h"
#include <react/renderer/core/ConcreteComponentDescriptor.h>

namespace facebook {
namespace react {

class RNDateTimePickerComponentDescriptor final : public ConcreteComponentDescriptor<RNDateTimePickerShadowNode> {
public:
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;

void adopt(ShadowNode::Unshared const &shadowNode) const override {
react_native_assert(std::dynamic_pointer_cast<RNDateTimePickerShadowNode>(shadowNode));
auto pickerShadowNode = std::static_pointer_cast<RNDateTimePickerShadowNode>(shadowNode);

react_native_assert(
std::dynamic_pointer_cast<YogaLayoutableShadowNode>(pickerShadowNode));
auto layoutableShadowNode =
std::static_pointer_cast<YogaLayoutableShadowNode>(pickerShadowNode);

auto state = std::static_pointer_cast<const RNDateTimePickerShadowNode::ConcreteState>(shadowNode->getState());
auto stateData = state->getData();

if(stateData.frameSize.width != 0 && stateData.frameSize.height != 0) {
layoutableShadowNode->setSize(Size{stateData.frameSize.width, stateData.frameSize.height});
}

ConcreteComponentDescriptor::adopt(shadowNode);
}
};

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "RNDateTimePickerState.h"

namespace facebook {
namespace react {

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <react/renderer/graphics/Geometry.h>

namespace facebook {
namespace react {

class RNDateTimePickerState final {
public:
using Shared = std::shared_ptr<const RNDateTimePickerState>;
RNDateTimePickerState(){};
RNDateTimePickerState(Size frameSize_) : frameSize(frameSize_){};

Size frameSize{};
};

} // namespace react
} // namespace facebook
19 changes: 19 additions & 0 deletions cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateShadowNodeCpp.js
*/

#include "ShadowNodes.h"

namespace facebook {
namespace react {

extern const char RNDateTimePickerComponentName[] = "RNDateTimePicker";

} // namespace react
} // namespace facebook
41 changes: 41 additions & 0 deletions cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateShadowNodeH.js
*/

#pragma once

#include "RNDateTimePickerState.h"
#include <react/renderer/components/RNDAteTimePicker/EventEmitters.h>
#include <react/renderer/components/RNDateTimePicker/Props.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
#include <react/renderer/core/LayoutContext.h>

namespace facebook {
namespace react {

JSI_EXPORT extern const char RNDateTimePickerComponentName[];

/*
* `ShadowNode` for <RNDateTimePicker> component.
*/
class JSI_EXPORT RNDateTimePickerShadowNode final : public ConcreteViewShadowNode<RNDateTimePickerComponentName, RNDateTimePickerProps, RNDateTimePickerEventEmitter, RNDateTimePickerState> {

public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;

static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
return traits;
}
};

} // namespace react
} // namespace facebook
Loading

0 comments on commit 2fd7c95

Please sign in to comment.