Skip to content

Commit 963ea83

Browse files
committed
Adding more comments
1 parent 8909520 commit 963ea83

File tree

8 files changed

+41
-15
lines changed

8 files changed

+41
-15
lines changed

cpp/react/renderer/components/RNDateTimePicker/ComponentDescriptors.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11

22
/**
33
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4-
*
5-
* Do not edit this file as changes may cause incorrect behavior and will be lost
6-
* once the code is regenerated.
7-
*
4+
* and copied to the cpp directory to override the adopt function and set the size of the shadow node based
5+
* on the state.
86
* @generated by codegen project: GenerateComponentDescriptorH.js
97
*/
108

cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Custom state to store frameSize that the component descriptor will use to modify the
3+
* shadow node layout.
4+
*/
5+
16
#include "RNDateTimePickerState.h"
27

38
namespace facebook {

cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Custom state to store frameSize that the component descriptor will use to modify the
3+
* shadow node layout.
4+
*/
5+
16
#pragma once
27

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

cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

22
/**
3-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4-
*
5-
* Do not edit this file as changes may cause incorrect behavior and will be lost
6-
* once the code is regenerated.
3+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen)
4+
* and copied to the cpp directory to add custom state and set shadow node trait as a LeafYogaNode.
75
*
86
* @generated by codegen project: GenerateShadowNodeCpp.js
97
*/

cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

22
/**
3-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4-
*
5-
* Do not edit this file as changes may cause incorrect behavior and will be lost
6-
* once the code is regenerated.
3+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen)
4+
* and copied to the cpp directory to add custom state and set shadow node trait as a LeafYogaNode.
75
*
86
* @generated by codegen project: GenerateShadowNodeH.js
97
*/

example/ios/Podfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
require_relative '../../node_modules/react-native-test-app/test_app'
22

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

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

ios/fabric/RNDateTimePickerComponentView.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* RNDateTimePickerComponentView is only be available when fabric is enabled.
3+
*/
4+
15
#import <React/RCTViewComponentView.h>
26

37
NS_ASSUME_NONNULL_BEGIN

ios/fabric/RNDateTimePickerComponentView.mm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* RNDateTimePickerComponentView is only be available when fabric is enabled.
3+
*/
4+
15
#import "RNDateTimePickerComponentView.h"
26
#import <React/RCTConversions.h>
37

@@ -64,6 +68,10 @@ -(void)onChange:(RNDateTimePicker *)sender
6468
->onChange(event);
6569
}
6670

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

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

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

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

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

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

238255
if (needsToUpdateMeasurements) {

0 commit comments

Comments
 (0)