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

fix: Enhance Popover screenshot test #890

Merged
merged 9 commits into from
Jan 15, 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 @@ -193,9 +193,8 @@ private fun ConfiguredPopover(
}

PopoverContentExamples.Image -> Image(
contentScale = ContentScale.Crop,
modifier = Modifier.height(500.dp),
model = "https://t.ly/gio0G",
contentScale = ContentScale.Inside,
model = "https://images.unsplash.com/photo-1606041008023-472dfb5e530f",
contentDescription = null,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ package com.adevinta.spark.popover
import android.annotation.SuppressLint
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
Expand All @@ -43,7 +40,7 @@ import com.adevinta.spark.ExperimentalSparkApi
import com.adevinta.spark.MaxPercentDifference
import com.adevinta.spark.PaparazziTheme
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.buttons.ButtonOutlined
import com.adevinta.spark.components.buttons.ButtonFilled
import com.adevinta.spark.components.popover.Popover
import com.adevinta.spark.components.popover.newapi.rememberTooltipState
import com.adevinta.spark.components.text.Text
Expand Down Expand Up @@ -77,69 +74,60 @@ internal class PopoverScreenshot {
)

@SuppressLint("CoroutineCreationDuringComposition")
@OptIn(ExperimentalComposeApi::class)
@Test
fun test() {
paparazzi.sparkSnapshot(name = "Popover", true) {
val state = rememberTooltipState(isPersistent = true)
val scope = rememberCoroutineScope()
val interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }
enableList.forEach { isEnabled ->
paparazzi.sparkSnapshot(name = "Popover_isDismissEnabled_$isEnabled", true) {
val state = rememberTooltipState(isPersistent = true)
val scope = rememberCoroutineScope()
val interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }

Row {
enableList.forEach { isEnabled ->
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = "isDismissButtonEnabled: $isEnabled",
)
Row {
Popover(
popoverContent = {
Column {
Text(
text = "Title",
modifier = Modifier.padding(bottom = 16.dp),
style = SparkTheme.typography.headline1.copy(fontWeight = FontWeight.Bold),
)
Text(
text = "Do you want to have this cookie now?",
modifier = Modifier.padding(bottom = 16.dp),
style = SparkTheme.typography.body2.copy(fontWeight = FontWeight.Bold),
)
Text(
text = "Text Link",
textDecoration = TextDecoration.Underline,
style = SparkTheme.typography.body1.copy(fontWeight = FontWeight.Bold)
.copy(color = SparkTheme.colors.accent),
)
}
},
isDismissButtonEnabled = isEnabled,
popoverState = state.apply {
scope.launch {
show()
}
},
) {
ButtonOutlined(
text = "Display Popover",
onClick = { scope.launch { state.show() } },
interactionSource = interactionSource,
scope.launch {
val press = PressInteraction.Press(Offset.Zero)
interactionSource.emit(press)
state.show()
delay(300)
interactionSource.emit(PressInteraction.Release(press))
}

Column {
Popover(
popoverContent = {
Column {
Text(
text = "Title",
modifier = Modifier.padding(bottom = 16.dp),
style = SparkTheme.typography.headline1.copy(fontWeight = FontWeight.Bold),
)
Text(
text = "Do you want to have this cookie now?",
modifier = Modifier.padding(bottom = 16.dp),
style = SparkTheme.typography.body2.copy(fontWeight = FontWeight.Bold),
)
Text(
text = "Text Link",
textDecoration = TextDecoration.Underline,
style = SparkTheme.typography.body1.copy(fontWeight = FontWeight.Bold)
.copy(color = SparkTheme.colors.accent),
)
}
}
},
isDismissButtonEnabled = isEnabled,
popoverState = state.apply {
scope.launch {
show()
}
},
) {
scope.launch { state.show() }
ButtonFilled(
text = "Display Popover",
onClick = { scope.launch { state.show() } },
interactionSource = interactionSource,
)
}
}
}

scope.launch {
val press = PressInteraction.Press(Offset.Zero)
interactionSource.emit(press)
state.show()
delay(300)
interactionSource.emit(PressInteraction.Release(press))
}
}
}
}

This file was deleted.

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.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.adevinta.spark.SparkTheme
import com.adevinta.spark.SparkTheme.colors
import com.adevinta.spark.components.buttons.ButtonOutlined
import com.adevinta.spark.components.iconbuttons.IconButtonGhost
import com.adevinta.spark.components.iconbuttons.IconButtonIntent
import com.adevinta.spark.components.popover.PopoverDefaults.PopoverAnchorPadding
import com.adevinta.spark.components.popover.PopoverDefaults.PopoverContentPadding
import com.adevinta.spark.components.popover.PopoverDefaults.PopoverDismissButtonPadding
Expand Down Expand Up @@ -110,8 +111,7 @@ public fun Popover(
Row {
Box(
modifier = Modifier
.padding(all = PopoverContentPadding)
.weight(1.0f, false),
.padding(all = PopoverContentPadding),
) {
CompositionLocalProvider(
content = popoverContent,
Expand All @@ -123,8 +123,8 @@ public fun Popover(
.padding(
top = PopoverDismissButtonPadding,
end = PopoverDismissButtonPadding,
)
.weight(2.0f, true),
),
intent = IconButtonIntent.Neutral,
icon = SparkIcons.Close,
onClick = { popoverState.dismiss() },
)
Expand Down
Loading