Skip to content

Commit

Permalink
Fix initial region android (react-native-maps#1563)
Browse files Browse the repository at this point in the history
* Fix initial region on android

* Fix initial region for android
  • Loading branch information
foyarash authored and codedre committed Aug 17, 2017
1 parent 2862c14 commit 667bf39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public void setRegion(AirMapView view, ReadableMap region) {
view.setRegion(region);
}

@ReactProp(name = "initialRegion")
public void setInitialRegion(AirMapView view, ReadableMap initialRegion) {
view.setInitialRegion(initialRegion);
}

@ReactProp(name = "mapType")
public void setMapType(AirMapView view, @Nullable String mapType) {
int typeId = MAP_TYPES.get(mapType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class AirMapView extends MapView implements GoogleMap.InfoWindowAdapter,
private boolean handlePanDrag = false;
private boolean moveOnMarkerPress = true;
private boolean cacheEnabled = false;
private boolean initialRegionSet = false;

private static final String[] PERMISSIONS = new String[]{
"android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"};
Expand Down Expand Up @@ -360,6 +361,13 @@ public synchronized void doDestroy() {
onDestroy();
}

public void setInitialRegion(ReadableMap initialRegion) {
if (!initialRegionSet && initialRegion != null) {
setRegion(initialRegion);
initialRegionSet = true;
}
}

public void setRegion(ReadableMap region) {
if (region == null) return;

Expand Down
5 changes: 4 additions & 1 deletion lib/components/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,13 @@ class MapView extends React.Component {
const { layout } = e.nativeEvent;
if (!layout.width || !layout.height) return;
if (this.state.isReady && !this.__layoutCalled) {
const region = this.props.region || this.props.initialRegion;
const { region, initialRegion } = this.props;
if (region) {
this.__layoutCalled = true;
this.map.setNativeProps({ region });
} else if (initialRegion) {
this.__layoutCalled = true;
this.map.setNativeProps({ initialRegion });
}
}
if (this.props.onLayout) {
Expand Down

1 comment on commit 667bf39

@petha
Copy link

@petha petha commented on 667bf39 Aug 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See issue react-native-maps#1577. This seem to break the IOS code.

Please sign in to comment.