Skip to content
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

Demonstrate scrolling dialogs #2002

Merged
merged 4 commits into from
Jan 24, 2024
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 @@ -16,15 +16,25 @@

package com.google.android.horologist.screensizes

import android.R
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Close
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.dialog.Alert
import com.google.android.horologist.compose.layout.ScalingLazyColumnState
import com.google.android.horologist.compose.layout.rememberColumnState
import com.google.android.horologist.compose.material.AlertContent
import com.google.android.horologist.compose.material.Button
import com.google.android.horologist.compose.material.ResponsiveDialogContent
import com.google.android.horologist.compose.material.ToggleChip
import com.google.android.horologist.compose.material.ToggleChipToggleControl
import com.google.android.horologist.compose.tools.Device
import kotlinx.coroutines.runBlocking
import org.junit.Test

class DialogTest(device: Device) : ScreenSizeTest(
Expand Down Expand Up @@ -70,4 +80,54 @@ class DialogTest(device: Device) : ScreenSizeTest(
}
}
}

@Test
fun longDialogScreen1() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: drop 1 from name

lateinit var columnState: ScalingLazyColumnState

runTest(testFn = {
screenshotTestRule.interact {
runBlocking {
columnState.state.scrollToItem(999, 0)
}
}

screenshotTestRule.takeScreenshot()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be called from ScreenSizeTest.runTest or is the intention to let each test to decide when to take a screenshot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I wanted the minimal way to let me get multiple screenshots. I should improve the API. Will follow up.

}) {
columnState = rememberColumnState()

ResponsiveDialogContent(
title = {
Text(
text = "Turn on Bedtime mode?",
color = MaterialTheme.colors.onBackground,
textAlign = TextAlign.Center,
maxLines = 3,
)
},
onOkButtonClick = {},
onCancelButtonClick = {},
okButtonContentDescription = stringResource(R.string.ok),
cancelButtonContentDescription = stringResource(R.string.cancel),
state = columnState,
) {
item {
Text(
text = "Watch screen, tilt-to-wake, and touch are turned off. " +
"Only calls from starred contacts, repeat callers, " +
"and alarms will notify you.",
textAlign = TextAlign.Left,
)
}
item {
ToggleChip(
checked = false,
onCheckedChanged = {},
label = "Don't show again",
toggleControl = ToggleChipToggleControl.Checkbox,
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class ScreenSizeTest(
runTest { Content() }
}

fun runTest(content: @Composable () -> Unit) {
fun runTest(testFn: () -> Unit = {}, content: @Composable () -> Unit) {
val shadowDisplay = Shadows.shadowOf(ShadowDisplay.getDefaultDisplay())
shadowDisplay.setDensity(device.density)
shadowDisplay.setHeight(device.screenSizePx)
Expand All @@ -82,6 +82,8 @@ abstract class ScreenSizeTest(
content = content,
)
}

testFn()
}

companion object {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.