Skip to content

Commit

Permalink
Merge branch 'main' into fix-addlistener
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Oct 25, 2023
2 parents 8d26183 + 1ca3fbf commit a12d1e1
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 7 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/dev-releases-for-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Release Dev Build for PR

on:
pull_request:
types:
- opened
- synchronize

jobs:
setup:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
plugins: ${{ steps.packages.outputs.paths }}
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@ce177499ccf9fd2aded3b0426c97e5434c2e8a73
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Get Latest
uses: actions/setup-node@v3
with:
node-version: 18.18.0
- uses: actions/checkout@v3
- name: Restore Dependency Cache
id: cache-modules
uses: actions/cache@v3
with:
path: |
node_modules
*/node_modules
key: ${{ runner.os }}-dependency-caching-${{ hashFiles('package.json', '*/package.json') }}
- run: npm install
- id: files
uses: tj-actions/changed-files@v37
with:
json: true
write_output_files: true
- id: catjson
run: |
echo "FILES_JSON=$(cat .github/outputs/all_changed_files.json)" >> $GITHUB_OUTPUT
- id: packages
uses: ./.github/actions/changed-packages
with:
files: ${{ steps.catjson.outputs.FILES_JSON }}

release-dev-of-plugins:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
pull-requests: write
needs:
- setup
strategy:
matrix:
plugin: ${{ fromJson(needs.setup.outputs.plugins) }}
steps:
- uses: actions/setup-node@v3
with:
node-version: 18.18.0
- uses: actions/checkout@v3
- name: Restore Dependency Cache
id: cache-modules
uses: actions/cache@v3
with:
path: |
node_modules
*/node_modules
key: ${{ runner.os }}-dependency-caching-${{ hashFiles('package.json', '*/package.json') }}
- run: npm install
- env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
npm version prerelease --no-git-tag-version -f --preid dev-$PR_NUMBER-$(date +%Y%m%dT%H%M%S)
npm publish --tag dev --dry-run
working-directory: ${{ matrix.plugin }}
- name: get-npm-version
id: package-version
uses: martinbeentjes/[email protected]
with:
path: ${{ matrix.plugin }}
- uses: mshick/add-pr-comment@v2
with:
message: |
Released dev build of ${{ matrix.plugin }} with dev version: ${{ steps.package-version.outputs.current-version }}
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ See [`CONTRIBUTING.md`](https://github.com/ionic-team/capacitor/blob/HEAD/CONTRI
brew install swiftlint
```

Sometimes, it may be necessary to work on Capacitor in parellel with the plugin(s). In this case, a few extra steps are necessary:
Sometimes, it may be necessary to work on Capacitor in parallel with the plugin(s). In this case, a few extra steps are necessary:

4. Follow the Capacitor repo's [local setup instructions](https://github.com/ionic-team/capacitor/blob/HEAD/CONTRIBUTING.md#local-setup).
5. Toggle each plugin to use your local copy of Capacitor.
Expand Down Expand Up @@ -47,13 +47,13 @@ To aid in managing these plugins, this repo has a variety of scripts (located in
#### `npm run set-capacitor-version "<version>"`
This script is for setting the version (or version range) of Capacitor packages in each plugin's `package.json`. It will also run `lerna bootstrap` for you.
This script is for setting the version (or version range) of Capacitor packages in each plugin's `package.json`.

#### `npm run toggle-local`

> :memo: Requires [Capacitor](https://github.com/ionic-team/capacitor/) to be cloned in a sibling directory.

This script is for switching between Capacitor packages from npm and Capacitor packages installed locally. It will also run `lerna bootstrap` for you.
This script is for switching between Capacitor packages from npm and Capacitor packages installed locally.

> If you get npm errors, you can try installing from scratch:
>
Expand Down
3 changes: 3 additions & 0 deletions google-maps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,9 @@ For iOS and Android only the config options declared on <a href="#googlemapconfi
| **`androidLiteMode`** | <code>boolean</code> | Enables image-based lite mode on Android. | <code>false</code> | |
| **`devicePixelRatio`** | <code>number</code> | Override pixel ratio for native map. | | |
| **`styles`** | <code>MapTypeStyle[] \| null</code> | Styles to apply to each of the default map types. Note that for satellite, hybrid and terrain modes, these styles will only apply to labels and geometry. | | 4.3.0 |
| **`mapId`** | <code>string</code> | A map id associated with a specific map style or feature. [Use Map IDs](https://developers.google.com/maps/documentation/get-map-id) Only for Web. | | 6.0.0 |
| **`androidMapId`** | <code>string</code> | A map id associated with a specific map style or feature. [Use Map IDs](https://developers.google.com/maps/documentation/get-map-id) Only for Android. | | 6.0.0 |
| **`iOSMapId`** | <code>string</code> | A map id associated with a specific map style or feature. [Use Map IDs](https://developers.google.com/maps/documentation/get-map-id) Only for iOS. | | 6.0.0 |


#### LatLng
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.getcapacitor.annotation.CapacitorPlugin
import com.getcapacitor.annotation.Permission
import com.getcapacitor.annotation.PermissionCallback
import com.google.android.gms.maps.MapsInitializer
import com.google.android.gms.maps.OnMapsSdkInitializedCallback
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.LatLngBounds
import kotlinx.coroutines.CoroutineScope
Expand All @@ -29,7 +30,7 @@ import org.json.JSONObject
),
],
)
class CapacitorGoogleMapsPlugin : Plugin() {
class CapacitorGoogleMapsPlugin : Plugin(), OnMapsSdkInitializedCallback {
private var maps: HashMap<String, CapacitorGoogleMap> = HashMap()
private var cachedTouchEvents: HashMap<String, MutableList<MotionEvent>> = HashMap()
private val tag: String = "CAP-GOOGLE-MAPS"
Expand All @@ -43,7 +44,8 @@ class CapacitorGoogleMapsPlugin : Plugin() {
override fun load() {
super.load()

MapsInitializer.initialize(this.context, MapsInitializer.Renderer.LATEST, null)
MapsInitializer.initialize(this.context, MapsInitializer.Renderer.LATEST, this)


this.bridge.webView.setOnTouchListener(
object : View.OnTouchListener {
Expand Down Expand Up @@ -90,6 +92,13 @@ class CapacitorGoogleMapsPlugin : Plugin() {
)
}

override fun onMapsSdkInitialized(renderer: MapsInitializer.Renderer) {
when (renderer) {
MapsInitializer.Renderer.LATEST -> Logger.debug("Capacitor Google Maps", "Latest Google Maps renderer enabled")
MapsInitializer.Renderer.LEGACY -> Logger.debug("Capacitor Google Maps", "Legacy Google Maps renderer enabled - Cloud based map styling and advanced drawing not available")
}
}

override fun handleOnStart() {
super.handleOnStart()
maps.forEach { it.value.onStart() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GoogleMapConfig(fromJSONObject: JSONObject) {
var liteMode: Boolean = false
var devicePixelRatio: Float = 1.00f
var styles: String? = null
var mapId: String? = null

init {
if (!fromJSONObject.has("width")) {
Expand Down Expand Up @@ -81,8 +82,14 @@ class GoogleMapConfig(fromJSONObject: JSONObject) {
center = LatLng(lat, lng)

val cameraPosition = CameraPosition(center, zoom.toFloat(), 0.0F, 0.0F)
googleMapOptions = GoogleMapOptions().camera(cameraPosition).liteMode(liteMode)

styles = fromJSONObject.getString("styles")

mapId = fromJSONObject.getString("androidMapId")

googleMapOptions = GoogleMapOptions().camera(cameraPosition).liteMode(liteMode)
if (mapId != null) {
googleMapOptions?.mapId(mapId!!)
}
}
}
3 changes: 3 additions & 0 deletions google-maps/ios/Plugin/GoogleMapConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public struct GoogleMapConfig: Codable {
let center: LatLng
let zoom: Double
let styles: String?
var mapId: String?

init(fromJSObject: JSObject) throws {
guard let width = fromJSObject["width"] as? Double else {
Expand Down Expand Up @@ -50,5 +51,7 @@ public struct GoogleMapConfig: Codable {
} else {
self.styles = nil
}

self.mapId = fromJSObject["iOSMapId"] as? String
}
}
10 changes: 9 additions & 1 deletion google-maps/ios/Plugin/Map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class GMViewController: UIViewController {
var GMapView: GMSMapView!
var cameraPosition: [String: Double]!
var minimumClusterSize: Int?
var mapId: String?

private var clusterManager: GMUClusterManager?

Expand All @@ -25,7 +26,13 @@ class GMViewController: UIViewController {

let camera = GMSCameraPosition.camera(withLatitude: cameraPosition["latitude"] ?? 0, longitude: cameraPosition["longitude"] ?? 0, zoom: Float(cameraPosition["zoom"] ?? 12))
let frame = CGRect(x: mapViewBounds["x"] ?? 0, y: mapViewBounds["y"] ?? 0, width: mapViewBounds["width"] ?? 0, height: mapViewBounds["height"] ?? 0)
self.GMapView = GMSMapView.map(withFrame: frame, camera: camera)
if let id = mapId {
let gmsId = GMSMapID(identifier: id)
self.GMapView = GMSMapView(frame: frame, mapID: gmsId, camera: camera)
} else {
self.GMapView = GMSMapView(frame: frame, camera: camera)
}

self.view = GMapView
}

Expand Down Expand Up @@ -85,6 +92,7 @@ public class Map {
self.config = config
self.delegate = delegate
self.mapViewController = GMViewController()
self.mapViewController.mapId = config.mapId

self.render()
}
Expand Down
30 changes: 30 additions & 0 deletions google-maps/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,36 @@ export interface GoogleMapConfig extends google.maps.MapOptions {
* @since 4.3.0
*/
styles?: google.maps.MapTypeStyle[] | null;
/**
* A map id associated with a specific map style or feature.
*
* [Use Map IDs](https://developers.google.com/maps/documentation/get-map-id)
*
* Only for Web.
*
* @since 6.0.0
*/
mapId?: string;
/**
* A map id associated with a specific map style or feature.
*
* [Use Map IDs](https://developers.google.com/maps/documentation/get-map-id)
*
* Only for Android.
*
* @since 6.0.0
*/
androidMapId?: string;
/**
* A map id associated with a specific map style or feature.
*
* [Use Map IDs](https://developers.google.com/maps/documentation/get-map-id)
*
* Only for iOS.
*
* @since 6.0.0
*/
iOSMapId?: string;
}

/**
Expand Down
1 change: 1 addition & 0 deletions google-maps/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ export class CapacitorGoogleMapsWeb
async create(_args: CreateMapArgs): Promise<void> {
console.log(`Create map: ${_args.id}`);
await this.importGoogleLib(_args.apiKey, _args.region, _args.language);

this.maps[_args.id] = {
map: new window.google.maps.Map(_args.element, { ..._args.config }),
element: _args.element,
Expand Down

0 comments on commit a12d1e1

Please sign in to comment.