Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ class GoogleMapsViewImpl(
}
initLocationCallbacks()
applyPending()
mapReady = true
onMapReady?.invoke(true)
}
mapReady = true
onMapReady?.invoke(true)
}

override fun onCameraMoveStarted(reason: Int) {
Expand Down Expand Up @@ -372,6 +372,8 @@ class GoogleMapsViewImpl(
}
}

var initialProps: RNInitialProps? = null

var uiSettings: RNMapUiSettings? = null
set(value) {
field = value
Expand Down Expand Up @@ -975,14 +977,14 @@ class GoogleMapsViewImpl(

fun destroyInternal() {
onUi {
locationHandler.stop()
markerBuilder.cancelAllJobs()
clearMarkers()
clearPolylines()
clearPolygons()
clearCircles()
clearHeatmaps()
clearKmlLayer()
locationHandler.stop()
googleMap?.apply {
setOnCameraMoveStartedListener(null)
setOnCameraMoveListener(null)
Expand All @@ -1003,6 +1005,7 @@ class GoogleMapsViewImpl(
}
super.removeAllViews()
reactContext.removeLifecycleEventListener(this)
initialized = false
}
}

Expand Down
19 changes: 14 additions & 5 deletions android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.rngooglemapsplus.extensions.toSize
class RNGoogleMapsPlusView(
val context: ThemedReactContext,
) : HybridRNGoogleMapsPlusViewSpec() {
private var propsInitialized = false
private var currentCustomMapStyle: String? = null
private var permissionHandler = PermissionHandler(context)
private var locationHandler = LocationHandler(context)
Expand All @@ -35,15 +36,23 @@ class RNGoogleMapsPlusView(
override val view =
GoogleMapsViewImpl(context, locationHandler, playServiceHandler, markerBuilder)

override fun afterUpdate() {
super.afterUpdate()
if (!propsInitialized) {
propsInitialized = true
view.initMapView(
initialProps?.mapId,
initialProps?.liteMode,
initialProps?.camera?.toCameraPosition(),
)
}
}

override var initialProps: RNInitialProps? = null
set(value) {
if (field == value) return
field = value
view.initMapView(
value?.mapId,
value?.liteMode,
value?.camera?.toCameraPosition(),
)
view.initialProps = value
}

override var uiSettings: RNMapUiSettings? = null
Expand Down
51 changes: 37 additions & 14 deletions example/src/components/MapWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { StyleSheet, useColorScheme, View } from 'react-native';
import { ActivityIndicator, StyleSheet, View } from 'react-native';
import {
GoogleMapsView,
type RNIndoorBuilding,
Expand All @@ -22,6 +22,7 @@ import {
import type { ViewProps } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { callback } from 'react-native-nitro-modules';
import { useTheme } from '@react-navigation/native';

type Props = ViewProps &
RNGoogleMapsPlusViewProps & {
Expand All @@ -31,8 +32,11 @@ type Props = ViewProps &

export default function MapWrapper(props: Props) {
const { children, ...rest } = props;
const scheme = useColorScheme();
const theme = useTheme();
const styles = getThemedStyles(theme);
const layout = useSafeAreaInsets();

const [mapReady, setMapReady] = React.useState(false);
const initialProps = useMemo(
() => ({
camera: {
Expand Down Expand Up @@ -96,15 +100,18 @@ export default function MapWrapper(props: Props) {
uiSettings={props.uiSettings ?? uiSettings}
style={[styles.map, props.style]}
userInterfaceStyle={
props.userInterfaceStyle ?? (scheme === 'dark' ? 'dark' : 'light')
props.userInterfaceStyle ?? (theme.dark ? 'dark' : 'light')
}
mapType={props.mapType ?? 'normal'}
mapZoomConfig={props.mapZoomConfig ?? mapZoomConfig}
mapPadding={props.mapPadding ?? mapPadding}
locationConfig={props.locationConfig ?? locationConfig}
onMapReady={callback(
props.onMapReady ?? {
f: (ready: boolean) => console.log('Map is ready! ' + ready),
f: (ready: boolean) => {
console.log('Map is ready! ' + ready);
setMapReady(true);
},
}
)}
onMapError={callback(
Expand Down Expand Up @@ -197,17 +204,33 @@ export default function MapWrapper(props: Props) {
)}
/>
{children}
{!mapReady && (
<View style={styles.loadingOverlay}>
<ActivityIndicator size="large" color={theme.colors.primary} />
</View>
)}
</View>
);
}

const styles = StyleSheet.create({
container: { flex: 1 },
map: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
},
});
const getThemedStyles = (theme: any) =>
StyleSheet.create({
container: {
flex: 1,
backgroundColor: theme.colors.background,
},
map: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
},
loadingOverlay: {
...StyleSheet.absoluteFillObject,
justifyContent: 'center',
alignItems: 'center',
zIndex: 10,
backgroundColor: theme.dark ? 'rgba(0,0,0,0.6)' : 'rgba(255,255,255,0.7)',
},
});
1 change: 0 additions & 1 deletion ios/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ disabled_rules:
- cyclomatic_complexity
- function_body_length
- closure_parameter_position
- todo

identifier_name:
min_length:
Expand Down
38 changes: 24 additions & 14 deletions ios/GoogleMapViewImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ GMSIndoorDisplayDelegate {
mapView?.camera
}

@MainActor
var initialProps: RNInitialProps? {
didSet {}
}

@MainActor
var uiSettings: RNMapUiSettings? {
didSet {
Expand Down Expand Up @@ -629,7 +634,10 @@ GMSIndoorDisplayDelegate {

@MainActor
func clearHeatmaps() {
heatmapsById.values.forEach { $0.map = nil }
heatmapsById.values.forEach {
$0.clearTileCache()
$0.map = nil
}
heatmapsById.removeAll()
pendingHeatmaps.removeAll()
}
Expand Down Expand Up @@ -671,16 +679,21 @@ GMSIndoorDisplayDelegate {
}

func deinitInternal() {
markerBuilder.cancelAllIconTasks()
clearMarkers()
clearPolylines()
clearPolygons()
clearCircles()
clearHeatmaps()
locationHandler.stop()
mapView?.clear()
mapView?.delegate = nil
mapView = nil
onMain {
self.locationHandler.stop()
self.markerBuilder.cancelAllIconTasks()
self.clearMarkers()
self.clearPolylines()
self.clearPolygons()
self.clearCircles()
self.clearHeatmaps()
self.clearKmlLayers()
self.mapView?.clear()
self.mapView?.indoorDisplay.delegate = nil
self.mapView?.delegate = nil
self.mapView = nil
self.initialized = false
}
}

@objc private func appDidBecomeActive() {
Expand All @@ -696,9 +709,6 @@ GMSIndoorDisplayDelegate {
override func didMoveToWindow() {
super.didMoveToWindow()
if window != nil {
if mapView != nil && mapReady {
onMapReady?(true)
}
locationHandler.start()
} else {
locationHandler.stop()
Expand Down
25 changes: 14 additions & 11 deletions ios/RNGoogleMapsPlusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
private let permissionHandler: PermissionHandler
private let locationHandler: LocationHandler

private var propsInitialized = false
private let markerBuilder = MapMarkerBuilder()
private let polylineBuilder = MapPolylineBuilder()
private let polygonBuilder = MapPolygonBuilder()
Expand All @@ -29,21 +30,23 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
)
}

/*
/// TODO: prepareForRecycle
override func prepareForRecycle() {
impl.clearAll()
}
*/
func afterUpdate() {
if !propsInitialized {
propsInitialized = true
Task { @MainActor in
impl.initMapView(
mapId: self.initialProps?.mapId,
liteMode: self.initialProps?.liteMode,
camera: self.initialProps?.camera?.toGMSCameraPosition(current: nil)
)
}
}
}

@MainActor
var initialProps: RNInitialProps? {
didSet {
impl.initMapView(
mapId: initialProps?.mapId,
liteMode: initialProps?.liteMode,
camera: initialProps?.camera?.toGMSCameraPosition(current: nil)
)
impl.initialProps = initialProps
}
}

Expand Down
Loading
Loading