- 
                Notifications
    You must be signed in to change notification settings 
- Fork 24.9k
1/n Adding Android support for Accessibility TtsSpan API - Support for accessibilitySpan and accessibilityLabel props in nested Text #35130
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
          
     Closed
      
      
    
  
     Closed
                    Changes from all 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
    
  
  
    
              
        
          
          
            176 changes: 176 additions & 0 deletions
          
          176 
        
  ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTtsSpan.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,176 @@ | ||
| /* | ||
| * 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.PersistableBundle; | ||
| import android.text.style.TtsSpan; | ||
| import androidx.annotation.Nullable; | ||
| import com.facebook.common.logging.FLog; | ||
|  | ||
| /* | ||
| * Used for nested Text accessibility announcements with | ||
| * props accessiblitySpan and accessibilityLabel. | ||
| * | ||
| * 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_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)."; | ||
|  | ||
| public ReactTtsSpan(String type, PersistableBundle args) { | ||
| super(type, args); | ||
| } | ||
|  | ||
| // https://developer.android.com/reference/android/text/style/TtsSpan | ||
| public enum AccessibilitySpan { | ||
| NONE, | ||
| CARDINAL, | ||
| ORDINAL, | ||
| MEASURE, | ||
| TELEPHONE, | ||
| VERBATIM; | ||
|  | ||
| public static String getValue(AccessibilitySpan accessibilitySpan) { | ||
| switch (accessibilitySpan) { | ||
| case CARDINAL: | ||
| return ReactTtsSpan.TYPE_CARDINAL; | ||
| case ORDINAL: | ||
| return ReactTtsSpan.TYPE_ORDINAL; | ||
| case MEASURE: | ||
| return ReactTtsSpan.TYPE_MEASURE; | ||
| case TELEPHONE: | ||
| return ReactTtsSpan.TYPE_TELEPHONE; | ||
| case VERBATIM: | ||
| return ReactTtsSpan.TYPE_VERBATIM; | ||
| case NONE: | ||
| return ReactTtsSpan.TYPE_TEXT; | ||
| default: | ||
| throw new IllegalArgumentException( | ||
| "Invalid accessibility span value: " + accessibilitySpan); | ||
| } | ||
| } | ||
|  | ||
| public static AccessibilitySpan fromValue(@Nullable String value) { | ||
| for (AccessibilitySpan accessibilitySpan : AccessibilitySpan.values()) { | ||
| if (accessibilitySpan.name().equalsIgnoreCase(value)) { | ||
| return accessibilitySpan; | ||
| } | ||
| } | ||
| throw new IllegalArgumentException("Invalid accessibility role value: " + value); | ||
| } | ||
| } | ||
|  | ||
| public static class Builder { | ||
| private String mType; | ||
| private final PersistableBundle mArgs = new PersistableBundle(); | ||
|  | ||
| public Builder(String type) { | ||
| mType = type; | ||
| } | ||
|         
                  fabOnReact marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| public Builder(AccessibilitySpan type, @Nullable String accessibilityLabel) { | ||
| mType = AccessibilitySpan.getValue(type); | ||
| String warningMessage = ""; | ||
| if (accessibilityLabel == null) { | ||
| return; | ||
| } | ||
| try { | ||
| /* | ||
| * The default type used when accessibilitySpan prop is not set (AccessibilitySpan.NONE) | ||
| * Adds the accessibilityLabel announcement on a Nested Text. | ||
| * | ||
| * https://developer.android.com/reference/android/text/style/TtsSpan#TYPE_TEXT | ||
| * This span type can be used to add morphosyntactic features to the text it spans over, | ||
| * or synthesize a something else than the spanned text. | ||
| * Use the argument ARG_TEXT to set a different text. | ||
| * | ||
| * https://developer.android.com/reference/android/text/style/TtsSpan#ARG_TEXT | ||
| * String supplying the text to be synthesized. | ||
| * The synthesizer is free to decide how to interpret the text. Can be used with TYPE_TEXT. | ||
| */ | ||
| if (mType.equals(TYPE_TEXT)) { | ||
| setStringArgument(ARG_TEXT, accessibilityLabel); | ||
| } | ||
| /* | ||
| * <p>Telephone refer to | ||
| * https://developer.android.com/reference/android/text/style/TtsSpan#ARG_NUMBER_PARTS | ||
| * | ||
| * <p>Argument used to specify the main number part of a telephone number. Can be a string of | ||
| * digits where the different parts of the telephone number can be separated with a space, '-', | ||
| * '/' or '.'. Can be used with TYPE_TELEPHONE. | ||
| */ | ||
| if (mType.equals(TYPE_TELEPHONE)) { | ||
| warningMessage = TYPE_TELEPHONE_WARNING_MSG; | ||
| setStringArgument(ARG_NUMBER_PARTS, accessibilityLabel); | ||
| } | ||
| /* | ||
| * <p>Measure refer to | ||
| * https://developer.android.com/reference/android/text/style/TtsSpan#ARG_UNIT | ||
| * | ||
| * <p>Argument used to specify the unit of a measure. The unit should always be specified in | ||
| * English singular form. Prefixes may be used. Engines will do their best to pronounce them | ||
| * correctly in the language used. Engines are expected to at least support the most common ones | ||
| * like "meter", "second", "degree celsius" and "degree fahrenheit" with some common prefixes | ||
| * like "milli" and "kilo". Can be used with TYPE_MEASURE. | ||
| */ | ||
| if (mType.equals(TYPE_MEASURE)) { | ||
| warningMessage = TYPE_MEASURE_WARNING_MSG; | ||
| setStringArgument(ARG_UNIT, accessibilityLabel); | ||
| } | ||
| /* | ||
| * <p>Ordinal and Cardinal | ||
| * https://developer.android.com/reference/android/text/style/TtsSpan#ARG_NUMBER | ||
| * | ||
| * <p>Argument used to specify a whole number. The value can be a string of digits of any size | ||
| * optionally prefixed with a - or +. Can be used with TYPE_CARDINAL and TYPE_ORDINAL. | ||
| */ | ||
| if (mType.equals(TYPE_CARDINAL) || mType.equals(TYPE_ORDINAL)) { | ||
| setStringArgument(ARG_NUMBER, accessibilityLabel); | ||
| } | ||
| } catch (Exception e) { | ||
| // fallback and use accessibilityLabel as text | ||
| if (mType != TYPE_TEXT) { | ||
| mType = TYPE_TEXT; | ||
| setStringArgument(ARG_TEXT, accessibilityLabel); | ||
| } | ||
| FLog.w( | ||
| TAG, | ||
| "Failed to create Builder with params type: " | ||
| + type | ||
| + " and accessibilityLabel: " | ||
| + accessibilityLabel | ||
| + " " | ||
| + warningMessage | ||
| + "Error: " | ||
| + e); | ||
| } | ||
| } | ||
|  | ||
| public ReactTtsSpan build() { | ||
| return new ReactTtsSpan(mType, mArgs); | ||
| } | ||
|  | ||
| public void setStringArgument(String arg, String value) { | ||
| mArgs.putString(arg, value); | ||
| } | ||
| } | ||
| } | ||
  
    
      This file contains hidden or 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 hidden or 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
    
  
  
    
              
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.