Skip to content

Commit

Permalink
Rename to RoboComposePreviewOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Feb 1, 2025
1 parent f05360a commit cbac859
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.github.takahirom.roborazzi.annotations
// TODO -> maybe add also parameter for ignoreFrames, as used in mainClock.advanceTime()
// TODO -> Make BINARY annotation only applicable to Methods
// TODO -> Docu: mention about the 16ms frame in Android
annotation class RoboManualAdvance(val advanceTimeMillis: Long)
annotation class RoboComposePreviewOptions(val advanceTimeMillis: Long)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.github.takahirom.roborazzi.annotations.RoboManualAdvance
import com.github.takahirom.roborazzi.annotations.RoboComposePreviewOptions
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.rules.TestWatcher
Expand Down Expand Up @@ -212,7 +212,7 @@ class AndroidComposePreviewTester : ComposePreviewTester<AndroidPreviewInfo> {
override fun previews(): List<ComposablePreview<AndroidPreviewInfo>> {
val options = options()
return AndroidComposablePreviewScanner().scanPackageTrees(*options.scanOptions.packages.toTypedArray())
.includeAnnotationInfoForAllOf(RoboManualAdvance::class.java).let {
.includeAnnotationInfoForAllOf(RoboComposePreviewOptions::class.java).let {
if (options.scanOptions.includePrivatePreviews) {
it.includePrivatePreviews()
} else {
Expand All @@ -239,7 +239,7 @@ class AndroidComposePreviewTester : ComposePreviewTester<AndroidPreviewInfo> {
.apply {
@Suppress("UNCHECKED_CAST")
composeTestRule(composeTestRule as AndroidComposeTestRule<ActivityScenarioRule<out ComponentActivity>, *>)
preview.getAnnotation<RoboManualAdvance>()?.let {
preview.getAnnotation<RoboComposePreviewOptions>()?.let {
manualAdvance(composeTestRule, it.advanceTimeMillis)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,37 @@ package com.github.takahirom.preview.tests
import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.Wallpapers
import androidx.compose.ui.unit.dp
import com.github.takahirom.roborazzi.annotations.RoboManualAdvance
import com.github.takahirom.roborazzi.annotations.RoboComposePreviewOptions
import kotlinx.coroutines.delay

@Preview
Expand Down Expand Up @@ -240,7 +260,7 @@ fun PreviewShowBackgroundWithBackgroundColor() {
}
}

@RoboManualAdvance(advanceTimeMillis = 516L) // 500 ms + 16ms frame
@RoboComposePreviewOptions(advanceTimeMillis = 516L) // 500 ms + 16ms frame
@Preview
@Composable
fun PreviewDelayed() {
Expand All @@ -253,7 +273,7 @@ fun PreviewDelayed() {
isVisible = true
}
LaunchedEffect(isVisible) {
while(true) {
while (true) {
delay(100)
counter++
}
Expand Down

0 comments on commit cbac859

Please sign in to comment.