| 15 | const VERTICAL_PADDING = 6; |
| 16 | |
| 17 | class CachedMap extends React.Component<any, any> { |
| 18 | constructor(props: any) { |
| 19 | super(props); |
| 20 | this.state = { |
| 21 | data: [...COUNTRIES], |
| 22 | cache: true, |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | toggleCache() { |
| 27 | // a hack to force listview to reload with the same data |
| 28 | this.setState({ |
| 29 | data: this.state.data, |
| 30 | }); |
| 31 | this.setState({ |
| 32 | cache: !this.state.cache, |
| 33 | data: [...COUNTRIES], |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | render() { |
| 38 | const {width} = Dimensions.get('window'); |
| 39 | const mapSize = width - HORIZONTAL_PADDING * 2; |
| 40 | return ( |
| 41 | <View style={styles.container}> |
| 42 | <View style={styles.buttonContainer}> |
| 43 | <TouchableOpacity |
| 44 | onPress={() => this.toggleCache()} |
| 45 | style={[styles.bubble, styles.button]}> |
| 46 | <Text style={styles.buttonText}> |
| 47 | {this.state.cache ? 'Cached' : 'Not cached'} |
| 48 | </Text> |
| 49 | </TouchableOpacity> |
| 50 | </View> |
| 51 | <FlatList |
| 52 | data={this.state.data} |
| 53 | renderItem={({item: region}) => ( |
| 54 | <View style={styles.item}> |
| 55 | <Text>{region.name}</Text> |
| 56 | <MapView |
| 57 | provider={this.props.provider} |
| 58 | style={{ |
| 59 | width: mapSize, |
| 60 | height: mapSize, |
| 61 | }} |
| 62 | initialRegion={region} |
| 63 | cacheEnabled={this.state.cache} |
| 64 | zoomEnabled |
| 65 | loadingIndicatorColor="#666666" |
| 66 | loadingBackgroundColor="#eeeeee"> |
| 67 | <Marker |
| 68 | coordinate={region} |
| 69 | centerOffset={{x: -18, y: -60}} |
| 70 | anchor={{x: 0.69, y: 1}} |
| 71 | image={flagImg} |
| 72 | /> |
| 73 | </MapView> |
| 74 | </View> |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…