Skip to content

Commit

Permalink
feat: add new google maps renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
monholm committed Mar 7, 2022
1 parent 88a8720 commit 81f1523
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ declare module 'react-native-maps' {
MUTEDSTANDARD: MapTypes;
};

export const enableLatestRenderer: () => Promise<'LATEST' | 'LEGACY'> | void;

export const PROVIDER_DEFAULT: null;
export const PROVIDER_GOOGLE: 'google';
}
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import MapView, {
Animated,
MAP_TYPES,
ProviderPropType,
enableLatestRenderer,
} from './lib/components/MapView';
import Marker from './lib/components/MapMarker.js';
import Overlay from './lib/components/MapOverlay.js';
Expand All @@ -19,7 +20,7 @@ export { default as AnimatedRegion } from './lib/components/AnimatedRegion.js';
export { default as Geojson } from './lib/components/Geojson.js';

export { Marker, Overlay };
export { Animated, MAP_TYPES, ProviderPropType };
export { Animated, MAP_TYPES, ProviderPropType, enableLatestRenderer };

export const PROVIDER_GOOGLE = MapView.PROVIDER_GOOGLE;
export const PROVIDER_DEFAULT = MapView.PROVIDER_DEFAULT;
Expand Down
8 changes: 4 additions & 4 deletions lib/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ android {
}

dependencies {
def work_version = "2.7.1"
def work_version = safeExtGet('targetSdkVersion', 27) < 31 ? "2.5.0" : "2.7.1"
def supportLibVersion = safeExtGet('supportLibVersion', '28.0.0')
def supportLibMajorVersion = supportLibVersion.split('\\.')[0] as int
def appCompatLibName = (supportLibMajorVersion < 20) ? "androidx.appcompat:appcompat" : "com.android.support:appcompat-v7"
implementation "$appCompatLibName:$supportLibVersion"
implementation('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}
implementation "com.google.android.gms:play-services-base:${safeExtGet('playServicesVersion', '17.0.0')}"
implementation "com.google.android.gms:play-services-maps:${safeExtGet('playServicesVersion', '17.0.0')}"
implementation "com.google.android.gms:play-services-location:17.0.0"
implementation "com.google.android.gms:play-services-base:${safeExtGet('playServicesVersion', '18.0.1')}"
implementation "com.google.android.gms:play-services-maps:${safeExtGet('playServicesVersion', '18.0.2')}"
implementation "com.google.android.gms:play-services-location:19.0.1"
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation "androidx.work:work-runtime:$work_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.net.Uri;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Log;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -21,6 +22,7 @@
import com.facebook.react.uimanager.UIBlock;
import com.facebook.react.uimanager.UIManagerModule;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;

Expand Down Expand Up @@ -352,4 +354,22 @@ public void execute(NativeViewHierarchyManager nvhm)
}
});
}

@ReactMethod
public void enableLatestRenderer(final Promise promise) {
final ReactApplicationContext context = getReactApplicationContext();

UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
uiManager.addUIBlock(new UIBlock()
{
@Override
public void execute(NativeViewHierarchyManager nvhm)
{
MapsInitializer.initialize(context, MapsInitializer.Renderer.LATEST, (MapsInitializer.Renderer renderer) -> {
Log.d("AirMapRenderer", renderer.toString());
promise.resolve(renderer.toString());
});
}
});
}
}
5 changes: 5 additions & 0 deletions lib/components/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,11 @@ if (!NativeModules.UIManager.getViewManagerConfig) {

export const Animated = RNAnimated.createAnimatedComponent(MapView);

export const enableLatestRenderer = () => {
if (Platform.OS !== 'android') return;
return NativeModules.AirMapModule.enableLatestRenderer();
};

export const ProviderPropType = PropTypes.oneOf(
Object.values(ProviderConstants)
);
Expand Down

0 comments on commit 81f1523

Please sign in to comment.