Skip to content

Commit

Permalink
Using CPP map instead of string
Browse files Browse the repository at this point in the history
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”;"
  • Loading branch information
fabOnReact committed Nov 14, 2022
1 parent 41173cb commit 3357873
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Libraries/Components/View/ViewAccessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export type AccessibilityState = {
};

export type AccessibilityUnit = {
hours?: number,
hours?: string,
};

export type AccessibilityValue = $ReadOnly<{|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ constexpr bool operator!=(
}

struct AccessibilityUnit {
std::optional<std::string> hours;
std::string hours{""};
};

constexpr bool operator==(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AccessibilityProps {

bool accessible{false};
AccessibilityState accessibilityState;
std::string accessibilityUnit{""};
AccessibilityUnit accessibilityUnit;
std::string accessibilityLabel{""};
AccessibilityLabelledBy accessibilityLabelledBy{};
AccessibilityLiveRegion accessibilityLiveRegion{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ inline void fromRawValue(
}
}

inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
AccessibilityUnit &result) {
auto map = (butter::map<std::string, RawValue>)value;
/*
auto hours = map.find("hours");
if (hours != map.end()) {
// This probably calls toString()
fromRawValue(context, hours->second, result.hours);
}
*/
if (value.hasType<std::string>()) {
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) {
Expand Down

0 comments on commit 3357873

Please sign in to comment.