-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1/n Adding Android support for Accessibility TtsSpan API - Support for accessibilitySpan and accessibilityLabel props in nested Text #35130
Closed
Closed
Changes from 64 commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
216a30a
draft solution partially spelling correctly
fabOnReact 48a01d0
correctly spelling a span text
fabOnReact 08d6f43
add span description
fabOnReact 145303e
remove code duplication
fabOnReact f66e914
remove code duplication
fabOnReact 3d4e662
draft java configs to trigger setAccessibilityUnit
fabOnReact 1653d6b
Merge branch 'main' into tts-span
fabOnReact 6def7a9
draft cpp configs - they trigger runtime
fabOnReact 7fa58f5
Fabric cpp settings trigger runtime error
fabOnReact 43e7c29
cpp mapbuffer configs before rebase
fabOnReact 0afdc69
Merge branch 'main' into tts-span
fabOnReact 0cd0ac4
avoid using key from other props
fabOnReact f5a3b49
avoid using key 24 and use key 99
fabOnReact 08fc9ac
remove log messages
fabOnReact c2adbb8
debug - change key number
fabOnReact 46c4fb8
Merge branch 'main' into tts-span
fabOnReact 45ec47f
custom conversion logic for accUnit as done with accRole
fabOnReact 0a00193
Merge branch 'main' into tts-span
fabOnReact 72ee5a1
remove accessibilityUnit prop from cpp
fabOnReact 81fe302
accessibilityRole verbatim correctly announces span text, but does no…
fabOnReact 7af9bd3
Remove logic for announcing nested text
fabOnReact 16f1f39
clean up not needed logic
fabOnReact d845073
removing not relevant logic
fabOnReact e215baa
adding TtsSpan with type date
fabOnReact 03a125c
refactoring logic parsing accRole to TtsSpan TYPES
fabOnReact fe5c480
TtsSpan works with parent Text component
fabOnReact 7e264da
adding TtsSpan to TextLayoutManager
fabOnReact d8823e5
removing not required logic
fabOnReact 9d4b8a5
update description
fabOnReact 7b85e25
adding all TtsSpan, no comp errors
fabOnReact aefa45f
accessibility TtsSpan examples
fabOnReact 95d6d3b
adding accessibility ttspan examples
fabOnReact 24c182a
manually patching the prefab-headers avoid the app from triggering a …
fabOnReact 7b4231f
Merge branch 'main' into tts-span
fabOnReact 4fbc54b
accessibilityUnit hours param Java test implementation
fabOnReact 29a8104
Merge branch 'main' into tts-span
fabOnReact e3fd7ff
clean up diff
fabOnReact 3e1d292
clean up diff
fabOnReact 8b23efd
Adding prop accessibilityUnit to TextAttributesProps (fabric) (#3)
fabOnReact bea5af9
code-review
fabOnReact 6fc18d4
fix circleci errors
fabOnReact 8b592f7
The ReactTtsSpan.Builder constructor expects a string and not an Acce…
fabOnReact f2642f6
adding type money support
fabOnReact c4cd23b
adding check on accessibilityUnit
fabOnReact 576bad6
improve logging
fabOnReact 958ae95
Test Buck fix circular dependency
fabOnReact 8a59592
adding final to Set
fabOnReact eb95e08
static interface method invocations are not supported in -source 7
fabOnReact 5aa9f74
error: static interface method invocations are not supported in -sour…
fabOnReact cb52ad9
refactor example
fabOnReact 60ef8f0
adding support for telephonegst
fabOnReact 06096d5
adding support for measure
fabOnReact cc45e04
simplify ReactTtsSpan API
fabOnReact 096019c
remove time warning
fabOnReact 7f4a0cd
adding back check on currency code
fabOnReact 0a42fd0
adding comments to prop
fabOnReact 79c4aed
remove comment
fabOnReact dfc4063
update TA_KEY_ACCESSIBILITY_UNIT value (code review)
fabOnReact 3b30659
adding static set SUPPORTED_TYPES_SET
fabOnReact fe4e1e0
introducing Set in ReactTtsSpan
fabOnReact ef9c59b
Merge branch 'main' into tts-span
fabOnReact ac79bae
update types cpp, objc typescript and js
fabOnReact 145db13
minor changes
fabOnReact a892b68
fix xcode warning
fabOnReact 61e5920
Merge branch 'main' into tts-span
fabOnReact f495025
adding role grid to ViewAccessibility.d.ts
fabOnReact 753858e
adding roles to Role typegst
fabOnReact 821a4c8
Merge branch 'main' into tts-span
fabOnReact 4988339
Merge branch 'main' into tts-span
fabOnReact 02af5a4
Merge branch 'main' into tts-span
fabOnReact dcb9f61
remove view prop (take 3)
fabOnReact e7cbd28
remove change from ViewAcc.d.ts
fabOnReact 565d7ed
adding accessibilitySpan prop
fabOnReact a1c7e0f
remove changes to accessibilityRole
fabOnReact f797c20
working solution migration to accessibilitySpan with AccSpan type
fabOnReact 8b90011
accSpan enum type
fabOnReact e830578
fix verbatim not working
fabOnReact 25b212e
adding cpp AccSpan type
fabOnReact c058657
adding more missing cpp configs
fabOnReact 151b37c
Verbatim and other strings are not announced.
fabOnReact 6f68513
adding type none to AccSpan
fabOnReact e1c56ac
android studio and circleci fixes
fabOnReact ecc815b
Use accessibilityLabel instead of accessibilityUnit.
fabOnReact 7c80bdb
removing changes to ReactAccDelegate
fabOnReact 34ed14e
Remove not supported TYPES from PR and move them to a separate branch
fabOnReact 23241dd
rename UNIT to LABEL
fabOnReact 112ed6f
Merge branch 'main' into tts-span
fabOnReact 235eda8
Review Android Studio and XCODE errors
fabOnReact d536cf7
update comments
fabOnReact c154196
update comments
fabOnReact 76ce49a
update check on accSpan and accLabel
fabOnReact File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTtsSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.views.text; | ||
|
||
import android.os.Parcel; | ||
import android.os.PersistableBundle; | ||
import android.text.style.TtsSpan; | ||
import com.facebook.common.logging.FLog; | ||
import com.facebook.react.uimanager.ReactAccessibilityDelegate.AccessibilityRole; | ||
import java.util.Arrays; | ||
import java.util.Currency; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import javax.annotation.Nullable; | ||
|
||
/* | ||
* Wraps {@link TtsSpan} as a {@link ReactSpan}. | ||
* A span that supplies additional meta-data for the associated text intended | ||
* for text-to-speech engines. If the text is being processed by a | ||
* text-to-speech engine, the engine may use the data in this span in addition | ||
* to or instead of its associated text. | ||
* | ||
* Each instance of a TtsSpan has a type, for example {@link #TYPE_DATE} | ||
* or {@link #TYPE_MEASURE}. And a list of arguments, provided as | ||
* key-value pairs in a bundle. | ||
* | ||
* The inner classes are there for convenience and provide builders for each | ||
* TtsSpan type. | ||
*/ | ||
public class ReactTtsSpan extends TtsSpan implements ReactSpan { | ||
private static final String TAG = ReactTtsSpan.class.getSimpleName(); | ||
private static final String TYPE_MONEY_WARNING_MSG = | ||
"The accessibilityUnit format may not be compatible" | ||
+ " with the format supported ISO 4217 (for example 'USD')."; | ||
private static final String TYPE_TELEPHONE_WARNING_MSG = | ||
"Failed to retrieve telephone number (for example '0112123432')."; | ||
private static final String TYPE_MEASURE_WARNING_MSG = | ||
"Failed to retrieve unit type (for ex. meter, second, milli)."; | ||
private static final String[] SUPPORTED_UNIT_VALUES = { | ||
TYPE_MEASURE, TYPE_TELEPHONE, TYPE_MONEY, | ||
}; | ||
|
||
private static final Set<String> SUPPORTED_UNIT_SET = | ||
new HashSet<String>(Arrays.asList(SUPPORTED_UNIT_VALUES)); | ||
|
||
public ReactTtsSpan(String type, PersistableBundle args) { | ||
super(type, args); | ||
} | ||
|
||
public ReactTtsSpan(Parcel src) { | ||
super(src); | ||
} | ||
|
||
public static class Builder<C extends Builder<?>> { | ||
private final String mType; | ||
private PersistableBundle mArgs = new PersistableBundle(); | ||
|
||
public Builder(String type) { | ||
mType = type; | ||
} | ||
fabOnReact marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public Builder(AccessibilityRole type, @Nullable String accessibilityUnit) { | ||
String typeConvertedToString = AccessibilityRole.getValue(type); | ||
mType = typeConvertedToString; | ||
String roleClassName = AccessibilityRole.getValue(type); | ||
String warningMessage = ""; | ||
Set<String> supportedTypes = new HashSet<String>(); | ||
if (accessibilityUnit == null || !ReactTtsSpan.SUPPORTED_UNIT_SET.contains(roleClassName)) { | ||
return; | ||
} | ||
try { | ||
if (roleClassName == ReactTtsSpan.TYPE_MONEY) { | ||
warningMessage = ReactTtsSpan.TYPE_MONEY_WARNING_MSG; | ||
Currency.getInstance(accessibilityUnit); | ||
setStringArgument(ReactTtsSpan.ARG_INTEGER_PART, ""); | ||
setStringArgument(ReactTtsSpan.ARG_CURRENCY, accessibilityUnit); | ||
} | ||
if (roleClassName == ReactTtsSpan.TYPE_TELEPHONE) { | ||
warningMessage = ReactTtsSpan.TYPE_TELEPHONE_WARNING_MSG; | ||
setStringArgument(ReactTtsSpan.ARG_NUMBER_PARTS, accessibilityUnit); | ||
} | ||
// https://developer.android.com/reference/android/text/style/TtsSpan#ARG_UNIT | ||
if (roleClassName == ReactTtsSpan.TYPE_MEASURE) { | ||
warningMessage = ReactTtsSpan.TYPE_MEASURE_WARNING_MSG; | ||
setStringArgument(ReactTtsSpan.ARG_UNIT, accessibilityUnit); | ||
} | ||
} catch (Exception e) { | ||
FLog.e( | ||
TAG, | ||
"Failed to create ReactTtsSpan.Builder with params type: " | ||
+ type | ||
+ " and accessibilityUnit: " | ||
+ accessibilityUnit | ||
+ " " | ||
+ warningMessage | ||
+ "Error: " | ||
+ e); | ||
} | ||
} | ||
|
||
public ReactTtsSpan build() { | ||
return new ReactTtsSpan(mType, mArgs); | ||
} | ||
|
||
public C setIntArgument(String arg, int value) { | ||
mArgs.putInt(arg, value); | ||
return (C) this; | ||
} | ||
|
||
public C setStringArgument(String arg, String value) { | ||
mArgs.putString(arg, value); | ||
return (C) this; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we get rid of
'grid'
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunaleaps Sorry. It was a mistake while removing the duplicate from RCTViewManager (related f3d9f2e).
Fixed with commit f495025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained by Nick in https://github.com/facebook/react-native/pull/34477/files#r982953176, this roles are platform specific. I'm not adding them to the Role type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test cases included in #35130 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
related PR facebook/react-native-deprecated-modules#15