2015-05-28 03:56:48 -07:00
|
|
|
/**
|
2017-05-05 20:50:47 -07:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 05:51:57 -07:00
|
|
|
*
|
2018-02-16 18:24:55 -08: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 05:51:57 -07:00
|
|
|
*
|
2018-05-11 13:32:37 -07:00
|
|
|
* @format
|
2015-05-28 03:56:48 -07:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 13:32:37 -07:00
|
|
|
|
2015-05-28 03:56:48 -07:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-08 20:36:40 -07:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 13:32:37 -07:00
|
|
|
var {AccessibilityInfo, Text, View} = ReactNative;
|
2015-05-28 03:56:48 -07:00
|
|
|
|
2017-08-17 18:36:54 -07:00
|
|
|
class AccessibilityIOSExample extends React.Component<{}> {
|
2015-05-28 03:56:48 -07:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<View
|
|
|
|
onAccessibilityTap={() => alert('onAccessibilityTap success')}
|
|
|
|
accessible={true}>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Text>Accessibility normal tap example</Text>
|
2015-05-28 03:56:48 -07:00
|
|
|
</View>
|
2018-05-11 13:32:37 -07:00
|
|
|
<View onMagicTap={() => alert('onMagicTap success')} accessible={true}>
|
|
|
|
<Text>Accessibility magic tap example</Text>
|
2015-05-28 03:56:48 -07:00
|
|
|
</View>
|
2018-05-11 13:32:37 -07:00
|
|
|
<View accessibilityLabel="Some announcement" accessible={true}>
|
|
|
|
<Text>Accessibility label example</Text>
|
2015-05-28 03:56:48 -07:00
|
|
|
</View>
|
2018-05-11 13:32:37 -07:00
|
|
|
<View accessibilityTraits={['button', 'selected']} accessible={true}>
|
|
|
|
<Text>Accessibility traits example</Text>
|
2015-05-28 03:56:48 -07:00
|
|
|
</View>
|
2017-09-12 12:38:13 -07:00
|
|
|
<Text>
|
2018-05-11 13:32:37 -07:00
|
|
|
Text's accessibilityLabel is the raw text itself unless it is set
|
|
|
|
explicitly.
|
2017-09-12 12:38:13 -07:00
|
|
|
</Text>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Text accessibilityLabel="Test of accessibilityLabel" accessible={true}>
|
2017-09-12 12:38:13 -07:00
|
|
|
This text component's accessibilityLabel is set explicitly.
|
|
|
|
</Text>
|
2018-01-29 14:20:06 -08:00
|
|
|
<View accessibilityElementsHidden={true}>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Text>
|
|
|
|
This view's children are hidden from the accessibility tree
|
|
|
|
</Text>
|
2018-01-29 14:20:06 -08:00
|
|
|
</View>
|
2015-05-28 03:56:48 -07:00
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 01:00:02 -07:00
|
|
|
}
|
|
|
|
}
|
2015-05-28 03:56:48 -07:00
|
|
|
|
2017-08-17 18:36:54 -07:00
|
|
|
class ScreenReaderStatusExample extends React.Component<{}, $FlowFixMeState> {
|
2017-02-27 18:28:23 -08:00
|
|
|
state = {
|
|
|
|
screenReaderEnabled: false,
|
2018-05-11 13:32:37 -07:00
|
|
|
};
|
2017-02-27 18:28:23 -08:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
AccessibilityInfo.addEventListener(
|
|
|
|
'change',
|
2018-05-11 13:32:37 -07:00
|
|
|
this._handleScreenReaderToggled,
|
2017-02-27 18:28:23 -08:00
|
|
|
);
|
2018-05-11 13:32:37 -07:00
|
|
|
AccessibilityInfo.fetch().done(isEnabled => {
|
2017-02-27 18:28:23 -08:00
|
|
|
this.setState({
|
2018-05-11 13:32:37 -07:00
|
|
|
screenReaderEnabled: isEnabled,
|
2017-02-27 18:28:23 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
AccessibilityInfo.removeEventListener(
|
|
|
|
'change',
|
2018-05-11 13:32:37 -07:00
|
|
|
this._handleScreenReaderToggled,
|
2017-02-27 18:28:23 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-11 13:32:37 -07:00
|
|
|
_handleScreenReaderToggled = isEnabled => {
|
2017-02-27 18:28:23 -08:00
|
|
|
this.setState({
|
|
|
|
screenReaderEnabled: isEnabled,
|
|
|
|
});
|
2018-05-11 13:32:37 -07:00
|
|
|
};
|
2017-02-27 18:28:23 -08:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text>
|
2018-05-11 13:32:37 -07:00
|
|
|
The screen reader is{' '}
|
|
|
|
{this.state.screenReaderEnabled ? 'enabled' : 'disabled'}.
|
2017-02-27 18:28:23 -08:00
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:06:33 -07:00
|
|
|
exports.title = 'AccessibilityIOS';
|
2018-05-11 13:32:37 -07:00
|
|
|
exports.description = "Interface to show iOS' accessibility samples";
|
2015-05-28 03:56:48 -07:00
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Accessibility elements',
|
2018-05-11 13:32:37 -07:00
|
|
|
render(): React.Element<any> {
|
|
|
|
return <AccessibilityIOSExample />;
|
|
|
|
},
|
2015-05-28 03:56:48 -07:00
|
|
|
},
|
2017-02-27 18:28:23 -08:00
|
|
|
{
|
|
|
|
title: 'Check if the screen reader is enabled',
|
2018-05-11 13:32:37 -07:00
|
|
|
render(): React.Element<any> {
|
|
|
|
return <ScreenReaderStatusExample />;
|
|
|
|
},
|
2017-02-27 18:28:23 -08:00
|
|
|
},
|
2015-05-28 03:56:48 -07:00
|
|
|
];
|