Skip to content

Commit 3357873

Browse files
committed
Using CPP map instead of string
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”;"
1 parent 41173cb commit 3357873

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

Libraries/Components/View/ViewAccessibility.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export type AccessibilityState = {
159159
};
160160

161161
export type AccessibilityUnit = {
162-
hours?: number,
162+
hours?: string,
163163
};
164164

165165
export type AccessibilityValue = $ReadOnly<{|

ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.text.StaticLayout;
2020
import android.text.TextPaint;
2121
import android.util.LayoutDirection;
22+
import android.util.Log;
2223
import android.util.LruCache;
2324
import android.view.View;
2425
import androidx.annotation.NonNull;

ReactCommon/react/renderer/components/view/AccessibilityPrimitives.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ constexpr bool operator!=(
8989
}
9090

9191
struct AccessibilityUnit {
92-
std::optional<std::string> hours;
92+
std::string hours{""};
9393
};
9494

9595
constexpr bool operator==(

ReactCommon/react/renderer/components/view/AccessibilityProps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AccessibilityProps {
3939

4040
bool accessible{false};
4141
AccessibilityState accessibilityState;
42-
std::string accessibilityUnit{""};
42+
AccessibilityUnit accessibilityUnit;
4343
std::string accessibilityLabel{""};
4444
AccessibilityLabelledBy accessibilityLabelledBy{};
4545
AccessibilityLiveRegion accessibilityLiveRegion{

ReactCommon/react/renderer/components/view/AccessibilityPropsMapBuffer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ constexpr MapBuffer::Key ACCESSIBILITY_STATE_DISABLED = 1;
4646
constexpr MapBuffer::Key ACCESSIBILITY_STATE_EXPANDED = 2;
4747
constexpr MapBuffer::Key ACCESSIBILITY_STATE_SELECTED = 3;
4848
constexpr MapBuffer::Key ACCESSIBILITY_STATE_CHECKED = 4;
49-
constexpr MapBuffer::Key ACCESSIBILITY_UNIT_HOURS = 5;
5049

5150
MapBuffer convertAccessibilityState(AccessibilityState const &state) {
5251
MapBufferBuilder builder(5);
@@ -73,9 +72,10 @@ MapBuffer convertAccessibilityState(AccessibilityState const &state) {
7372
return builder.build();
7473
}
7574

76-
MapBuffer convertAccessibilityUnit(AccessibilityUnit const &state) {
75+
constexpr MapBuffer::Key ACCESSIBILITY_UNIT_HOURS = 0;
76+
MapBuffer convertAccessibilityUnit(AccessibilityUnit const &unit) {
7777
MapBufferBuilder builder(1);
78-
builder.putString(ACCESSIBILITY_UNIT_HOURS, "10");
78+
builder.putString(ACCESSIBILITY_UNIT_HOURS, unit.hours);
7979
return builder.build();
8080
}
8181

@@ -141,9 +141,9 @@ void AccessibilityProps::propsDiffMapBuffer(
141141
}
142142

143143
if (oldProps.accessibilityUnit != newProps.accessibilityUnit) {
144-
builder.putString(
144+
builder.putMapBuffer(
145145
AP_ACCESSIBILITY_UNIT,
146-
"10");
146+
convertAccessibilityUnit(newProps.accessibilityUnit));
147147
}
148148

149149
if (oldProps.accessibilityValue != newProps.accessibilityValue) {

ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,26 @@ inline void fromRawValue(
170170
}
171171
}
172172

173+
inline void fromRawValue(
174+
const PropsParserContext &context,
175+
const RawValue &value,
176+
AccessibilityUnit &result) {
177+
auto map = (butter::map<std::string, RawValue>)value;
178+
/*
179+
auto hours = map.find("hours");
180+
if (hours != map.end()) {
181+
// This probably calls toString()
182+
fromRawValue(context, hours->second, result.hours);
183+
}
184+
*/
185+
if (value.hasType<std::string>()) {
186+
auto string = "10";
187+
result.hours = string;
188+
} else {
189+
LOG(ERROR) << "Can not set type string for AccessibilityUnit field hours";
190+
}
191+
}
192+
173193
inline std::string toString(
174194
const ImportantForAccessibility &importantForAccessibility) {
175195
switch (importantForAccessibility) {

0 commit comments

Comments
 (0)