2015-05-28 10:56:48 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
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';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
var {AccessibilityInfo, Text, View} = ReactNative;
|
2015-05-28 10:56:48 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class AccessibilityIOSExample extends React.Component<{}> {
|
2015-05-28 10:56:48 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<View
|
|
|
|
onAccessibilityTap={() => alert('onAccessibilityTap success')}
|
|
|
|
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-05-11 20:32:37 +00:00
|
|
|
<View onMagicTap={() => alert('onMagicTap success')} accessible={true}>
|
|
|
|
<Text>Accessibility magic tap example</Text>
|
2015-05-28 10:56:48 +00:00
|
|
|
</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-05-11 20:32:37 +00:00
|
|
|
<View accessibilityTraits={['button', 'selected']} accessible={true}>
|
|
|
|
<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-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
|
|
|
];
|