Created
August 30, 2019 20:59
-
-
Save bebebebebe/8cb66a11c3b21c66751467d891266679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Demo RN 0.61 app with accessibility actions. | |
* - Add extra content when TalkBack control activated by TalkBack. | |
* | |
* @format | |
* @flow | |
*/ | |
import React from 'react'; | |
import {useState} from 'react'; | |
import { | |
SafeAreaView, | |
StyleSheet, | |
ScrollView, | |
View, | |
Text, | |
StatusBar, | |
TouchableHighlight, | |
Alert, | |
} from 'react-native'; | |
import { | |
Header, | |
LearnMoreLinks, | |
Colors, | |
DebugInstructions, | |
ReloadInstructions, | |
} from 'react-native/Libraries/NewAppScreen'; | |
const App: () => React$Node = () => { | |
const [isControlsVisibleTalkBack, setControlsVisibleTalkBack] = useState( | |
false, | |
); | |
return ( | |
<> | |
<StatusBar barStyle="dark-content" /> | |
<SafeAreaView> | |
<ScrollView | |
contentInsetAdjustmentBehavior="automatic" | |
style={styles.scrollView}> | |
<Header /> | |
{global.HermesInternal == null ? null : ( | |
<View style={styles.engine}> | |
<Text style={styles.footer}>Engine: Hermes</Text> | |
</View> | |
)} | |
<View style={styles.body}> | |
<TouchableHighlight | |
style={styles.sectionContainer} | |
accessible={true} | |
accessibilityActions={[{name: 'activate', label: 'activate'}]} | |
onAccessibilityAction={event => { | |
switch (event.nativeEvent.actionName) { | |
case 'activate': | |
Alert.alert('Hi!'); | |
setControlsVisibleTalkBack(true); | |
break; | |
} | |
}} | |
onPress={() => { | |
Alert.alert('Hi!'); | |
}}> | |
<Text style={styles.sectionTitle}>Hello.</Text> | |
</TouchableHighlight> | |
<View style={styles.sectionContainer}> | |
{isControlsVisibleTalkBack && ( | |
<View> | |
<Text>Controls enabled via TalkBack!</Text> | |
<TouchableHighlight | |
onPress={() => { | |
setControlsVisibleTalkBack(false); | |
}}> | |
<Text style={styles.sectionTitle}>Hide controls</Text> | |
</TouchableHighlight> | |
</View> | |
)} | |
</View> | |
</View> | |
</ScrollView> | |
</SafeAreaView> | |
</> | |
); | |
}; | |
const styles = StyleSheet.create({ | |
scrollView: { | |
backgroundColor: Colors.lighter, | |
}, | |
engine: { | |
position: 'absolute', | |
right: 0, | |
}, | |
body: { | |
backgroundColor: Colors.white, | |
}, | |
sectionContainer: { | |
marginTop: 32, | |
paddingHorizontal: 24, | |
}, | |
sectionTitle: { | |
fontSize: 24, | |
fontWeight: '600', | |
color: Colors.black, | |
}, | |
sectionDescription: { | |
marginTop: 8, | |
fontSize: 18, | |
fontWeight: '400', | |
color: Colors.dark, | |
}, | |
highlight: { | |
fontWeight: '700', | |
}, | |
footer: { | |
color: Colors.dark, | |
fontSize: 12, | |
fontWeight: '600', | |
padding: 4, | |
paddingRight: 12, | |
textAlign: 'right', | |
}, | |
}); | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment