Skip to content

Commit 29ae3e8

Browse files
authored
Merge pull request react-native-maps#546 from tt-sport-mobile/master
Support Android LiteMode
2 parents a4399c0 + 0ca660f commit 29ae3e8

File tree

9 files changed

+118
-4
lines changed

9 files changed

+118
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ Markers are draggable, and emit continuous drag events to update other UI during
240240

241241
![](http://i.giphy.com/l2JImnZxdv1WbpQfC.gif) ![](http://i.giphy.com/l2JIhv4Jx6Ugx1EGI.gif)
242242

243+
### Lite Mode ( Android )
244+
245+
Enable lite mode on Android with `liteMode` prop. Ideal when having multiple maps in a View or ScrollView.
246+
247+
![](http://i.giphy.com/qZ2lAf18s89na.gif)
243248

244249
## Component API
245250

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.airbnb.android.react.maps;
2+
3+
import com.facebook.react.bridge.ReactApplicationContext;
4+
import com.google.android.gms.maps.GoogleMapOptions;
5+
6+
public class AirMapLiteManager extends AirMapManager {
7+
8+
private static final String REACT_CLASS = "AIRMapLite";
9+
10+
@Override
11+
public String getName() {
12+
return REACT_CLASS;
13+
}
14+
15+
public AirMapLiteManager(ReactApplicationContext context) {
16+
super(context);
17+
this.googleMapOptions = new GoogleMapOptions().liteMode(true);
18+
}
19+
20+
}

android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.facebook.react.uimanager.annotations.ReactProp;
1717
import com.facebook.react.uimanager.events.RCTEventEmitter;
1818
import com.google.android.gms.maps.GoogleMap;
19+
import com.google.android.gms.maps.GoogleMapOptions;
1920
import com.google.android.gms.maps.MapsInitializer;
2021
import com.google.android.gms.maps.model.LatLng;
2122
import com.google.android.gms.maps.model.LatLngBounds;
@@ -43,8 +44,11 @@ public class AirMapManager extends ViewGroupManager<AirMapView> {
4344

4445
private final ReactApplicationContext appContext;
4546

47+
protected GoogleMapOptions googleMapOptions;
48+
4649
public AirMapManager(ReactApplicationContext context) {
4750
this.appContext = context;
51+
this.googleMapOptions = new GoogleMapOptions();
4852
}
4953

5054
@Override
@@ -63,7 +67,7 @@ protected AirMapView createViewInstance(ThemedReactContext context) {
6367
emitMapError("Map initialize error", "map_init_error");
6468
}
6569

66-
return new AirMapView(context, this.appContext, this);
70+
return new AirMapView(context, this.appContext, this, this.googleMapOptions);
6771
}
6872

6973
@Override

android/src/main/java/com/airbnb/android/react/maps/AirMapView.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.android.gms.maps.CameraUpdate;
3232
import com.google.android.gms.maps.CameraUpdateFactory;
3333
import com.google.android.gms.maps.GoogleMap;
34+
import com.google.android.gms.maps.GoogleMapOptions;
3435
import com.google.android.gms.maps.MapView;
3536
import com.google.android.gms.maps.OnMapReadyCallback;
3637
import com.google.android.gms.maps.Projection;
@@ -76,8 +77,9 @@ public class AirMapView extends MapView implements GoogleMap.InfoWindowAdapter,
7677
private final ThemedReactContext context;
7778
private final EventDispatcher eventDispatcher;
7879

79-
public AirMapView(ThemedReactContext context, Context appContext, AirMapManager manager) {
80-
super(appContext);
80+
public AirMapView(ThemedReactContext context, Context appContext, AirMapManager manager, GoogleMapOptions googleMapOptions) {
81+
super(appContext, googleMapOptions);
82+
8183
this.manager = manager;
8284
this.context = context;
8385

android/src/main/java/com/airbnb/android/react/maps/MapsPackage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext
3737
AirMapPolygonManager polygonManager = new AirMapPolygonManager(reactContext);
3838
AirMapCircleManager circleManager = new AirMapCircleManager(reactContext);
3939
AirMapManager mapManager = new AirMapManager(reactContext);
40+
AirMapLiteManager mapLiteManager = new AirMapLiteManager(reactContext);
4041

4142
return Arrays.<ViewManager>asList(
4243
calloutManager,
4344
annotationManager,
4445
polylineManager,
4546
polygonManager,
4647
circleManager,
47-
mapManager);
48+
mapManager,
49+
mapLiteManager);
4850
}
4951
}

components/MapView.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ const propTypes = {
222222
longitudeDelta: PropTypes.number.isRequired,
223223
}),
224224

