我能够解决这个问题。在React Native中,Android可以设置一个名为的属性 importantForAccessibility 。它比我更喜欢它,但我实现了自己的NavigationCardStack和NavigationCard(扩展了React Native的版本以在渲染中添加我自己的逻辑)。
基本上迭代每个场景 NavigationCardStack 我通过一个新的财产, isActiveScreen 我通过检查当前索引仅在活动场景上设置为true。
isActiveScreen
然后进去 NavigationCard 我通过添加来利用importantForAccessibility
importantForAccessibility={this.props.isActiveScreen ? 'yes' : 'no-hide-descendants'}
以这种方式在android上只有我当前可见的场景启用了辅助功能,而堆栈中的所有其他场景都设置了无隐藏后代。
我有同样的问题使用 反应导航 图书馆。我能够修改 react-navigation/src/views/CardStack/Card.js 为了解决这里可以找到的问题,我只修改了渲染方法(无法获取格式化代码:()
react-navigation/src/views/CardStack/Card.js
Card.js @ Github
以下是我对此的修改:
// Fixes an issue on Android whereby talkback/voiceover will pick up elements on a child view that is not active in the stack navigator if(this.props.scene.isActive) { importantForAccessibility='yes'; } else { importantForAccessibility='no-hide-descendants'; } return ( <Animated.View pointerEvents={pointerEvents} ref={this.props.onComponentRef} style={[styles.main, style]} importantForAccessibility={importantForAccessibility} > {children} </Animated.View> );
这个修复程序也在github&amp;如果有人需要,则发布到NPM如下: https://github.com/awseeley/react-navigation
https://www.npmjs.com/package/react-navigation-awseeley