Use @DayNightPreviews to correctly render the PinIcon in dark mode (#795)
- Fixes rendering of `-night` resources in screenshot tests by overriding the `nightMode` with `paparazzi.unsafeUpdateConfig()`.
This commit is contained in:
parent
d8fcfc5844
commit
c48fcac2f1
43 changed files with 77 additions and 96 deletions
|
|
@ -52,7 +52,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.features.messages.impl.actionlist.model.TimelineItemAction
|
||||
|
|
@ -70,7 +69,8 @@ import io.element.android.features.messages.impl.utils.messagesummary.MessageSum
|
|||
import io.element.android.libraries.designsystem.ElementTextStyles
|
||||
import io.element.android.libraries.designsystem.components.avatar.Avatar
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.DayNightPreviews
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.text.toSp
|
||||
import io.element.android.libraries.designsystem.theme.components.Divider
|
||||
|
|
@ -395,18 +395,11 @@ private fun EmojiButton(
|
|||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@DayNightPreviews
|
||||
@Composable
|
||||
fun SheetContentLightPreview(@PreviewParameter(ActionListStateProvider::class) state: ActionListState) =
|
||||
ElementPreviewLight { ContentToPreview(state) }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun SheetContentDarkPreview(@PreviewParameter(ActionListStateProvider::class) state: ActionListState) =
|
||||
ElementPreviewDark { ContentToPreview(state) }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview(state: ActionListState) {
|
||||
fun SheetContentPreview(
|
||||
@PreviewParameter(ActionListStateProvider::class) state: ActionListState
|
||||
) = ElementPreview {
|
||||
SheetContent(
|
||||
state = state,
|
||||
onActionClicked = {},
|
||||
|
|
|
|||
|
|
@ -23,11 +23,10 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.designsystem.R
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.preview.DayNightPreviews
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||
import io.element.android.libraries.theme.ElementTheme
|
||||
|
||||
|
|
@ -50,17 +49,8 @@ fun PinIcon(
|
|||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@DayNightPreviews
|
||||
@Composable
|
||||
fun PinIconLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PinIconDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
fun PinIconPreview() = ElementPreview {
|
||||
PinIcon()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ import androidx.compose.ui.unit.dp
|
|||
import io.element.android.libraries.designsystem.ElementTextStyles
|
||||
import io.element.android.libraries.designsystem.VectorIcons
|
||||
import io.element.android.libraries.designsystem.modifiers.applyIf
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.DayNightPreviews
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||
import io.element.android.libraries.designsystem.theme.components.Surface
|
||||
|
|
@ -414,32 +415,9 @@ private fun BoxScope.SendButton(
|
|||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@DayNightPreviews
|
||||
@Composable
|
||||
internal fun TextComposerSimpleLightPreview() = ElementPreviewLight { SimpleContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun TextComposerSimpleDarkPreview() = ElementPreviewDark { SimpleContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun TextComposerEditLightPreview() = ElementPreviewLight { EditContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun TextComposerEditDarkPreview() = ElementPreviewDark { EditContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun TextComposerReplyLightPreview() = ElementPreviewLight { ReplyContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun TextComposerReplyDarkPreview() = ElementPreviewDark { ReplyContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun SimpleContentToPreview() {
|
||||
fun TextComposerSimplePreview() = ElementPreview {
|
||||
Column {
|
||||
TextComposer(
|
||||
onSendMessage = {},
|
||||
|
|
@ -468,8 +446,9 @@ private fun SimpleContentToPreview() {
|
|||
}
|
||||
}
|
||||
|
||||
@DayNightPreviews
|
||||
@Composable
|
||||
private fun EditContentToPreview() {
|
||||
fun TextComposerEditPreview() = ElementPreview {
|
||||
TextComposer(
|
||||
onSendMessage = {},
|
||||
onComposerTextChange = {},
|
||||
|
|
@ -480,8 +459,9 @@ private fun EditContentToPreview() {
|
|||
)
|
||||
}
|
||||
|
||||
@DayNightPreviews
|
||||
@Composable
|
||||
private fun ReplyContentToPreview() {
|
||||
fun TextComposerReplyPreview() = ElementPreview {
|
||||
Column {
|
||||
TextComposer(
|
||||
onSendMessage = {},
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ import androidx.lifecycle.Lifecycle
|
|||
import app.cash.paparazzi.Paparazzi
|
||||
import com.airbnb.android.showkase.models.Showkase
|
||||
import com.android.ide.common.rendering.api.SessionParams
|
||||
import com.android.resources.NightMode
|
||||
import com.google.testing.junit.testparameterinjector.TestParameter
|
||||
import com.google.testing.junit.testparameterinjector.TestParameterInjector
|
||||
import io.element.android.libraries.designsystem.preview.NIGHT_MODE_NAME
|
||||
import io.element.android.libraries.theme.ElementTheme
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
|
@ -85,7 +85,13 @@ class ScreenshotTest {
|
|||
Locale.setDefault(locale) // Needed for regional settings, as first day of week
|
||||
paparazzi.unsafeUpdateConfig(
|
||||
deviceConfig = baseDeviceConfig.deviceConfig.copy(
|
||||
softButtons = false
|
||||
softButtons = false,
|
||||
nightMode = componentTestPreview.isNightMode().let {
|
||||
when (it) {
|
||||
true -> NightMode.NIGHT
|
||||
false -> NightMode.NOTNIGHT
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
paparazzi.snapshot {
|
||||
|
|
@ -98,9 +104,9 @@ class ScreenshotTest {
|
|||
),
|
||||
LocalConfiguration provides Configuration().apply {
|
||||
setLocales(LocaleList(locale))
|
||||
// Dark mode previews have name "N" so their component name contains "- N"
|
||||
if (componentTestPreview.name.contains("- $NIGHT_MODE_NAME")){
|
||||
uiMode = Configuration.UI_MODE_NIGHT_YES
|
||||
uiMode = when (componentTestPreview.isNightMode()) {
|
||||
true -> Configuration.UI_MODE_NIGHT_YES
|
||||
false -> Configuration.UI_MODE_NIGHT_NO
|
||||
}
|
||||
},
|
||||
// Needed so that UI that uses it don't crash during screenshot tests
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@
|
|||
package io.element.android.tests.uitests
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.airbnb.android.showkase.models.ShowkaseElementsMetadata
|
||||
import io.element.android.libraries.designsystem.preview.NIGHT_MODE_NAME
|
||||
|
||||
interface TestPreview {
|
||||
@Composable
|
||||
|
|
@ -24,3 +27,12 @@ interface TestPreview {
|
|||
|
||||
val name: String
|
||||
}
|
||||
|
||||
/**
|
||||
* Showkase doesn't put the [Preview.uiMode] parameter in its [ShowkaseElementsMetadata]
|
||||
* so we have to encode the night mode bit in a preview's name.
|
||||
*/
|
||||
fun TestPreview.isNightMode(): Boolean {
|
||||
// Dark mode previews have name "N" so their component name contains "- N"
|
||||
return this.name.contains("- $NIGHT_MODE_NAME")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:d760fb152bec0b3ab0e6a7c60cb0174cafd5221e3c9debcd63eeff32bfaad9af
|
||||
size 4478
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:d760fb152bec0b3ab0e6a7c60cb0174cafd5221e3c9debcd63eeff32bfaad9af
|
||||
size 4478
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:5ccab2f54c80d52438b71a8afee8eb2fbd755b44cf3912c7b8a6b4cce77ee2a1
|
||||
size 39327
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a03f5e42a98c9664175d7630923b89ed9f657745e457a1dd3061693e523992dd
|
||||
size 45340
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:de5fc56ef0c5a093895cfff39972f4f472207fe39c36458c29789f34ef875f60
|
||||
size 45865
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:2c6a00bfbe9b860736900fad85d5727e06ef2589c0ac15b8f5dc47a68685fef8
|
||||
size 39719
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:8918fa3ef7b1e73d7f9c85ae279016693c36e83271ca46f808ae6beee862d30e
|
||||
size 41053
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c385584daf063f769882c424507a526e33c876bddd6c76126c4c7eeb55ecd370
|
||||
size 25797
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:8c89ac73df77c2bccb0c2aa80cee1420f78e7d07f0eda89a90bffef55e8cf753
|
||||
size 4464
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:8c89ac73df77c2bccb0c2aa80cee1420f78e7d07f0eda89a90bffef55e8cf753
|
||||
size 4464
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b3ce19cca10531dbac2ca4a6a3e84f544bea12576b863b2cebad7a3f35b7c998
|
||||
size 38768
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0fdeeaa710d34e74380251f495dc3e14b241cc352c3060b3771a136dbda406c0
|
||||
size 45217
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6c3bb4caae6c2e9307b3b3a7fd02916c969a2c3cfa635c68a82bbfcaf33ea208
|
||||
size 45722
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:49e8bc6bdee76d09254b63c05c50dc2fb07ef34afe40288f12ec4e06c3add894
|
||||
size 39158
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0bef33ca6c76d7b6fed09b63bfa4ef9b6fa7c04a45e7a0f043a9f4f0b898fcdb
|
||||
size 40603
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:dee1ad227aee82d1ff3981c9606cc855c74cc636fc2ac8f17f1ffd00a0bdbc88
|
||||
size 25767
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c81885a3cffdb92e8282bfd511ac4efff4b02b1de2d6a37c01f9e41b94841e25
|
||||
size 5429
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:51e6c82dee78de8f5f320c30625ca7ac01918042cd13dc71611087e422e9ab12
|
||||
size 5637
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:899e8b2a2a257fa6ce646a41525a1cc0173c43265dbf610646b5389134a7837b
|
||||
size 12924
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:29b622a6954933418d053dce5da7f15fb46d2229a0a68c3957b6dcc715092bb8
|
||||
size 12431
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7d83815b1834a70e52fd55ab3558cb3f705abeba74474f4b23f6aafbb028a5ff
|
||||
size 77687
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c110dcb1e79f782acba58c795fcdcbf2611611be234ffa0df7251b764e155d3e
|
||||
size 77734
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:33f9c822ea3c2a8baf01615e4b817e241d15f2b9cfd40267e7ac4a8f8e4c2375
|
||||
size 33735
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:eeb1cc3040e3a3fc490af539916e93f0780028e72f95f87546b4bd5941191a1e
|
||||
size 33499
|
||||
Loading…
Add table
Add a link
Reference in a new issue