Skip to content

Commit

Permalink
Adding more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsocj-cb committed Sep 22, 2022
1 parent 8909520 commit 963ea83
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

/**
* 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.
*
* and copied to the cpp directory to override the adopt function and set the size of the shadow node based
* on the state.
* @generated by codegen project: GenerateComponentDescriptorH.js
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Custom state to store frameSize that the component descriptor will use to modify the
* shadow node layout.
*/

#include "RNDateTimePickerState.h"

namespace facebook {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Custom state to store frameSize that the component descriptor will use to modify the
* shadow node layout.
*/

#pragma once

#include <react/renderer/graphics/Geometry.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/**
* 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.
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen)
* and copied to the cpp directory to add custom state and set shadow node trait as a LeafYogaNode.
*
* @generated by codegen project: GenerateShadowNodeCpp.js
*/
Expand Down
6 changes: 2 additions & 4 deletions cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/**
* 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.
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen)
* and copied to the cpp directory to add custom state and set shadow node trait as a LeafYogaNode.
*
* @generated by codegen project: GenerateShadowNodeH.js
*/
Expand Down
5 changes: 3 additions & 2 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require_relative '../../node_modules/react-native-test-app/test_app'

# Disabling flipper to prevent this issue https://github.com/facebook/react-native/issues/33764
use_flipper!(false)
# Flipper causes the build to fail on release when fabric is enabled
# https://github.com/facebook/react-native/issues/33764
use_flipper!()

workspace 'date-time-picker-example.xcworkspace'

Expand Down
4 changes: 4 additions & 0 deletions ios/fabric/RNDateTimePickerComponentView.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* RNDateTimePickerComponentView is only be available when fabric is enabled.
*/

#import <React/RCTViewComponentView.h>

NS_ASSUME_NONNULL_BEGIN
Expand Down
19 changes: 18 additions & 1 deletion ios/fabric/RNDateTimePickerComponentView.mm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* RNDateTimePickerComponentView is only be available when fabric is enabled.
*/

#import "RNDateTimePickerComponentView.h"
#import <React/RCTConversions.h>

Expand Down Expand Up @@ -64,6 +68,10 @@ -(void)onChange:(RNDateTimePicker *)sender
->onChange(event);
}

/**
* Updates the shadow node state with the dummyPicker size. This will update the shadow node size.
* (see adopt method in ComponentDescriptors.h)
*/
- (void) updateMeasurements {
if (_state == nullptr) {
return;
Expand Down Expand Up @@ -109,6 +117,9 @@ -(void)updateTextColorForPicker:(UIDatePicker *)picker color:(UIColor *)color
[picker setValue:@(NO) forKey:@"highlightsToday"];
}

/**
* override update state to update shadow node size once the state is available
*/
- (void)updateState:(const State::Shared &)state oldState:(const State::Shared &)oldState {
_state = std::static_pointer_cast<const RNDateTimePickerShadowNode::ConcreteState>(state);

Expand All @@ -118,6 +129,12 @@ - (void)updateState:(const State::Shared &)state oldState:(const State::Shared &
}
}

/**
* Updates picker properties based on prop changes and returns a boolean that indicates if the shadow node size needs
* to be updated. This boolean helpful when we update the dummy picker to know if we need to update the shadow node
* size before updating the actual picker.
* Props that will to update measurements: date, locale, mode, displayIOS.
*/
- (Boolean)updatePropsForPicker:(UIDatePicker *)picker props:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {

const auto &oldPickerProps = *std::static_pointer_cast<const RNDateTimePickerProps>(_props);
Expand Down Expand Up @@ -232,7 +249,7 @@ - (Boolean)updatePropsForPicker:(UIDatePicker *)picker props:(Props::Shared cons

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
// Updating the dummy first to calculate measurements
// Updating the dummy first to check if we need to update measurements
Boolean needsToUpdateMeasurements = [self updatePropsForPicker:_dummyPicker props:props oldProps:oldProps];

if (needsToUpdateMeasurements) {
Expand Down

0 comments on commit 963ea83

Please sign in to comment.