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
|
|
|
* 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.
|
|
|
|
*
|
2015-05-28 10:56:48 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule AccessibilityIOSExample
|
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');
|
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
|
|
|
|
2016-07-26 08:00:02 +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>
|
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-28 10:56:48 +00:00
|
|
|
|
2017-02-28 02:28:23 +00:00
|
|
|
class ScreenReaderStatusExample extends React.Component {
|
|
|
|
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
|
|
|
];
|