2015-05-28 10:56:48 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-05-28 10:56:48 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-05-28 10:56:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-10-30 21:03:18 +00:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
2018-11-20 02:06:49 +00:00
|
|
|
const {AccessibilityInfo, Text, View, TouchableOpacity, Alert} = ReactNative;
|
2015-05-28 10:56:48 +00:00
|
|
|
|
2018-12-31 16:26:00 +00:00
|
|
|
type Props = $ReadOnly<{||}>;
|
|
|
|
class AccessibilityIOSExample extends React.Component<Props> {
|
2015-05-28 10:56:48 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<View
|
2018-11-20 02:06:49 +00:00
|
|
|
onAccessibilityTap={() =>
|
|
|
|
Alert.alert('Alert', 'onAccessibilityTap success')
|
|
|
|
}
|
2015-05-28 10:56:48 +00:00
|
|
|
accessible={true}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>Accessibility normal tap example</Text>
|
2015-05-28 10:56:48 +00:00
|
|
|
</View>
|
2018-11-20 02:06:49 +00:00
|
|
|
<View
|
|
|
|
onMagicTap={() => Alert.alert('Alert', 'onMagicTap success')}
|
|
|
|
accessible={true}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>Accessibility magic tap example</Text>
|
2015-05-28 10:56:48 +00:00
|
|
|
</View>
|
2018-12-07 03:39:42 +00:00
|
|
|
<View
|
|
|
|
onAccessibilityEscape={() => alert('onAccessibilityEscape success')}
|
|
|
|
accessible={true}>
|
|
|
|
<Text>Accessibility escape example</Text>
|
|
|
|
</View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<View accessibilityLabel="Some announcement" accessible={true}>
|
|
|
|
<Text>Accessibility label example</Text>
|
2015-05-28 10:56:48 +00:00
|
|
|
</View>
|
2018-07-26 20:44:57 +00:00
|
|
|
<View
|
|
|
|
accessibilityRole="button"
|
|
|
|
accessibilityStates={['selected']}
|
|
|
|
accessible={true}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>Accessibility traits example</Text>
|
2015-05-28 10:56:48 +00:00
|
|
|
</View>
|
2017-09-12 19:38:13 +00:00
|
|
|
<Text>
|
2018-05-11 20:32:37 +00:00
|
|
|
Text's accessibilityLabel is the raw text itself unless it is set
|
|
|
|
explicitly.
|
2017-09-12 19:38:13 +00:00
|
|
|
</Text>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text accessibilityLabel="Test of accessibilityLabel" accessible={true}>
|
2017-09-12 19:38:13 +00:00
|
|
|
This text component's accessibilityLabel is set explicitly.
|
|
|
|
</Text>
|
2018-07-26 00:33:58 +00:00
|
|
|
<View
|
|
|
|
accessibilityLabel="Test of accessibilityHint"
|
|
|
|
accessibilityHint="The hint provides more info than the label does"
|
|
|
|
accessible={true}>
|
|
|
|
<Text>
|
|
|
|
This view component has both an accessibilityLabel and an
|
|
|
|
accessibilityHint explicitly set.
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
<Text
|
|
|
|
accessibilityLabel="Test of accessibilityHint"
|
|
|
|
accessibilityHint="The hint provides more info than the label does">
|
|
|
|
This text component has both an accessibilityLabel and an
|
|
|
|
accessibilityHint explicitly set.
|
|
|
|
</Text>
|
|
|
|
<TouchableOpacity
|
|
|
|
accessibilityLabel="Test of accessibilityHint"
|
|
|
|
accessibilityHint="The hint provides more info than the label does">
|
|
|
|
<View>
|
|
|
|
<Text>
|
|
|
|
This button has both an accessibilityLabel and an
|
|
|
|
accessibilityHint explicitly set.
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
2018-01-29 22:20:06 +00:00
|
|
|
<View accessibilityElementsHidden={true}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>
|
|
|
|
This view's children are hidden from the accessibility tree
|
|
|
|
</Text>
|
2018-01-29 22:20:06 +00:00
|
|
|
</View>
|
2015-05-28 10:56:48 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-28 10:56:48 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ScreenReaderStatusExample extends React.Component<{}, $FlowFixMeState> {
|
2017-02-28 02:28:23 +00:00
|
|
|
state = {
|
|
|
|
screenReaderEnabled: false,
|
2018-05-11 20:32:37 +00:00
|
|
|
};
|
2017-02-28 02:28:23 +00:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
AccessibilityInfo.addEventListener(
|
|
|
|
'change',
|
2018-05-11 20:32:37 +00:00
|
|
|
this._handleScreenReaderToggled,
|
2017-02-28 02:28:23 +00:00
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
AccessibilityInfo.fetch().done(isEnabled => {
|
2017-02-28 02:28:23 +00:00
|
|
|
this.setState({
|
2018-05-11 20:32:37 +00:00
|
|
|
screenReaderEnabled: isEnabled,
|
2017-02-28 02:28:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
AccessibilityInfo.removeEventListener(
|
|
|
|
'change',
|
2018-05-11 20:32:37 +00:00
|
|
|
this._handleScreenReaderToggled,
|
2017-02-28 02:28:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
_handleScreenReaderToggled = isEnabled => {
|
2017-02-28 02:28:23 +00:00
|
|
|
this.setState({
|
|
|
|
screenReaderEnabled: isEnabled,
|
|
|
|
});
|
2018-05-11 20:32:37 +00:00
|
|
|
};
|
2017-02-28 02:28:23 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text>
|
2018-05-11 20:32:37 +00:00
|
|
|
The screen reader is{' '}
|
|
|
|
{this.state.screenReaderEnabled ? 'enabled' : 'disabled'}.
|
2017-02-28 02:28:23 +00:00
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:06:33 +00:00
|
|
|
exports.title = 'AccessibilityIOS';
|
2018-05-11 20:32:37 +00:00
|
|
|
exports.description = "Interface to show iOS' accessibility samples";
|
2015-05-28 10:56:48 +00:00
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Accessibility elements',
|
2018-05-11 20:32:37 +00:00
|
|
|
render(): React.Element<any> {
|
|
|
|
return <AccessibilityIOSExample />;
|
|
|
|
},
|
2015-05-28 10:56:48 +00:00
|
|
|
},
|
2017-02-28 02:28:23 +00:00
|
|
|
{
|
|
|
|
title: 'Check if the screen reader is enabled',
|
2018-05-11 20:32:37 +00:00
|
|
|
render(): React.Element<any> {
|
|
|
|
return <ScreenReaderStatusExample />;
|
|
|
|
},
|
2017-02-28 02:28:23 +00:00
|
|
|
},
|
2015-05-28 10:56:48 +00:00
|
|
|
];
|