mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 13:25:51 +08:00
Summary: This PR divides the accessibility tests into two activities-- a cross-platform activity for accessibility features which are expected to work on all platforms, and platform specific tests for Android and iOS. We believe that most, if not all, accessibility features should be cross-platform, with fallback implementations where the underlying concept doesn't exist on a particular platform. This division of the tests makes it clearer for developers which features are expected to work on all supported platforms, and which are platform-specific. [CATEGORY] general, Android, iOS [TYPE] change Message Refactor the RNTester accessibility activities to better represent where the features are expected to work. Moves all cross-platform tests to AccessibilityExample.js, Android-specific tests to AccessibilityAndroidExample.android.js, and iOS-specific tests to AccessibilityIOsExample.ios.js. Pull Request resolved: https://github.com/facebook/react-native/pull/23722 Differential Revision: D14320696 Pulled By: cpojer fbshipit-source-id: b5ab7a82a90f06d55a24262e86bd69fbdc890427
181 lines
4.8 KiB
JavaScript
181 lines
4.8 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const React = require('react');
|
|
const ReactNative = require('react-native');
|
|
const {
|
|
AccessibilityInfo,
|
|
StyleSheet,
|
|
Text,
|
|
View,
|
|
ToastAndroid,
|
|
TouchableWithoutFeedback,
|
|
} = ReactNative;
|
|
|
|
const RNTesterBlock = require('./RNTesterBlock');
|
|
const RNTesterPage = require('./RNTesterPage');
|
|
|
|
const importantForAccessibilityValues = [
|
|
'auto',
|
|
'yes',
|
|
'no',
|
|
'no-hide-descendants',
|
|
];
|
|
|
|
class AccessibilityAndroidExample extends React.Component {
|
|
state = {
|
|
count: 0,
|
|
backgroundImportantForAcc: 0,
|
|
forgroundImportantForAcc: 0,
|
|
};
|
|
|
|
_addOne = () => {
|
|
this.setState({
|
|
count: ++this.state.count,
|
|
});
|
|
};
|
|
|
|
_changeBackgroundImportantForAcc = () => {
|
|
this.setState({
|
|
backgroundImportantForAcc: (this.state.backgroundImportantForAcc + 1) % 4,
|
|
});
|
|
};
|
|
|
|
_changeForgroundImportantForAcc = () => {
|
|
this.setState({
|
|
forgroundImportantForAcc: (this.state.forgroundImportantForAcc + 1) % 4,
|
|
});
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<RNTesterPage title={'Accessibility Android APIs'}>
|
|
<RNTesterBlock title="LiveRegion">
|
|
<TouchableWithoutFeedback onPress={this._addOne}>
|
|
<View style={styles.embedded}>
|
|
<Text>Click me</Text>
|
|
</View>
|
|
</TouchableWithoutFeedback>
|
|
<Text accessibilityLiveRegion="polite">
|
|
Clicked {this.state.count} times
|
|
</Text>
|
|
</RNTesterBlock>
|
|
|
|
<RNTesterBlock title="Overlapping views and importantForAccessibility property">
|
|
<View style={styles.container}>
|
|
<View
|
|
style={{
|
|
position: 'absolute',
|
|
left: 10,
|
|
top: 10,
|
|
right: 10,
|
|
height: 100,
|
|
backgroundColor: 'green',
|
|
}}
|
|
accessible={true}
|
|
accessibilityLabel="First layout"
|
|
importantForAccessibility={
|
|
importantForAccessibilityValues[
|
|
this.state.backgroundImportantForAcc
|
|
]
|
|
}>
|
|
<View accessible={true}>
|
|
<Text style={{fontSize: 25}}>Hello</Text>
|
|
</View>
|
|
</View>
|
|
<View
|
|
style={{
|
|
position: 'absolute',
|
|
left: 10,
|
|
top: 25,
|
|
right: 10,
|
|
height: 110,
|
|
backgroundColor: 'yellow',
|
|
opacity: 0.5,
|
|
}}
|
|
accessible={true}
|
|
accessibilityLabel="Second layout"
|
|
importantForAccessibility={
|
|
importantForAccessibilityValues[
|
|
this.state.forgroundImportantForAcc
|
|
]
|
|
}>
|
|
<View accessible={true}>
|
|
<Text style={{fontSize: 20}}>world</Text>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
<TouchableWithoutFeedback
|
|
onPress={this._changeBackgroundImportantForAcc}>
|
|
<View style={styles.embedded}>
|
|
<Text>
|
|
Change importantForAccessibility for background layout.
|
|
</Text>
|
|
</View>
|
|
</TouchableWithoutFeedback>
|
|
<View accessible={true}>
|
|
<Text>Background layout importantForAccessibility</Text>
|
|
<Text>
|
|
{
|
|
importantForAccessibilityValues[
|
|
this.state.backgroundImportantForAcc
|
|
]
|
|
}
|
|
</Text>
|
|
</View>
|
|
<TouchableWithoutFeedback
|
|
onPress={this._changeForgroundImportantForAcc}>
|
|
<View style={styles.embedded}>
|
|
<Text>
|
|
Change importantForAccessibility for forground layout.
|
|
</Text>
|
|
</View>
|
|
</TouchableWithoutFeedback>
|
|
<View accessible={true}>
|
|
<Text>Forground layout importantForAccessibility</Text>
|
|
<Text>
|
|
{
|
|
importantForAccessibilityValues[
|
|
this.state.forgroundImportantForAcc
|
|
]
|
|
}
|
|
</Text>
|
|
</View>
|
|
</RNTesterBlock>
|
|
</RNTesterPage>
|
|
);
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
embedded: {
|
|
backgroundColor: 'yellow',
|
|
padding: 10,
|
|
},
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: 'white',
|
|
padding: 10,
|
|
height: 150,
|
|
},
|
|
});
|
|
|
|
exports.title = 'AccessibilityAndroid';
|
|
exports.description = 'Android specific Accessibility APIs.';
|
|
exports.examples = [
|
|
{
|
|
title: 'Accessibility elements',
|
|
render(): React.Element<typeof AccessibilityAndroidExample> {
|
|
return <AccessibilityAndroidExample />;
|
|
},
|
|
},
|
|
];
|