import React from 'react'; import { Platform, View, StyleSheet, TouchableOpacity, ScrollView, Text, Switch, } from 'react-native'; import { PROVIDER_GOOGLE, PROVIDER_DEFAULT } from 'react-native-maps'; import DisplayLatLng from './examples/DisplayLatLng'; import ViewsAsMarkers from './examples/ViewsAsMarkers'; import EventListener from './examples/EventListener'; import MarkerTypes from './examples/MarkerTypes'; import DraggableMarkers from './examples/DraggableMarkers'; import PolygonCreator from './examples/PolygonCreator'; import PolylineCreator from './examples/PolylineCreator'; import GradientPolylines from './examples/GradientPolylines'; import AnimatedViews from './examples/AnimatedViews'; import AnimatedMarkers from './examples/AnimatedMarkers'; import Callouts from './examples/Callouts'; import Overlays from './examples/Overlays'; import DefaultMarkers from './examples/DefaultMarkers'; import CustomMarkers from './examples/CustomMarkers'; import CachedMap from './examples/CachedMap'; import LoadingMap from './examples/LoadingMap'; import MapBoundaries from './examples/MapBoundaries'; import TakeSnapshot from './examples/TakeSnapshot'; import FitToSuppliedMarkers from './examples/FitToSuppliedMarkers'; import FitToCoordinates from './examples/FitToCoordinates'; import LiteMapView from './examples/LiteMapView'; import CustomTiles from './examples/CustomTiles'; import WMSTiles from './examples/WMSTiles'; import ZIndexMarkers from './examples/ZIndexMarkers'; import StaticMap from './examples/StaticMap'; import MapStyle from './examples/MapStyle'; import LegalLabel from './examples/LegalLabel'; import SetNativePropsOverlays from './examples/SetNativePropsOverlays'; import CustomOverlay from './examples/CustomOverlay'; import MapKml from './examples/MapKml'; import BugMarkerWontUpdate from './examples/BugMarkerWontUpdate'; import ImageOverlayWithAssets from './examples/ImageOverlayWithAssets'; import ImageOverlayWithURL from './examples/ImageOverlayWithURL'; import ImageOverlayWithRotation from './examples/ImageOverlayWithRotation'; import AnimatedNavigation from './examples/AnimatedNavigation'; import OnPoiClick from './examples/OnPoiClick'; import TestIdMarkers from './examples/TestIdMarkers'; import IndoorMap from './examples/IndoorMap'; import CameraControl from './examples/CameraControl'; import MassiveCustomMarkers from './examples/MassiveCustomMarkers'; import GeojsonMap from './examples/Geojson'; const IOS = Platform.OS === 'ios'; const ANDROID = Platform.OS === 'android'; function makeExampleMapper(useGoogleMaps) { if (useGoogleMaps) { return example => [ example[0], [example[1], example[3]].filter(Boolean).join(' '), ]; } return example => example; } type Props = {}; export default class App extends React.Component { constructor(props) { super(props); this.state = { Component: null, useGoogleMaps: ANDROID, }; } renderExample([Component, title]) { return ( this.setState({ Component })} > {title} ); } renderBackButton() { return ( this.setState({ Component: null })} > ); } renderGoogleSwitch() { return ( Use GoogleMaps? this.setState({ useGoogleMaps: value })} style={styles.googleSwitch} value={this.state.useGoogleMaps} /> ); } renderExamples(examples) { const { Component, useGoogleMaps } = this.state; return ( {Component && ( )} {Component && this.renderBackButton()} {!Component && ( {IOS && this.renderGoogleSwitch()} {examples.map(example => this.renderExample(example))} )} ); } render() { return this.renderExamples( [ // [, , , ] [StaticMap, 'StaticMap', true], [DisplayLatLng, 'Tracking Position', true, '(incomplete)'], [ViewsAsMarkers, 'Arbitrary Views as Markers', true], [EventListener, 'Events', true, '(incomplete)'], [MarkerTypes, 'Image Based Markers', true], [DraggableMarkers, 'Draggable Markers', true], [PolygonCreator, 'Polygon Creator', true], [PolylineCreator, 'Polyline Creator', true], [GradientPolylines, 'Gradient Polylines', true], [AnimatedViews, 'Animating with MapViews'], [AnimatedMarkers, 'Animated Marker Position'], [Callouts, 'Custom Callouts', true], [Overlays, 'Circles, Polygons, and Polylines', true], [DefaultMarkers, 'Default Markers', true], [CustomMarkers, 'Custom Markers', true], [TakeSnapshot, 'Take Snapshot', true, '(incomplete)'], [CachedMap, 'Cached Map'], [LoadingMap, 'Map with loading'], [MapBoundaries, 'Get visible map boundaries', true], [FitToSuppliedMarkers, 'Focus Map On Markers', true], [FitToCoordinates, 'Fit Map To Coordinates', true], [LiteMapView, 'Android Lite MapView'], [CustomTiles, 'Custom Tiles', true], [WMSTiles, 'WMS Tiles', true], [ZIndexMarkers, 'Position Markers with Z-index', true], [MapStyle, 'Customize the style of the map', true], [LegalLabel, 'Reposition the legal label', true], [SetNativePropsOverlays, 'Update native props', true], [CustomOverlay, 'Custom Overlay Component', true], [TestIdMarkers, 'Test ID for Automation', true], [MapKml, 'Load Map with KML', true], [BugMarkerWontUpdate, "BUG: Marker Won't Update (Android)", true], [ImageOverlayWithAssets, 'Image Overlay Component with Assets', true], [ImageOverlayWithURL, 'Image Overlay Component with URL', true], [ ImageOverlayWithRotation, 'Image Overlay Component with Rotation', 'default', ], [AnimatedNavigation, 'Animated Map Navigation', true], [OnPoiClick, 'On Poi Click', true], [IndoorMap, 'Indoor Map', true], [CameraControl, 'CameraControl', true], [MassiveCustomMarkers, 'MassiveCustomMarkers', true], [GeojsonMap, 'Geojson', true], ] // Filter out examples that are not yet supported for Google Maps on iOS. .filter( example => ANDROID || (IOS && (example[2] || !this.state.useGoogleMaps)) ) .map(makeExampleMapper(IOS && this.state.useGoogleMaps)) ); } } const styles = StyleSheet.create({ container: { ...StyleSheet.absoluteFillObject, justifyContent: 'flex-end', alignItems: 'center', }, scrollview: { alignItems: 'center', paddingVertical: 40, }, button: { flex: 1, marginTop: 10, backgroundColor: 'rgba(220,220,220,0.7)', paddingHorizontal: 18, paddingVertical: 12, borderRadius: 20, }, back: { position: 'absolute', top: 20, left: 12, backgroundColor: 'rgba(255,255,255,0.4)', padding: 12, borderRadius: 20, width: 80, alignItems: 'center', justifyContent: 'center', }, backButton: { fontWeight: 'bold', fontSize: 30 }, googleSwitch: { marginBottom: 10 }, });