From a0691e440306ae9505dbd2acfec1522a71062086 Mon Sep 17 00:00:00 2001 From: Alfonso Curbelo Date: Thu, 22 Sep 2022 09:55:55 -0400 Subject: [PATCH] Adding more comments --- .../RNDateTimePicker/ComponentDescriptors.h | 6 ++---- .../RNDateTimePickerState.cpp | 5 +++++ .../RNDateTimePicker/RNDateTimePickerState.h | 5 +++++ .../RNDateTimePicker/ShadowNodes.cpp | 6 ++---- .../components/RNDateTimePicker/ShadowNodes.h | 6 ++---- ios/fabric/RNDateTimePickerComponentView.h | 4 ++++ ios/fabric/RNDateTimePickerComponentView.mm | 19 ++++++++++++++++++- 7 files changed, 38 insertions(+), 13 deletions(-) diff --git a/cpp/react/renderer/components/RNDateTimePicker/ComponentDescriptors.h b/cpp/react/renderer/components/RNDateTimePicker/ComponentDescriptors.h index 80e8c6e5..4a1a8e24 100644 --- a/cpp/react/renderer/components/RNDateTimePicker/ComponentDescriptors.h +++ b/cpp/react/renderer/components/RNDateTimePicker/ComponentDescriptors.h @@ -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 */ diff --git a/cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.cpp b/cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.cpp index e1cd3444..d5177a9e 100644 --- a/cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.cpp +++ b/cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.cpp @@ -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 { diff --git a/cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.h b/cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.h index 661da78c..6215e17b 100644 --- a/cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.h +++ b/cpp/react/renderer/components/RNDateTimePicker/RNDateTimePickerState.h @@ -1,3 +1,8 @@ +/** + * Custom state to store frameSize that the component descriptor will use to modify the + * shadow node layout. + */ + #pragma once #include diff --git a/cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.cpp b/cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.cpp index da16aad1..192850e3 100644 --- a/cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.cpp +++ b/cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.cpp @@ -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 */ diff --git a/cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.h b/cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.h index 4b176437..dd2b6efc 100644 --- a/cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.h +++ b/cpp/react/renderer/components/RNDateTimePicker/ShadowNodes.h @@ -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 */ diff --git a/ios/fabric/RNDateTimePickerComponentView.h b/ios/fabric/RNDateTimePickerComponentView.h index 9b54089e..738a97d3 100644 --- a/ios/fabric/RNDateTimePickerComponentView.h +++ b/ios/fabric/RNDateTimePickerComponentView.h @@ -1,3 +1,7 @@ +/** + * RNDateTimePickerComponentView is only be available when fabric is enabled. + */ + #import NS_ASSUME_NONNULL_BEGIN diff --git a/ios/fabric/RNDateTimePickerComponentView.mm b/ios/fabric/RNDateTimePickerComponentView.mm index 91ed8072..81045c1a 100644 --- a/ios/fabric/RNDateTimePickerComponentView.mm +++ b/ios/fabric/RNDateTimePickerComponentView.mm @@ -1,3 +1,7 @@ +/** + * RNDateTimePickerComponentView is only be available when fabric is enabled. + */ + #import "RNDateTimePickerComponentView.h" #import @@ -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; @@ -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(state); @@ -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(_props); @@ -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) {