/** * Sample React Native App for react-native-svg library * https://github.com/magicismight/react-native-svg/tree/master/Example */ 'use strict'; import React, {Component} from 'react'; import { Dimensions, StyleSheet, Text, View, ScrollView, TouchableHighlight, TouchableOpacity, SafeAreaView, } from 'react-native'; import {Modal, Platform} from 'react-native'; import {Svg, Circle, Line} from 'react-native-svg'; import * as examples from './src/examples'; import {commonStyles} from './src/commonStyles'; const names: (keyof typeof examples)[] = [ 'Svg', 'Stroking', 'Path', 'Line', 'Rect', 'Polygon', 'Polyline', 'Circle', 'Ellipse', 'G', 'Text', 'Gradients', 'Clipping', 'Image', 'TouchEvents', 'PanResponder', 'Reusable', 'Reanimated', 'Transforms', 'Markers', 'Mask', 'Filters', 'FilterImage', ]; const initialState = { modal: false, content: null, }; export default class SvgExample extends Component { state: { content: React.ReactNode; modal: boolean; scroll?: boolean; } = initialState; show = (name: keyof typeof examples) => { if (this.state.modal) { return; } let example = examples[name]; if (example) { let samples = example.samples; this.setState({ modal: true, content: ( {samples.map((Sample, i) => ( {Sample.title} ))} ), scroll: (example as {scroll?: boolean}).scroll !== false, }); } }; hide = () => { this.setState(initialState); }; getExamples = () => { return names.map(name => { var icon; let example = examples[name]; if (example) { icon = example.icon; } return ( this.show(name)}> {icon} {name} ); }); }; modalContent = () => ( <> {this.state.content} ); render() { return ( SVG library for React Apps {this.getExamples()} {(Platform.OS === 'windows' || Platform.OS === 'macos') && this.state.modal ? ( {this.modalContent()} ) : ( {this.modalContent()} )} ); } } const hairline = StyleSheet.hairlineWidth; const styles = StyleSheet.create({ container: { flex: 1, paddingTop: 20, alignItems: 'center', overflow: 'hidden', }, contentContainer: { alignSelf: 'stretch', borderTopWidth: hairline, borderTopColor: '#ccc', borderBottomWidth: hairline, borderBottomColor: '#ccc', flexWrap: 'wrap', flexDirection: 'row', marginHorizontal: 10, }, link: { height: 40, alignSelf: 'stretch', width: Dimensions.get('window').width / 2 - 10, }, close: { position: 'absolute', right: 20, top: 20, }, scroll: { position: 'absolute', top: 30, right: 10, bottom: 20, left: 10, backgroundColor: '#fff', }, scrollContent: { borderTopWidth: hairline, borderTopColor: '#ccc', }, });