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
52 changes: 41 additions & 11 deletions android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.LatLngBounds
import com.google.android.gms.maps.model.MapColorScheme
import com.google.android.gms.maps.model.MapStyleOptions
import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions
Expand Down Expand Up @@ -45,6 +46,7 @@ class GoogleMapsViewImpl(
private var pendingMinZoomLevel: Double? = null
private var pendingMaxZoomLevel: Double? = null
private var pendingMapPadding: RNMapPadding? = null
private var pendingMapType: Int? = null
private val pendingPolygons = mutableListOf<Pair<String, PolygonOptions>>()
private val pendingPolylines = mutableListOf<Pair<String, PolylineOptions>>()
private val pendingMarkers = mutableListOf<Pair<String, MarkerOptions>>()
Expand Down Expand Up @@ -245,6 +247,9 @@ class GoogleMapsViewImpl(
googleMap?.isTrafficEnabled = it
}
googleMap?.setMapStyle(pendingCustomMapStyle)
pendingMapType?.let {
googleMap?.mapType = it
}
pendingUserInterfaceStyle?.let {
googleMap?.mapColorScheme = it
}
Expand Down Expand Up @@ -282,20 +287,25 @@ class GoogleMapsViewImpl(
get() = googleMap?.isBuildingsEnabled ?: pendingBuildingEnabled
set(value) {
pendingBuildingEnabled = value
value?.let {
onUi {
onUi {
value?.let {
googleMap?.isBuildingsEnabled = it
}
?: run {
googleMap?.isBuildingsEnabled = false
}
}
}

var trafficEnabled: Boolean?
get() = googleMap?.isTrafficEnabled ?: pendingTrafficEnabled
set(value) {
pendingTrafficEnabled = value
value?.let {
onUi {
onUi {
value?.let {
googleMap?.isTrafficEnabled = it
} ?: run {
googleMap?.isTrafficEnabled = false
}
}
}
Expand All @@ -319,10 +329,11 @@ class GoogleMapsViewImpl(
get() = pendingUserInterfaceStyle
set(value) {
pendingUserInterfaceStyle = value

value?.let {
onUi {
onUi {
value?.let {
googleMap?.mapColorScheme = it
} ?: run {
googleMap?.mapColorScheme = MapColorScheme.FOLLOW_SYSTEM
}
}
}
Expand All @@ -331,9 +342,11 @@ class GoogleMapsViewImpl(
get() = pendingMinZoomLevel
set(value) {
pendingMinZoomLevel = value
value?.let {
onUi {
onUi {
value?.let {
googleMap?.setMinZoomPreference(it.toFloat())
} ?: run {
googleMap?.setMinZoomPreference(2.0f)
}
}
}
Expand All @@ -342,9 +355,11 @@ class GoogleMapsViewImpl(
get() = pendingMaxZoomLevel
set(value) {
pendingMaxZoomLevel = value
value?.let {
onUi {
onUi {
value?.let {
googleMap?.setMaxZoomPreference(it.toFloat())
} ?: run {
googleMap?.setMaxZoomPreference(21.0f)
}
}
}
Expand All @@ -362,6 +377,21 @@ class GoogleMapsViewImpl(
it.bottom.dpToPx().toInt(),
)
}
} ?: run {
googleMap?.setPadding(0, 0, 0, 0)
}
}

var mapType: Int?
get() = pendingMapType
set(value) {
pendingMapType = value
onUi {
value?.let {
googleMap?.mapType = it
} ?: run {
googleMap?.mapType = 1
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class RNGoogleMapsPlusView(
view.mapPadding = value
}

override var mapType: RNMapType?
get() = RNMapType.entries.firstOrNull { it.value == view.mapType }
set(value) {
value?.let {
view.mapType = it.value
}
}

override var markers: Array<RNMarker>? = emptyArray()
set(value) {
val prevById = field?.associateBy { it.id } ?: emptyMap()
Expand Down
1 change: 1 addition & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export default function App() {
zoom: 15,
}}
userInterfaceStyle={'light'}
mapType={'normal'}
maxZoomLevel={20}
minZoomLevel={0}
mapPadding={{
Expand Down
123 changes: 68 additions & 55 deletions ios/GoogleMapViewImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
private var pendingMinZoomLevel: Double?
private var pendingMaxZoomLevel: Double?
private var pendingMapPadding: RNMapPadding?
private var pendingMapType: GMSMapViewType?

private var pendingPolygons: [(id: String, polygon: GMSPolygon)] = []
private var pendingPolylines: [(id: String, polyline: GMSPolyline)] = []
Expand Down Expand Up @@ -131,6 +132,10 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
mapView.mapStyle = style
}

if let mapType = pendingMapType {
mapView.mapType = mapType
}

if let buildings = pendingBuildingEnabled {
mapView.isBuildingsEnabled = buildings
}
Expand Down Expand Up @@ -173,97 +178,105 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {

@MainActor
var buildingEnabled: Bool? {
get { mapView.isBuildingsEnabled }
set {
pendingBuildingEnabled = newValue
if let value = newValue {
mapView.isBuildingsEnabled = value
}
get { mapView.isBuildingsEnabled }
set {
pendingBuildingEnabled = newValue
if let value = newValue {
mapView.isBuildingsEnabled = value
}
}
}

@MainActor
var trafficEnabled: Bool? {
get { mapView.isTrafficEnabled }
set {
pendingTrafficEnabled = newValue
if let value = newValue {
mapView.isTrafficEnabled = value
}
get { mapView.isTrafficEnabled }
set {
pendingTrafficEnabled = newValue
if let value = newValue {
mapView.isTrafficEnabled = value
}
}
}

@MainActor
var customMapStyle: GMSMapStyle? {
get { pendingCustomMapStyle }
set {
pendingCustomMapStyle = newValue
if let style = newValue {
mapView.mapStyle = style
}
get { pendingCustomMapStyle }
set {
pendingCustomMapStyle = newValue
if let style = newValue {
mapView.mapStyle = style
}
}
}

@MainActor
var initialCamera: GMSCameraPosition? {
get { pendingInitialCamera }
set {
pendingInitialCamera = newValue
if let camera = newValue, !mapReady {
mapView.camera = camera
}
get { pendingInitialCamera }
set {
pendingInitialCamera = newValue
if let camera = newValue, !mapReady {
mapView.camera = camera
}
}
}

@MainActor
var userInterfaceStyle: UIUserInterfaceStyle? {
get { pendingUserInterfaceStyle }
set {
pendingUserInterfaceStyle = newValue
if let style = newValue {
mapView.overrideUserInterfaceStyle = style
}
get { pendingUserInterfaceStyle }
set {
pendingUserInterfaceStyle = newValue
if let style = newValue {
mapView.overrideUserInterfaceStyle = style
}
}
}

@MainActor
var minZoomLevel: Double? {
get { pendingMinZoomLevel }
set {
pendingMinZoomLevel = newValue
if let min = newValue, let max = pendingMaxZoomLevel {
mapView.setMinZoom(Float(min), maxZoom: Float(max))
}
get { pendingMinZoomLevel }
set {
pendingMinZoomLevel = newValue
if let min = newValue, let max = pendingMaxZoomLevel {
mapView.setMinZoom(Float(min), maxZoom: Float(max))
}
}
}

@MainActor
var maxZoomLevel: Double? {
get { pendingMaxZoomLevel }
set {
pendingMaxZoomLevel = newValue
if let max = newValue, let min = pendingMinZoomLevel {
mapView.setMinZoom(Float(min), maxZoom: Float(max))
}
get { pendingMaxZoomLevel }
set {
pendingMaxZoomLevel = newValue
if let max = newValue, let min = pendingMinZoomLevel {
mapView.setMinZoom(Float(min), maxZoom: Float(max))
}
}
}

@MainActor
var mapPadding: RNMapPadding? {
get { pendingMapPadding }
set {
pendingMapPadding = newValue
if let padding = newValue {
mapView.padding = UIEdgeInsets(
top: padding.top,
left: padding.left,
bottom: padding.bottom,
right: padding.right
)
} else {
mapView.padding = .zero
}
get { pendingMapPadding }
set {
pendingMapPadding = newValue
if let padding = newValue {
mapView.padding = UIEdgeInsets(
top: padding.top,
left: padding.left,
bottom: padding.bottom,
right: padding.right
)
} else {
mapView.padding = .zero
}
}
}

@MainActor var mapType: Int32? {
get { pendingMapType.map { Int32($0.rawValue) } }
set {
pendingMapType = GMSMapViewType(rawValue: UInt(newValue ?? 1))
mapView.mapType = pendingMapType ?? .normal
}
}

func setCamera(camera: RNCamera, animated: Bool, durationMS: Double) {
Expand Down
11 changes: 11 additions & 0 deletions ios/RNGoogleMapsPlusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
set { impl.mapPadding = newValue }
}

@MainActor
var mapType: RNMapType? {
get {
guard let value = impl.mapType else { return nil }
return RNMapType(rawValue: value)
}
set {
impl.mapType = newValue.map { Int32($0.rawValue) }
}
}

@MainActor
var markers: [RNMarker]? {
didSet {
Expand Down
2 changes: 2 additions & 0 deletions src/RNGoogleMapsPlusView.nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
RNRegion,
RNLocation,
RNMapErrorCode,
RNMapType,
} from './types';

export interface RNGoogleMapsPlusViewProps extends HybridViewProps {
Expand All @@ -27,6 +28,7 @@ export interface RNGoogleMapsPlusViewProps extends HybridViewProps {
minZoomLevel?: number;
maxZoomLevel?: number;
mapPadding?: RNMapPadding;
mapType?: RNMapType;
markers?: RNMarker[];
polygons?: RNPolygon[];
polylines?: RNPolyline[];
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type RNMapPadding = {
right: number;
};

export type RNMapType = 'none' | 'normal' | 'hybrid' | 'satellite' | 'terrain';

export type RNUserInterfaceStyle = 'light' | 'dark' | 'default';

export type RNFeatureType = string;
Expand Down
Loading