-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathaccessible.tsx
150 lines (144 loc) · 4.57 KB
/
accessible.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
* @format
*/
import * as React from 'react';
import {
AppRegistry,
StyleSheet,
Text,
TextInput,
View,
AccessibilityInfo,
findNodeHandle,
TouchableHighlight,
} from 'react-native';
import {ViewWindows} from 'react-native-windows';
export default class Bootstrap extends React.Component<
{},
{displayText: string; counterValue: number; sliderValue: number}
> {
constructor(props: {}) {
super(props);
this.state = {
displayText: 'Starting text. (THIRD ITEM)',
counterValue: 0,
sliderValue: 0,
};
}
myElement = React.createRef<TextInput>();
render() {
return (
<View style={styles.container}>
<View style={styles.item} accessibilityLabel="FIRST ITEM" focusable>
<Text style={styles.text}>Welcome to React Native! (FIRST ITEM)</Text>
</View>
<ViewWindows
style={styles.item}
accessibilityLabel="SECOND ITEM"
focusable
enableFocusRing={false}>
<Text style={styles.text}>No focus visual (SECOND ITEM)</Text>
</ViewWindows>
<ViewWindows
style={styles.item}
accessibilityLabel="THIRD ITEM"
focusable
enableFocusRing={false}
{...{
// Use weird format as work around for the fact that these props are not part of the @types/react-native yet
onFocus: () => this.setState({displayText: 'FOCUSED'}),
onBlur: () => this.setState({displayText: 'BLURRED'}),
}}>
<Text style={styles.text}>{this.state.displayText}</Text>
</ViewWindows>
<TouchableHighlight
style={styles.item}
accessibilityLabel="counter"
accessible={true}
accessibilityRole="button"
accessibilityValue={{text: `${this.state.counterValue}`}}
onPress={() => {
this.setState({counterValue: this.state.counterValue + 1});
}}>
<Text style={styles.text}>
Testing accessibilityValue:text, Click to increase:{' '}
{this.state.counterValue}
</Text>
</TouchableHighlight>
<TouchableHighlight
style={styles.item}
accessibilityLabel="button imitating slider control"
accessible={true}
accessibilityRole="adjustable"
accessibilityValue={{
min: 0,
max: 100,
now: this.state.sliderValue,
}}
onPress={() => {
this.setState({sliderValue: this.state.sliderValue + 1});
}}>
<Text style={styles.text}>
Testing accessibilityValue:min/max/now, click to increase:{' '}
{this.state.sliderValue}
</Text>
</TouchableHighlight>
<TouchableHighlight
style={styles.item}
accessibilityLabel="TEST Announce For Accessibility"
onPress={() => {
AccessibilityInfo.announceForAccessibility('Testing Testing 1 2 3');
}}
{...{
// Use weird format as work around for the fact that these props are not part of the @types/react-native yet
focusable: true,
}}>
<Text style={styles.text}>TEST announceForAccessibility</Text>
</TouchableHighlight>
<TouchableHighlight
style={styles.item}
accessibilityLabel="TEST Set Accessibility Focus"
onPress={() => {
const reactTag = findNodeHandle(this.myElement.current);
if (reactTag) {
AccessibilityInfo.setAccessibilityFocus(reactTag);
}
}}
{...{
// Use weird format as work around for the fact that these props are not part of the @types/react-native yet
focusable: true,
}}>
<Text style={styles.text}>TEST setAccessibilityFocus</Text>
</TouchableHighlight>
<TextInput ref={this.myElement} />
<View style={styles.item} accessibilityElementsHidden={true}>
<Text style={styles.text}>TEST Accessibility Hidden </Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'lightgray',
},
item: {
margin: 10,
backgroundColor: 'lightpink',
borderColor: 'indianred',
borderWidth: 2,
justifyContent: 'center',
},
text: {
fontSize: 20,
textAlign: 'center',
color: 'black',
margin: 10,
},
});
AppRegistry.registerComponent('Bootstrap', () => Bootstrap);