1import { StackScreenProps } from '@react-navigation/stack'; 2import * as React from 'react'; 3import { ScrollView, StyleSheet, Text, View } from 'react-native'; 4 5import examples from './examples'; 6 7type Links = { SVGExample: { title?: string; key: string } }; 8 9type Props = StackScreenProps<Links, 'SVGExample'>; 10 11export default class SVGExampleScreen extends React.Component<Props> { 12 static navigationOptions = ({ route }: Props) => { 13 return { 14 title: route.params.title ?? 'An SVG Example', 15 }; 16 }; 17 18 renderSample = (Sample: React.ComponentType & { title: string }, index: number) => ( 19 <View style={styles.example} key={`sample-${index}`}> 20 <Text style={styles.sampleTitle}>{Sample.title}</Text> 21 <Sample /> 22 </View> 23 ); 24 25 renderNoExample = () => <Text>No example found.</Text>; 26 27 renderContent = () => { 28 const example = examples[this.props.route.params.key]; 29 if (!example) { 30 return this.renderNoExample(); 31 } 32 const { samples } = example; 33 return samples.map(this.renderSample); 34 }; 35 36 render() { 37 return ( 38 <ScrollView style={styles.container} contentContainerStyle={styles.contentContainer}> 39 {this.renderContent()} 40 </ScrollView> 41 ); 42 } 43} 44 45const styles = StyleSheet.create({ 46 container: { 47 ...StyleSheet.absoluteFillObject, 48 }, 49 contentContainer: { 50 alignItems: 'center', 51 justifyContent: 'center', 52 }, 53 example: { 54 paddingVertical: 25, 55 alignSelf: 'stretch', 56 alignItems: 'center', 57 borderBottomWidth: StyleSheet.hairlineWidth, 58 borderBottomColor: '#ccc', 59 }, 60 sampleTitle: { 61 marginHorizontal: 15, 62 fontSize: 16, 63 color: '#666', 64 }, 65}); 66