/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ 'use strict'; const React = require('react'); const { AccessibilityInfo, Button, Image, Text, View, TouchableOpacity, TouchableWithoutFeedback, Alert, StyleSheet, } = require('react-native'); const RNTesterBlock = require('../../components/RNTesterBlock'); const checkImageSource = require('./check.png'); const uncheckImageSource = require('./uncheck.png'); const mixedCheckboxImageSource = require('./mixed.png'); const styles = StyleSheet.create({ image: { width: 20, height: 20, resizeMode: 'contain', marginRight: 10, }, }); class AccessibilityExample extends React.Component { render() { return ( Text's accessibilityLabel is the raw text itself unless it is set explicitly. This text component's accessibilityLabel is set explicitly. This is text one. This is text two. This is text one. This is text two. This is text one. This is text two. {/* Android screen readers will say the accessibility hint instead of the text since the view doesn't have a label. */} This is text one. This is text two. This is text one. This is text two. This is a title. Alert.alert('Link has been clicked!')} accessibilityRole="link"> Click me Alert.alert('Button has been pressed!')} accessibilityRole="button"> Click me Alert.alert('Button has been pressed!')} accessibilityRole="button" accessibilityState={{disabled: true}} disabled={true}> I am disabled. Clicking me will not trigger any action. This view is selected and disabled. Accessible view with label, hint, role, and state ); } } class CheckboxExample extends React.Component { state = { checkboxState: true, }; _onCheckboxPress = () => { let checkboxState = false; if (this.state.checkboxState === false) { checkboxState = 'mixed'; } else if (this.state.checkboxState === 'mixed') { checkboxState = true; } else { checkboxState = false; } this.setState({ checkboxState: checkboxState, }); }; render() { return ( Checkbox example ); } } class SwitchExample extends React.Component { state = { switchState: true, }; _onSwitchToggle = () => { const switchState = !this.state.switchState; this.setState({ switchState: switchState, }); }; render() { return ( Switch example ); } } class SelectionExample extends React.Component { constructor(props) { super(props); this.selectableElement = React.createRef(); } state = { isSelected: true, isEnabled: false, }; render() { let accessibilityHint = 'click me to select'; if (this.state.isSelected) { accessibilityHint = 'click me to unselect'; } if (!this.state.isEnabled) { accessibilityHint = 'use the button on the right to enable selection'; } let buttonTitle = this.state.isEnabled ? 'Disable selection' : 'Enable selection'; return ( { if (this.state.isEnabled) { this.setState({ isSelected: !this.state.isSelected, }); } }} accessibilityLabel="element 19" accessibilityState={{ selected: this.state.isSelected, disabled: !this.state.isEnabled, }} accessibilityHint={accessibilityHint}> Selectable element example