Skip to content

Commit 4812b0a

Browse files
heysailorchristopherdro
authored andcommitted
Enable control of Google Maps Marker tracksViewChanges property. (react-native-maps#1705)
Fixes issue react-native-maps#1031, enabling use of custom marker images and views in Google Maps on iOS and android. As detailed in the Google Maps Marker documentation (kudos to @hughvidos), map markers track view changes by default. This has meant however that custom marker images or views on iOS and android, when using Google Maps, cause high continuous CPU load. The recommended use of tracksViewChanges is to enable when the marker is being rendered or animated, then to disable it. An example of use of tracksViewChanges would be to set it to false once onMapReady has fired. This can be accomplished by toggling a state property (e.g. `initialized`), and passing it to the child map markers in their `tracksViewChanges` prop. Markers would then render correctly on map load; CPU use falls off once the tracking ceases.
1 parent 4c1570f commit 4812b0a

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

lib/components/MapMarker.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ const propTypes = {
165165

166166
draggable: PropTypes.bool,
167167

168+
/**
169+
* Sets whether this marker should track view changes true.
170+
*
171+
* @platform ios
172+
*/
173+
174+
tracksViewChanges: PropTypes.bool,
175+
168176
/**
169177
* Callback that is called when the user presses on the marker
170178
*/
@@ -264,7 +272,9 @@ class MapMarker extends React.Component {
264272

265273
return (
266274
<AIRMapMarker
267-
ref={ref => { this.marker = ref; }}
275+
ref={ref => {
276+
this.marker = ref;
277+
}}
268278
{...this.props}
269279
image={image}
270280
style={[styles.marker, this.props.style]}

lib/ios/AirGoogleMaps/AIRGoogleMapMarker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@property (nonatomic, assign) NSInteger zIndex;
3232
@property (nonatomic, assign) double opacity;
3333
@property (nonatomic, assign) BOOL draggable;
34+
@property (nonatomic, assign) BOOL tracksViewChanges;
3435

3536
- (void)showCalloutView;
3637
- (void)hideCalloutView;

lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ - (instancetype)init
3636
if ((self = [super init])) {
3737
_realMarker = [[AIRGMSMarker alloc] init];
3838
_realMarker.fakeMarker = self;
39+
_realMarker.tracksViewChanges = true;
3940
}
4041
return self;
4142
}
@@ -295,4 +296,12 @@ - (BOOL)draggable {
295296
return _realMarker.draggable;
296297
}
297298

299+
- (void)setTracksViewChanges:(BOOL)tracksViewChanges {
300+
_realMarker.tracksViewChanges = tracksViewChanges;
301+
}
302+
303+
- (BOOL)tracksViewChanges {
304+
return _realMarker.tracksViewChanges;
305+
}
306+
298307
@end

lib/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ - (UIView *)view
3737
RCT_EXPORT_VIEW_PROPERTY(anchor, CGPoint)
3838
RCT_EXPORT_VIEW_PROPERTY(zIndex, NSInteger)
3939
RCT_EXPORT_VIEW_PROPERTY(draggable, BOOL)
40+
RCT_EXPORT_VIEW_PROPERTY(tracksViewChanges, BOOL)
4041
RCT_EXPORT_VIEW_PROPERTY(opacity, double)
4142
RCT_EXPORT_VIEW_PROPERTY(onDragStart, RCTDirectEventBlock)
4243
RCT_EXPORT_VIEW_PROPERTY(onDrag, RCTDirectEventBlock)

0 commit comments

Comments
 (0)