Skip to content

Commit

Permalink
Merge branch 'googlemaps:main' into set-initial-map-padding
Browse files Browse the repository at this point in the history
  • Loading branch information
kkris authored Oct 21, 2023
2 parents ae012d1 + 99646dd commit 2e1422e
Show file tree
Hide file tree
Showing 33 changed files with 607 additions and 158 deletions.
28 changes: 14 additions & 14 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@

version: 2
updates:
- package-ecosystem: gradle
directory: "/./app"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
commit-message:
prefix: chore(deps)
- package-ecosystem: gradle
directory: "/./maps-compose"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
commit-message:
prefix: chore(deps)
- package-ecosystem: "gradle" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
open-pull-requests-limit: 10
commit-message:
prefix: chore(deps)
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
open-pull-requests-limit: 10
commit-message:
prefix: chore(deps)
8 changes: 4 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ jobs:
- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1.0.4

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v2.3.1
with:
java-version: '11'
java-version: '17'
distribution: 'adopt'

# Run dokka and create tar
- name: Generate documentation
run: |
./gradlew dokkaHtml
./gradlew dokkaHtmlMultiModule
echo "Creating tar for generated docs"
cd $GITHUB_WORKSPACE/maps-compose/build/dokka/html && tar cvf ~/maps-compose-docs.tar .
cd $GITHUB_WORKSPACE/build/dokka/htmlMultiModule && tar cvf ~/maps-compose-docs.tar .
echo "Unpacking tar into gh-pages branch"
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/instrumentation-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1.0.4

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v2.3.1
with:
java-version: '11'
java-version: '17'
distribution: 'adopt'

- name: Inject Maps API Key
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
with:
token: ${{ secrets.SYNCED_GITHUB_TOKEN_REPO }}
- uses: gradle/wrapper-validation-action@v1.0.4
- name: Set up JDK 17
uses: actions/setup-java@v2.3.1
with:
java-version: '17'
distribution: 'adopt'
- name: Create .gpg key
run: |
echo $GPG_KEY_ARMOR | base64 --decode > ./release.asc
Expand All @@ -49,6 +54,9 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install conventionalcommits
run: npm i -D conventional-changelog-conventionalcommits

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3.4.1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1.0.4

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'

