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
|
|
|
*
|
2015-05-28 10:56:48 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2015-05-28 10:56:48 +00:00
|
|
|
var {
|
2017-02-28 02:28:23 +00:00
|
|
|
AccessibilityInfo,
|
2015-05-28 10:56:48 +00:00
|
|
|
Text,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = 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}>
|
|
|
|
<Text>
|
|
|
|
Accessibility normal tap example
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
<View onMagicTap={() => alert('onMagicTap success')}
|
|
|
|
accessible={true}>
|
|
|
|
<Text>
|
|
|
|
Accessibility magic tap example
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
<View accessibilityLabel="Some announcement"
|
|
|
|
accessible={true}>
|
|
|
|
<Text>
|
|
|
|
Accessibility label example
|
|
|
|
</Text>
|
|
|
|
</View>
|
2015-10-16 11:02:18 +00:00
|
|
|
<View accessibilityTraits={['button', 'selected']}
|
2015-05-28 10:56:48 +00:00
|
|
|
accessible={true}>
|
|
|
|
<Text>
|
|
|
|
Accessibility traits example
|
|
|
|
</Text>
|
|
|
|
</View>
|
2017-09-12 19:38:13 +00:00
|
|
|
<Text>
|
|
|
|
Text's accessibilityLabel is the raw text itself unless it is set explicitly.
|
|
|
|
</Text>
|
|
|
|
<Text accessibilityLabel="Test of accessibilityLabel"
|
|
|
|
accessible={true}>
|
|
|
|
This text component's accessibilityLabel is set explicitly.
|
|
|
|
</Text>
|
2018-01-29 22:20:06 +00:00
|
|
|
<View accessibilityElementsHidden={true}>
|
|
|
|
<Text>This view's children are hidden from the accessibility tree</Text>
|
|
|
|
</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,
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text>
|
|
|
|
The screen reader is {this.state.screenReaderEnabled ? 'enabled' : 'disabled'}.
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:06:33 +00:00
|
|
|
exports.title = 'AccessibilityIOS';
|
2015-05-28 10:56:48 +00:00
|
|
|
exports.description = 'Interface to show iOS\' accessibility samples';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Accessibility elements',
|
2016-10-16 11:11:59 +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',
|
|
|
|
render(): React.Element<any> { return <ScreenReaderStatusExample />; }
|
|
|
|
},
|
2015-05-28 10:56:48 +00:00
|
|
|
];
|