225+
/**
226+
* A Boolean indicating whether to use liteMode for android
227+
* Default value is `false`
228+
*
229+
* @platform android
230+
*/
231+
liteMode: PropTypes.bool,
232+
225233
/**
226234
* Maximum size of area that can be displayed.
227235
*
@@ -457,6 +465,15 @@ class MapView extends React.Component {
457465
};
458466
}
459467

468+
if (Platform.OS === 'android' && this.props.liteMode) {
469+
return (
470+
<AIRMapLite
471+
ref={ref => { this.map = ref; }}
472+
{...props}
473+
/>
474+
);
475+
}
476+
460477
return (
461478
<AIRMap
462479
ref={ref => { this.map = ref; }}
@@ -477,6 +494,14 @@ const AIRMap = requireNativeComponent('AIRMap', MapView, {
477494
},
478495
});
479496

497+
const AIRMapLite = requireNativeComponent('AIRMapLite', MapView, {
498+
nativeOnly: {
499+
onChange: true,
500+
onMapReady: true,
501+
handlePanDrag: true,
502+
},
503+
});
504+
480505
MapView.Marker = MapMarker;
481506
MapView.Polyline = MapPolyline;
482507
MapView.Polygon = MapPolygon;

docs/mapview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
|---|---|---|---|
77
| `region` | `Region` | | The region to be displayed by the map. <br/><br/>The region is defined by the center coordinates and the span of coordinates to display.
88
| `initialRegion` | `Region` | | The initial region to be displayed by the map. Use this prop instead of `region` only if you don't want to control the viewport of the map besides the initial region.<br/><br/> Changing this prop after the component has mounted will not result in a region change.<br/><br/> This is similar to the `initialValue` prop of a text input.
9+
| `liteMode` | `Boolean` | `false` | Enable lite mode. **Note**: Android only.
910
| `mapType` | `String` | `"standard"` | The map type to be displayed. <br/><br/> - standard: standard road map (default)<br/> - satellite: satellite view<br/> - hybrid: satellite view with roads and points of interest overlayed<br/> - terrain: (Android only) topographic view
1011
| `showsUserLocation` | `Boolean` | `false` | If `true` the app will ask for the user's location. **NOTE**: You need to add `NSLocationWhenInUseUsageDescription` key in Info.plist to enable geolocation, otherwise it is going to *fail silently*!
1112
| `followsUserLocation` | `Boolean` | `false` | If `true` the map will focus on the user's location. This only works if `showsUserLocation` is true and the user has shared their location. **Note**: iOS only.

example/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import CachedMap from './examples/CachedMap';
2323
import LoadingMap from './examples/LoadingMap';
2424
import TakeSnapshot from './examples/TakeSnapshot';
2525
import FitToSuppliedMarkers from './examples/FitToSuppliedMarkers';
26+
import LiteMapView from './examples/LiteMapView';
2627

2728
class App extends React.Component {
2829
constructor(props) {
@@ -93,6 +94,7 @@ class App extends React.Component {
9394
[CachedMap, 'Cached Map'],
9495
[LoadingMap, 'Map with loading'],
9596
[FitToSuppliedMarkers, 'Focus Map On Markers'],
97+
[LiteMapView, 'Android Lite MapView'],
9698
]);
9799
}
98100
}

example/examples/LiteMapView.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
import {
3+
StyleSheet,
4+
Dimensions,
5+
ScrollView,
6+
} from 'react-native';
7+
8+
import MapView from 'react-native-maps';
9+
10+
const { width, height } = Dimensions.get('window');
11+
12+
const ASPECT_RATIO = width / height;
13+
const LATITUDE = 37.78825;
14+
const LONGITUDE = -122.4324;
15+
const LATITUDE_DELTA = 0.0922;
16+
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;
17+
18+
const SAMPLE_REGION = {
19+
latitude: LATITUDE,
20+
longitude: LONGITUDE,
21+
latitudeDelta: LATITUDE_DELTA,
22+
longitudeDelta: LONGITUDE_DELTA,
23+
};
24+
25+
class LiteMapView extends React.Component {
26+
render() {
27+
const maps = [];
28+
for (let i = 0; i < 10; i++) {
29+
maps.push(
30+
<MapView
31+
liteMode
32+
key={`map_${i}`}
33+
style={styles.map}
34+
initialRegion={SAMPLE_REGION}
35+
/>
36+
);
37+
}
38+
return (
39+
<ScrollView style={StyleSheet.absoluteFillObject}>
40+
{maps}
41+
</ScrollView>
42+
);
43+
}
44+
}
45+
46+
const styles = StyleSheet.create({
47+
map: {
48+
height: 200,
49+
marginVertical: 50,
50+
},
51+
});
52+
53+
module.exports = LiteMapView;

0 commit comments

Comments
 (0)