- name: Build modules
Expand Down
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ This repository contains [Jetpack Compose][jetpack-compose] components for the [

## Installation

You no longer need to specify the Maps SDK for Android or its Utility Library as separate dependencies, since `maps-compose` and `maps-compose-utils` pull in the appropriate versions of these respectively.

```groovy
dependencies {
implementation 'com.google.maps.android:maps-compose:2.12.0'
// Make sure to also include the latest version of the Maps SDK for Android
// See latest version at https://goo.gle/android-maps-sdk-version
implementation 'com.google.maps.android:maps-compose:3.1.1'
// Optionally, you can include the Compose utils library for Clustering, etc.
implementation 'com.google.maps.android:maps-compose-utils:2.12.0'
implementation 'com.google.maps.android:maps-compose-utils:3.1.1'
// Optionally, you can include the widgets library for ScaleBar, etc.
implementation 'com.google.maps.android:maps-compose-widgets:2.12.0'
implementation 'com.google.maps.android:maps-compose-widgets:3.1.1'
}
```

Expand Down Expand Up @@ -172,6 +171,26 @@ GoogleMap(
}
```

You can also customize the marker you want to add by using `MarkerComposable`.

```kotlin
val state = MyState()

GoogleMap(
//...
) {
MarkerComposable(
keys = arrayOf(state),
state = MarkerState(position = LatLng(-34, 151)),
) {
MyCustomMarker(state)
}
}
```
As this Composable is backed by a rendering of your Composable into a Bitmap, it will not render
your Composable every recomposition. So to trigger a new render of your Composable, you can pass
all variables that your Composable depends on to trigger a render whenever one of them change.

</details>

<details>
Expand Down
5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ plugins {

android {
namespace "com.google.maps.android.compose"
compileSdk 33
compileSdk 34

defaultConfig {
minSdk 21
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -45,7 +45,6 @@ dependencies {
implementation libs.kotlin
implementation libs.material
implementation libs.maps.ktx.std
implementation libs.maps.utils
implementation libs.androidx.compose.ui.preview.tooling
debugImplementation libs.androidx.compose.ui.tooling

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package com.google.maps.android.compose

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertIsDisplayed
Expand Down Expand Up @@ -78,7 +80,7 @@ class GoogleMapViewTests {
initMap()
assertEquals(CameraMoveStartedReason.NO_MOVEMENT_YET, cameraPositionState.cameraMoveStartedReason)
zoom(shouldAnimate = true, zoomIn = true) {
composeTestRule.waitUntil(1000) {
composeTestRule.waitUntil(timeout2) {
cameraPositionState.isMoving
}
assertTrue(cameraPositionState.isMoving)
Expand All @@ -90,10 +92,10 @@ class GoogleMapViewTests {
fun testCameraReportsNotMoving() {
initMap()
zoom(shouldAnimate = true, zoomIn = true) {
composeTestRule.waitUntil(1000) {
composeTestRule.waitUntil(timeout2) {
cameraPositionState.isMoving
}
composeTestRule.waitUntil(5000) {
composeTestRule.waitUntil(timeout5) {
!cameraPositionState.isMoving
}
assertFalse(cameraPositionState.isMoving)
Expand All @@ -104,10 +106,10 @@ class GoogleMapViewTests {
fun testCameraZoomInAnimation() {
initMap()
zoom(shouldAnimate = true, zoomIn = true) {
composeTestRule.waitUntil(1000) {
composeTestRule.waitUntil(timeout2) {
cameraPositionState.isMoving
}
composeTestRule.waitUntil(3000) {
composeTestRule.waitUntil(timeout3) {
!cameraPositionState.isMoving
}
assertEquals(
Expand All @@ -122,10 +124,10 @@ class GoogleMapViewTests {
fun testCameraZoomIn() {
initMap()
zoom(shouldAnimate = false, zoomIn = true) {
composeTestRule.waitUntil(1000) {
composeTestRule.waitUntil(timeout2) {
cameraPositionState.isMoving
}
composeTestRule.waitUntil(3000) {
composeTestRule.waitUntil(timeout3) {
!cameraPositionState.isMoving
}
assertEquals(
Expand All @@ -140,10 +142,10 @@ class GoogleMapViewTests {
fun testCameraZoomOut() {
initMap()
zoom(shouldAnimate = false, zoomIn = false) {
composeTestRule.waitUntil(1000) {
composeTestRule.waitUntil(timeout2) {
cameraPositionState.isMoving
}
composeTestRule.waitUntil(3000) {
composeTestRule.waitUntil(timeout3) {
!cameraPositionState.isMoving
}
assertEquals(
Expand All @@ -158,10 +160,10 @@ class GoogleMapViewTests {
fun testCameraZoomOutAnimation() {
initMap()
zoom(shouldAnimate = true, zoomIn = false) {
composeTestRule.waitUntil(1000) {
composeTestRule.waitUntil(timeout2) {
cameraPositionState.isMoving
}
composeTestRule.waitUntil(3000) {
composeTestRule.waitUntil(timeout3) {
!cameraPositionState.isMoving
}
assertEquals(
Expand Down Expand Up @@ -210,6 +212,29 @@ class GoogleMapViewTests {
}
}

@Test(expected = IllegalStateException::class)
fun testMarkerStateInsideMarkerComposableCannotBeReused() {
initMap {
val markerState = rememberMarkerState()
MarkerComposable(
keys = arrayOf("marker1"),
state = markerState,
) {
Box {
Text(text = "marker1")
}
}
MarkerComposable(
keys = arrayOf("marker2"),
state = markerState,
) {
Box {
Text(text = "marker2")
}
}
}
}

@Test
fun testCameraPositionStateMapClears() {
initMap()
Expand All @@ -234,4 +259,4 @@ class GoogleMapViewTests {

assertionBlock()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@ class MapInColumnTests {
private val startingPosition = LatLng(1.23, 4.56)
private lateinit var cameraPositionState: CameraPositionState

private fun initMap(content: @Composable () -> Unit = {}) {
private fun initMap() {
check(hasValidApiKey) { "Maps API key not specified" }
val countDownLatch = CountDownLatch(1)
composeTestRule.setContent {
Expand Down Expand Up @@ -130,18 +130,17 @@ class MapInColumnTests {
startingPosition.assertEquals(cameraPositionState.position.target)
}

// @Test
// fun testPanMapUp_MapCameraChangesColumnDoesNotScroll() {
// initMap()
// // Swipe the map up
// // FIXME - for some reason this scrolls the entire column instead of just the map
// composeTestRule.onNodeWithTag("Map").performTouchInput { swipeUp() }
// composeTestRule.waitForIdle()
//
// // Make sure that the map changed (i.e., we can scroll the map in the column)
// startingPosition.assertNotEquals(cameraPositionState.position.target)
//
// // Check to make sure column didn't scroll
// composeTestRule.onNodeWithTag("Item 1").assertIsDisplayed()
// }
@Test
fun testPanMapUp_MapCameraChangesColumnDoesNotScroll() {
initMap()
//Swipe the map up
composeTestRule.onAllNodesWithTag("Map").onFirst().performTouchInput { swipeUp() }
composeTestRule.waitForIdle()

//Make sure that the map changed (i.e., we can scroll the map in the column)
assertNotEquals(startingPosition, cameraPositionState.position.target)

//Check to make sure column didn't scroll
composeTestRule.onNodeWithTag("Item 1").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class StreetViewTests {
onClick = onClick
)
}
composeTestRule.waitUntil(10000) {
composeTestRule.waitUntil(timeout5) {
cameraPositionState.location.position.latitude != 0.0 &&
cameraPositionState.location.position.longitude != 0.0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.google.maps.android.compose
import com.google.android.gms.maps.model.LatLng
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
const val timeout2 = 2_000L
const val timeout3 = 3_000L
const val timeout5 = 5_000L

val hasValidApiKey: Boolean =
BuildConfig.MAPS_API_KEY.isNotBlank() && BuildConfig.MAPS_API_KEY != "YOUR_API_KEY"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<activity
android:name=".StreetViewActivity"
android:exported="false"/>
<activity
android:name=".CustomControlsActivity"
android:exported="false"/>

<!-- Used by createComponentActivity() for unit testing -->
<activity android:name="androidx.activity.ComponentActivity" />
Expand Down
Loading

0 comments on commit 2e1422e

Please sign in to comment.