-
Notifications
You must be signed in to change notification settings - Fork 181
docs: Update demo app to include more examples #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9287b63
chore: Add basic entry activity, sample scrolling activity
barbeau e6f6578
chore: Tweak text and scrolling map size
barbeau ee6e2cf
chore: Try out fix for vertical map scrolling
barbeau e2de15e
fix: Tests (including bumping timeout on test)
barbeau 735b649
chore: Fix dark theme background and text
barbeau 2b9f93d
fix: Try to fix vertical scrolling with pointerInteropFilter
barbeau 10248e3
fix: Use LaunchedEffect to re-enable column scrolling when map camera…
barbeau 60e1cd5
Merge branch 'main' into sean/scroll-example
barbeau 8f7af38
Merge branch 'main' into sean/scroll-example
barbeau af1d9d3
chore: Hoist state for ScrollingMapActivity to enable testing
barbeau 545a9a9
chore: Add first test for scrolling column
barbeau c015849
chore: Add test for panning map
barbeau 4c945a7
chore: Use swipe instead of scroll to
barbeau b4615e9
chore: Comment out failing UI test
barbeau 3d205d1
chore: Refactor ScrollingMap -> MapInColumn
barbeau 5fe3267
Merge branch 'main' into sean/scroll-example
barbeau 2f02903
chore: Update composeTestRule
barbeau c2268fe
chore: Remove invisible box - it works without it!
barbeau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
app/src/androidTest/java/com/google/maps/android/compose/MapInColumnTests.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // Copyright 2022 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package com.google.maps.android.compose | ||
|
|
||
| import android.util.Log | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.runtime.* | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.test.* | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import com.google.android.gms.maps.model.CameraPosition | ||
| import com.google.android.gms.maps.model.LatLng | ||
| import org.junit.Assert.* | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import java.util.concurrent.CountDownLatch | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
| private const val TAG = "MapInColumnTests" | ||
|
|
||
| class MapInColumnTests { | ||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| private val startingZoom = 10f | ||
| private val startingPosition = LatLng(1.23, 4.56) | ||
| private lateinit var cameraPositionState: CameraPositionState | ||
|
|
||
| private fun initMap(content: @Composable () -> Unit = {}) { | ||
| val countDownLatch = CountDownLatch(1) | ||
| composeTestRule.setContent { | ||
| var scrollingEnabled by remember { mutableStateOf(true) } | ||
|
|
||
| LaunchedEffect(cameraPositionState.isMoving) { | ||
| if (!cameraPositionState.isMoving) { | ||
| scrollingEnabled = true | ||
| Log.d(TAG, "Map camera stopped moving - Enabling column scrolling...") | ||
| } | ||
| } | ||
|
|
||
| MapInColumn( | ||
| modifier = Modifier.fillMaxSize(), | ||
| cameraPositionState, | ||
| columnScrollingEnabled = scrollingEnabled, | ||
| onMapTouched = { | ||
| scrollingEnabled = false | ||
| Log.d( | ||
| TAG, | ||
| "User touched map - Disabling column scrolling after user touched this Box..." | ||
| ) | ||
| }, | ||
| onMapLoaded = { | ||
| countDownLatch.countDown() | ||
| } | ||
| ) | ||
| } | ||
| val mapLoaded = countDownLatch.await(30, TimeUnit.SECONDS) | ||
| assertTrue("Map loaded", mapLoaded) | ||
| } | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| cameraPositionState = CameraPositionState( | ||
| position = CameraPosition.fromLatLngZoom( | ||
| startingPosition, | ||
| startingZoom | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun testStartingCameraPosition() { | ||
| initMap() | ||
| startingPosition.assertEquals(cameraPositionState.position.target) | ||
| } | ||
|
|
||
| @Test | ||
| fun testLatLngInVisibleRegion() { | ||
| initMap() | ||
| composeTestRule.runOnUiThread { | ||
| val projection = cameraPositionState.projection | ||
| assertNotNull(projection) | ||
| assertTrue( | ||
| projection!!.visibleRegion.latLngBounds.contains(startingPosition) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testLatLngNotInVisibleRegion() { | ||
| initMap() | ||
| composeTestRule.runOnUiThread { | ||
| val projection = cameraPositionState.projection | ||
| assertNotNull(projection) | ||
| val latLng = LatLng(23.4, 25.6) | ||
| assertFalse( | ||
| projection!!.visibleRegion.latLngBounds.contains(latLng) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testScrollColumn_MapCameraRemainsSame() { | ||
| initMap() | ||
| // Check that the column scrolls to the last item | ||
| composeTestRule.onRoot().performTouchInput { swipeUp() } | ||
| composeTestRule.waitForIdle() | ||
| composeTestRule.onNodeWithTag("Item 1").assertIsNotDisplayed() | ||
|
|
||
| // Check that the map didn't change | ||
| 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() | ||
| // } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
app/src/androidTest/java/com/google/maps/android/compose/TestUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| 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 assertRoundingError: Double = 0.01 | ||
|
|
||
| fun LatLng.assertEquals(other: LatLng) { | ||
| assertEquals(latitude, other.latitude, assertRoundingError) | ||
| assertEquals(longitude, other.longitude, assertRoundingError) | ||
| } | ||
|
|
||
| fun LatLng.assertNotEquals(other: LatLng) { | ||
| assertNotEquals(latitude, other.latitude, assertRoundingError) | ||
| assertNotEquals(longitude, other.longitude, assertRoundingError) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/main/java/com/google/maps/android/compose/MainActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright 2021 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package com.google.maps.android.compose | ||
|
|
||
| import android.content.Intent | ||
| import android.os.Bundle | ||
| import androidx.activity.ComponentActivity | ||
| import androidx.activity.compose.setContent | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.material.Button | ||
| import androidx.compose.material.MaterialTheme | ||
| import androidx.compose.material.Surface | ||
| import androidx.compose.material.Text | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.unit.dp | ||
|
|
||
| private const val TAG = "MapSampleActivity" | ||
|
|
||
| class MainActivity : ComponentActivity() { | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContent { | ||
| Surface( | ||
| modifier = Modifier.fillMaxSize(), | ||
| color = MaterialTheme.colors.background | ||
| ) { | ||
| val context = LocalContext.current | ||
| Column( | ||
| Modifier | ||
| .fillMaxSize(), | ||
| horizontalAlignment = Alignment.CenterHorizontally | ||
| ) { | ||
| Spacer(modifier = Modifier.padding(10.dp)) | ||
| Text( | ||
| text = getString(R.string.main_activity_title), | ||
| style = MaterialTheme.typography.h5 | ||
| ) | ||
| Spacer(modifier = Modifier.padding(10.dp)) | ||
| Button( | ||
| onClick = { | ||
| context.startActivity(Intent(context, BasicMapActivity::class.java)) | ||
| }) { | ||
| Text(getString(R.string.basic_map_activity)) | ||
| } | ||
| Spacer(modifier = Modifier.padding(5.dp)) | ||
| Button( | ||
| onClick = { | ||
| context.startActivity(Intent(context, MapInColumnActivity::class.java)) | ||
| }) { | ||
| Text(getString(R.string.map_in_column_activity)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arriolac @wangela I still need to work on this unit test further (for some reason it fails when it should pass), but I'd like to go ahead and get this PR merged first and add this test later (IMHO it's a "nice-to-have"). Otherwise, due to the refactoring in this PR I keep getting merge conflicts every time the main branch is changed.
So it should be ready for review.