forked from react-native-maps/react-native-maps
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[google] refactor AIRGoogleMapMarker to use DummyView (react-native-m…
…aps#649) - DummyView is used to create virtual tree - Add CustomMarkers example - Prevent annoying errors from showing up with OS_ACTIVITY_MODE disable, see here facebook/react-native#9921 (comment)
- Loading branch information
Showing
8 changed files
with
217 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import React from 'react'; | ||
import { | ||
StyleSheet, | ||
View, | ||
Text, | ||
Dimensions, | ||
TouchableOpacity, | ||
} from 'react-native'; | ||
|
||
import MapView from 'react-native-maps'; | ||
import flagPinkImg from './assets/flag-pink.png'; | ||
|
||
const { width, height } = Dimensions.get('window'); | ||
|
||
const ASPECT_RATIO = width / height; | ||
const LATITUDE = 37.78825; | ||
const LONGITUDE = -122.4324; | ||
const LATITUDE_DELTA = 0.0922; | ||
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO; | ||
let id = 0; | ||
|
||
class CustomMarkers extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
region: { | ||
latitude: LATITUDE, | ||
longitude: LONGITUDE, | ||
latitudeDelta: LATITUDE_DELTA, | ||
longitudeDelta: LONGITUDE_DELTA, | ||
}, | ||
markers: [], | ||
}; | ||
|
||
this.onMapPress = this.onMapPress.bind(this); | ||
} | ||
|
||
onMapPress(e) { | ||
this.setState({ | ||
markers: [ | ||
...this.state.markers, | ||
{ | ||
coordinate: e.nativeEvent.coordinate, | ||
key: `foo${id++}`, | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<MapView | ||
provider={this.props.provider} | ||
style={styles.map} | ||
initialRegion={this.state.region} | ||
onPress={this.onMapPress} | ||
> | ||
{this.state.markers.map(marker => ( | ||
<MapView.Marker | ||
title={marker.key} | ||
image={flagPinkImg} | ||
key={marker.key} | ||
coordinate={marker.coordinate} | ||
/> | ||
))} | ||
</MapView> | ||
<View style={styles.buttonContainer}> | ||
<TouchableOpacity | ||
onPress={() => this.setState({ markers: [] })} | ||
style={styles.bubble} | ||
> | ||
<Text>Tap to create a marker of random color</Text> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
CustomMarkers.propTypes = { | ||
provider: MapView.ProviderPropType, | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
...StyleSheet.absoluteFillObject, | ||
justifyContent: 'flex-end', | ||
alignItems: 'center', | ||
}, | ||
map: { | ||
...StyleSheet.absoluteFillObject, | ||
}, | ||
bubble: { | ||
backgroundColor: 'rgba(255,255,255,0.7)', | ||
paddingHorizontal: 18, | ||
paddingVertical: 12, | ||
borderRadius: 20, | ||
}, | ||
latlng: { | ||
width: 200, | ||
alignItems: 'stretch', | ||
}, | ||
button: { | ||
width: 80, | ||
paddingHorizontal: 12, | ||
alignItems: 'center', | ||
marginHorizontal: 10, | ||
}, | ||
buttonContainer: { | ||
flexDirection: 'row', | ||
marginVertical: 20, | ||
backgroundColor: 'transparent', | ||
}, | ||
}); | ||
|
||
module.exports = CustomMarkers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// DummyView.h | ||
// AirMapsExplorer | ||
// | ||
// Created by Gil Birman on 10/4/16. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
|
||
@interface DummyView : UIView | ||
@property (nonatomic, weak) UIView *view; | ||
- (instancetype)initWithView:(UIView*)view; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// DummyView.m | ||
// AirMapsExplorer | ||
// | ||
// Created by Gil Birman on 10/4/16. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "DummyView.h" | ||
|
||
@implementation DummyView | ||
- (instancetype)initWithView:(UIView*)view | ||
{ | ||
if ((self = [super init])) { | ||
self.view = view; | ||
} | ||
return self; | ||
} | ||
@end |