2015-09-14 14:35:58 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule AccessibilityAndroidExample
|
2015-09-14 14:35:58 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2015-09-14 14:35:58 +00:00
|
|
|
var {
|
2017-02-28 02:28:23 +00:00
|
|
|
AccessibilityInfo,
|
2015-09-14 14:35:58 +00:00
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
View,
|
|
|
|
ToastAndroid,
|
|
|
|
TouchableWithoutFeedback,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
var RNTesterBlock = require('./RNTesterBlock');
|
|
|
|
var RNTesterPage = require('./RNTesterPage');
|
2015-09-14 14:35:58 +00:00
|
|
|
|
|
|
|
var importantForAccessibilityValues = ['auto', 'yes', 'no', 'no-hide-descendants'];
|
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class AccessibilityAndroidExample extends React.Component {
|
|
|
|
static title = 'Accessibility';
|
|
|
|
static description = 'Examples of using Accessibility API.';
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
count: 0,
|
|
|
|
backgroundImportantForAcc: 0,
|
|
|
|
forgroundImportantForAcc: 0,
|
2017-02-28 02:28:23 +00:00
|
|
|
screenReaderEnabled: false,
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-02-28 02:28:23 +00:00
|
|
|
componentDidMount() {
|
|
|
|
AccessibilityInfo.addEventListener(
|
|
|
|
'change',
|
|
|
|
this._handleScreenReaderToggled
|
|
|
|
);
|
|
|
|
AccessibilityInfo.fetch().done((isEnabled) => {
|
|
|
|
this.setState({
|
|
|
|
screenReaderEnabled: isEnabled
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
AccessibilityInfo.removeEventListener(
|
|
|
|
'change',
|
|
|
|
this._handleScreenReaderToggled
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleScreenReaderToggled = (isEnabled) => {
|
|
|
|
this.setState({
|
|
|
|
screenReaderEnabled: isEnabled,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_addOne = () => {
|
2015-09-14 14:35:58 +00:00
|
|
|
this.setState({
|
|
|
|
count: ++this.state.count,
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_changeBackgroundImportantForAcc = () => {
|
2015-09-14 14:35:58 +00:00
|
|
|
this.setState({
|
|
|
|
backgroundImportantForAcc: (this.state.backgroundImportantForAcc + 1) % 4,
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_changeForgroundImportantForAcc = () => {
|
2015-09-14 14:35:58 +00:00
|
|
|
this.setState({
|
|
|
|
forgroundImportantForAcc: (this.state.forgroundImportantForAcc + 1) % 4,
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-09-14 14:35:58 +00:00
|
|
|
return (
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterPage title={'Accessibility'}>
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Nonaccessible view with TextViews">
|
2015-09-14 14:35:58 +00:00
|
|
|
<View>
|
|
|
|
<Text style={{color: 'green',}}>
|
|
|
|
This is
|
|
|
|
</Text>
|
|
|
|
<Text style={{color: 'blue'}}>
|
|
|
|
nontouchable normal view.
|
|
|
|
</Text>
|
|
|
|
</View>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Accessible view with TextViews wihout label">
|
2015-09-14 14:35:58 +00:00
|
|
|
<View accessible={true}>
|
|
|
|
<Text style={{color: 'green',}}>
|
|
|
|
This is
|
|
|
|
</Text>
|
|
|
|
<Text style={{color: 'blue'}}>
|
|
|
|
nontouchable accessible view without label.
|
|
|
|
</Text>
|
|
|
|
</View>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Accessible view with TextViews with label">
|
2015-09-14 14:35:58 +00:00
|
|
|
<View accessible={true}
|
|
|
|
accessibilityLabel="I have label, so I read it instead of embedded text.">
|
|
|
|
<Text style={{color: 'green',}}>
|
|
|
|
This is
|
|
|
|
</Text>
|
|
|
|
<Text style={{color: 'blue'}}>
|
|
|
|
nontouchable accessible view with label.
|
|
|
|
</Text>
|
|
|
|
</View>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Touchable with component type = button">
|
2015-09-14 14:35:58 +00:00
|
|
|
<TouchableWithoutFeedback
|
|
|
|
onPress={() => ToastAndroid.show('Toasts work by default', ToastAndroid.SHORT)}
|
|
|
|
accessibilityComponentType="button">
|
|
|
|
<View style={styles.embedded}>
|
|
|
|
<Text>Click me</Text>
|
|
|
|
<Text>Or not</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableWithoutFeedback>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="LiveRegion">
|
2015-09-14 14:35:58 +00:00
|
|
|
<TouchableWithoutFeedback onPress={this._addOne}>
|
|
|
|
<View style={styles.embedded}>
|
|
|
|
<Text>Click me</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
<Text accessibilityLiveRegion="polite">
|
|
|
|
Clicked {this.state.count} times
|
|
|
|
</Text>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Check if the screen reader is enabled">
|
2017-02-28 02:28:23 +00:00
|
|
|
<Text>
|
|
|
|
The screen reader is {this.state.screenReaderEnabled ? 'enabled' : 'disabled'}.
|
|
|
|
</Text>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2017-02-28 02:28:23 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Overlapping views and importantForAccessibility property">
|
2015-09-14 14:35:58 +00:00
|
|
|
<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>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterPage>
|
2015-09-14 14:35:58 +00:00
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-14 14:35:58 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
embedded: {
|
|
|
|
backgroundColor: 'yellow',
|
|
|
|
padding:10,
|
|
|
|
},
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: 'white',
|
|
|
|
padding: 10,
|
|
|
|
height:150,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = AccessibilityAndroidExample;
|