/** * 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, Modal, Platform, SafeAreaView, ScrollView, StyleSheet, Text, TouchableHighlight, TouchableOpacity, View, } from 'react-native'; import {Circle, Line, Svg} from 'react-native-svg'; import {commonStyles} from './src/commonStyles'; import E2eTestingView from './src/e2e'; import * as examples from './src/examples'; import {names} from './utils/names'; 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 .filter(el => { if (el !== 'E2E') return true; return Platform.OS === 'android' || Platform.OS === 'ios'; }) .map(name => { var icon; let example = examples[name as keyof typeof examples]; if (example) { icon = example.icon; } return ( this.show(name as keyof typeof examples)}> {icon} {name} ); }); }; modalContent = () => ( <> {this.state.content} ); render() { if (process.env.E2E) { console.log( 'Opening E2E example, as E2E env is set to ' + process.env.E2E, ); return ; } 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', }, });