From 3357873f7100c00c9ef718f51cfaf0d788ebeafd Mon Sep 17 00:00:00 2001 From: fabriziobertoglio1987 Date: Mon, 14 Nov 2022 11:07:19 +0100 Subject: [PATCH] Using CPP map instead of string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Basic working setup to use CPP Map instead of basic string type Settings copied from accessibilityState (fromRawValue) and from importantForAccessibility (toString) the CPP convertRawProps will use two functions to convert the prop: - fromRawValue which takes as param the prop RawValue - toString or toBoolean, to*** which convert the RawValue to String/Boolean/Number The error was triggered for missing conversion from RawValue (AccessibilityUnit field hours) toString. (std::string) accessibilityUnit.hours would call toString(accessibilityUnit.hours) Tasks Details: Complete draft CPP accessibilityUnit settings:Commit the changes and pushAdd more clear log statements and further verify value passed to  accessibilityUnitLog the value passed from javascript in conversion.hAdd changes from PR #2Change logic in conversion.h to add the value passed from javascript -- Change the type from String to Hash in PR #3:Plan next tasksFind a prop that uses the Hash type (for ex accessibilityState)Start with a clear git statusCopy the CPP settings from accessibilityState Parse accessibilityUnit hours value to a string type. The value is already string, but in CPP is not mapped to string.importantForAccessibility uses 2 conversions, fromRawValue and toString. fromRawValue parses the props importantForAccessibility, while toString converts the value from IMPORTANT_FOR_ACCESSIBILITY to string.Follow the same implementation fromRawValue(IMPORTANT_FOR_ACCESSIBILITY), but avoid adding their toString(Important_For_Accessibility) conversion.Pass a static string auto hours = “10”; "Complete draft CPP accessibilityUnit settings: Commit the changes and push Add more clear log statements and further verify value passed to accessibilityUnit Log the value passed from javascript in conversion.h Add changes from PR [#2](https://github.com/fabriziobertoglio1987/react-native/pull/2/files) Change logic in conversion.h to add the value passed from javascript" "Change the type from String to Hash in PR [#3](https://github.com/fabriziobertoglio1987/react-native/pull/3/files): Plan next tasks Find a prop that uses the Hash type (for ex [accessibilityState](https://github.com/fabriziobertoglio1987/react-native/blob/41173cbeba53b26a3c838d16776daa8d10e57639/ReactCommon/react/renderer/components/view/AccessibilityProps.h#L41)) Start with a clear git status Copy the CPP settings from accessibilityState" "Parse accessibilityUnit hours value to a string type. The value is already string, but in CPP is not mapped to string.
[importantForAccessibility](https://github.com/fabriziobertoglio1987/react-native/blob/41173cbeba53b26a3c838d16776daa8d10e57639/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h#L173-L209) uses 2 conversions, fromRawValue and toString. fromRawValue parses the props importantForAccessibility, while toString converts the value from IMPORTANT_FOR_ACCESSIBILITY to string. Follow the same implementation [fromRawValue(IMPORTANT_FOR_ACCESSIBILITY)](https://github.com/fabriziobertoglio1987/react-native/blob/41173cbeba53b26a3c838d16776daa8d10e57639/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h#L193), but avoid adding their toString(Important_For_Accessibility) conversion.
Pass a static string auto hours = “10”;" --- .../Components/View/ViewAccessibility.js | 2 +- .../react/views/text/TextLayoutManager.java | 1 + .../components/view/AccessibilityPrimitives.h | 2 +- .../components/view/AccessibilityProps.h | 2 +- .../view/AccessibilityPropsMapBuffer.cpp | 10 +++++----- .../view/accessibilityPropsConversions.h | 20 +++++++++++++++++++ 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Libraries/Components/View/ViewAccessibility.js b/Libraries/Components/View/ViewAccessibility.js index 1cd11667db1286..8b69ad2995cfa6 100644 --- a/Libraries/Components/View/ViewAccessibility.js +++ b/Libraries/Components/View/ViewAccessibility.js @@ -159,7 +159,7 @@ export type AccessibilityState = { }; export type AccessibilityUnit = { - hours?: number, + hours?: string, }; export type AccessibilityValue = $ReadOnly<{| diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index c940dee9f6fc2d..761e16dbd0eb65 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -19,6 +19,7 @@ import android.text.StaticLayout; import android.text.TextPaint; import android.util.LayoutDirection; +import android.util.Log; import android.util.LruCache; import android.view.View; import androidx.annotation.NonNull; diff --git a/ReactCommon/react/renderer/components/view/AccessibilityPrimitives.h b/ReactCommon/react/renderer/components/view/AccessibilityPrimitives.h index 3fed2e90f9d168..c31e318f4c1fd1 100644 --- a/ReactCommon/react/renderer/components/view/AccessibilityPrimitives.h +++ b/ReactCommon/react/renderer/components/view/AccessibilityPrimitives.h @@ -89,7 +89,7 @@ constexpr bool operator!=( } struct AccessibilityUnit { - std::optional hours; + std::string hours{""}; }; constexpr bool operator==( diff --git a/ReactCommon/react/renderer/components/view/AccessibilityProps.h b/ReactCommon/react/renderer/components/view/AccessibilityProps.h index 7778ff4f2d6aed..387245325f24ab 100644 --- a/ReactCommon/react/renderer/components/view/AccessibilityProps.h +++ b/ReactCommon/react/renderer/components/view/AccessibilityProps.h @@ -39,7 +39,7 @@ class AccessibilityProps { bool accessible{false}; AccessibilityState accessibilityState; - std::string accessibilityUnit{""}; + AccessibilityUnit accessibilityUnit; std::string accessibilityLabel{""}; AccessibilityLabelledBy accessibilityLabelledBy{}; AccessibilityLiveRegion accessibilityLiveRegion{ diff --git a/ReactCommon/react/renderer/components/view/AccessibilityPropsMapBuffer.cpp b/ReactCommon/react/renderer/components/view/AccessibilityPropsMapBuffer.cpp index b6aa1f3faa7784..37046ad7ad0cca 100644 --- a/ReactCommon/react/renderer/components/view/AccessibilityPropsMapBuffer.cpp +++ b/ReactCommon/react/renderer/components/view/AccessibilityPropsMapBuffer.cpp @@ -46,7 +46,6 @@ constexpr MapBuffer::Key ACCESSIBILITY_STATE_DISABLED = 1; constexpr MapBuffer::Key ACCESSIBILITY_STATE_EXPANDED = 2; constexpr MapBuffer::Key ACCESSIBILITY_STATE_SELECTED = 3; constexpr MapBuffer::Key ACCESSIBILITY_STATE_CHECKED = 4; -constexpr MapBuffer::Key ACCESSIBILITY_UNIT_HOURS = 5; MapBuffer convertAccessibilityState(AccessibilityState const &state) { MapBufferBuilder builder(5); @@ -73,9 +72,10 @@ MapBuffer convertAccessibilityState(AccessibilityState const &state) { return builder.build(); } -MapBuffer convertAccessibilityUnit(AccessibilityUnit const &state) { +constexpr MapBuffer::Key ACCESSIBILITY_UNIT_HOURS = 0; +MapBuffer convertAccessibilityUnit(AccessibilityUnit const &unit) { MapBufferBuilder builder(1); - builder.putString(ACCESSIBILITY_UNIT_HOURS, "10"); + builder.putString(ACCESSIBILITY_UNIT_HOURS, unit.hours); return builder.build(); } @@ -141,9 +141,9 @@ void AccessibilityProps::propsDiffMapBuffer( } if (oldProps.accessibilityUnit != newProps.accessibilityUnit) { - builder.putString( + builder.putMapBuffer( AP_ACCESSIBILITY_UNIT, - "10"); + convertAccessibilityUnit(newProps.accessibilityUnit)); } if (oldProps.accessibilityValue != newProps.accessibilityValue) { diff --git a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h index 6659e9d7104db3..195b65563686ef 100644 --- a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h +++ b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h @@ -170,6 +170,26 @@ inline void fromRawValue( } } +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + AccessibilityUnit &result) { + auto map = (butter::map)value; + /* + auto hours = map.find("hours"); + if (hours != map.end()) { + // This probably calls toString() + fromRawValue(context, hours->second, result.hours); + } + */ + if (value.hasType()) { + auto string = "10"; + result.hours = string; + } else { + LOG(ERROR) << "Can not set type string for AccessibilityUnit field hours"; + } +} + inline std::string toString( const ImportantForAccessibility &importantForAccessibility) { switch (importantForAccessibility) {