From bd646943b71a8e2f9343af01dfd83ad6b32bdf4f Mon Sep 17 00:00:00 2001 From: takahirom Date: Mon, 2 Dec 2024 19:40:51 +0900 Subject: [PATCH] Rename Applier to Config --- .../RoborazziPreviewScannerSupport.kt | 4 +- .../takahirom/roborazzi/RoborazziCompose.kt | 6 +- ...seApplier.kt => RoborazziComposeConfig.kt} | 104 +++++++++--------- 3 files changed, 57 insertions(+), 57 deletions(-) rename roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/{RoborazziComposeApplier.kt => RoborazziComposeConfig.kt} (54%) diff --git a/roborazzi-compose-preview-scanner-support/src/main/java/com/github/takahirom/roborazzi/RoborazziPreviewScannerSupport.kt b/roborazzi-compose-preview-scanner-support/src/main/java/com/github/takahirom/roborazzi/RoborazziPreviewScannerSupport.kt index 9251adc1..9f426735 100644 --- a/roborazzi-compose-preview-scanner-support/src/main/java/com/github/takahirom/roborazzi/RoborazziPreviewScannerSupport.kt +++ b/roborazzi-compose-preview-scanner-support/src/main/java/com/github/takahirom/roborazzi/RoborazziPreviewScannerSupport.kt @@ -13,7 +13,7 @@ import sergio.sastre.composable.preview.scanner.core.preview.ComposablePreview fun ComposablePreview.captureRoboImage( filePath: String, roborazziOptions: RoborazziOptions = provideRoborazziContext().options, - applierBuilder: RoborazziComposeApplierBuilder = RoborazziComposeApplierBuilder() + applierBuilder: RoborazziComposeConfigBuilder = RoborazziComposeConfigBuilder() .sized( widthDp = previewInfo.widthDp, heightDp = previewInfo.heightDp @@ -34,7 +34,7 @@ fun ComposablePreview.captureRoboImage( } } -fun RoborazziComposeApplierBuilder.device(device: String) = with(DeviceApplier(device)) +fun RoborazziComposeConfigBuilder.device(device: String) = with(DeviceApplier(device)) @ExperimentalRoborazziApi data class DeviceApplier(val device: String) : diff --git a/roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziCompose.kt b/roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziCompose.kt index 9699b95b..3de275f4 100644 --- a/roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziCompose.kt +++ b/roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziCompose.kt @@ -30,7 +30,7 @@ fun captureRoboImage( captureRoboImage( file = file, roborazziOptions = roborazziOptions, - applierBuilder = RoborazziComposeApplierBuilder(), + applierBuilder = RoborazziComposeConfigBuilder(), content = content ) } @@ -39,7 +39,7 @@ fun captureRoboImage( fun captureRoboImage( filePath: String = DefaultFileNameGenerator.generateFilePath(), roborazziOptions: RoborazziOptions = provideRoborazziContext().options, - applierBuilder: RoborazziComposeApplierBuilder = RoborazziComposeApplierBuilder(), + applierBuilder: RoborazziComposeConfigBuilder = RoborazziComposeConfigBuilder(), content: @Composable () -> Unit, ) { captureRoboImage( @@ -54,7 +54,7 @@ fun captureRoboImage( fun captureRoboImage( file: File, roborazziOptions: RoborazziOptions = provideRoborazziContext().options, - applierBuilder: RoborazziComposeApplierBuilder = RoborazziComposeApplierBuilder(), + applierBuilder: RoborazziComposeConfigBuilder = RoborazziComposeConfigBuilder(), content: @Composable () -> Unit, ) { if (!roborazziOptions.taskType.isEnabled()) return diff --git a/roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziComposeApplier.kt b/roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziComposeConfig.kt similarity index 54% rename from roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziComposeApplier.kt rename to roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziComposeConfig.kt index 50c7feb0..87d32081 100644 --- a/roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziComposeApplier.kt +++ b/roborazzi-compose/src/main/java/com/github/takahirom/roborazzi/RoborazziComposeConfig.kt @@ -20,51 +20,51 @@ import kotlin.math.roundToInt @ExperimentalRoborazziApi interface RoborazziComposeApplier -interface RoborazziComposeSetupApplier : RoborazziComposeApplier { - fun apply() +interface RoborazziComposeSetupConfig : RoborazziComposeApplier { + fun configure() } @ExperimentalRoborazziApi -interface RoborazziComposeActivityScenarioApplier : RoborazziComposeApplier { - fun applyToActivityScenario(scenario: ActivityScenario) +interface RoborazziComposeActivityScenarioConfig : RoborazziComposeApplier { + fun configureToActivityScenario(scenario: ActivityScenario) } @ExperimentalRoborazziApi -interface RoborazziComposeComposableApplier : RoborazziComposeApplier { - fun applyToComposable(content: @Composable () -> Unit): @Composable () -> Unit +interface RoborazziComposeComposableConfig : RoborazziComposeApplier { + fun configureToComposable(content: @Composable () -> Unit): @Composable () -> Unit } @ExperimentalRoborazziApi -class RoborazziComposeApplierBuilder { - private val activityScenarioAppliers = - mutableListOf() - private val composableAppliers = mutableListOf() - private val setupAppliers = mutableListOf() - - fun with(applier: RoborazziComposeApplier): RoborazziComposeApplierBuilder { - if (applier is RoborazziComposeActivityScenarioApplier) { - activityScenarioAppliers.add(applier) +class RoborazziComposeConfigBuilder { + private val activityScenarioConfigs = + mutableListOf() + private val composableConfigs = mutableListOf() + private val setupConfigs = mutableListOf() + + fun with(applier: RoborazziComposeApplier): RoborazziComposeConfigBuilder { + if (applier is RoborazziComposeActivityScenarioConfig) { + activityScenarioConfigs.add(applier) } - if (applier is RoborazziComposeComposableApplier) { - composableAppliers.add(applier) + if (applier is RoborazziComposeComposableConfig) { + composableConfigs.add(applier) } - if (applier is RoborazziComposeSetupApplier) { - setupAppliers.add(applier) + if (applier is RoborazziComposeSetupConfig) { + setupConfigs.add(applier) } return this } @InternalRoborazziApi - fun apply( + fun configure( scenario: ActivityScenario, content: @Composable () -> Unit ): @Composable () -> Unit { - setupAppliers.forEach { it.apply() } - activityScenarioAppliers.forEach { it.applyToActivityScenario(scenario) } + setupConfigs.forEach { it.configure() } + activityScenarioConfigs.forEach { it.configureToActivityScenario(scenario) } var appliedContent = content - composableAppliers.forEach { applier -> - appliedContent = applier.applyToComposable(appliedContent) + composableConfigs.forEach { applier -> + appliedContent = applier.configureToComposable(appliedContent) } return { appliedContent() @@ -73,15 +73,15 @@ class RoborazziComposeApplierBuilder { } @ExperimentalRoborazziApi -fun RoborazziComposeApplierBuilder.sized(widthDp: Int = 0, heightDp: Int = 0): RoborazziComposeApplierBuilder { - return with(RoborazziComposeSizeApplier(widthDp, heightDp)) +fun RoborazziComposeConfigBuilder.sized(widthDp: Int = 0, heightDp: Int = 0): RoborazziComposeConfigBuilder { + return with(RoborazziComposeSizeConfig(widthDp, heightDp)) } @ExperimentalRoborazziApi -data class RoborazziComposeSizeApplier(val widthDp: Int, val heightDp: Int) : - RoborazziComposeActivityScenarioApplier, - RoborazziComposeComposableApplier { - override fun applyToActivityScenario(scenario: ActivityScenario) { +data class RoborazziComposeSizeConfig(val widthDp: Int, val heightDp: Int) : + RoborazziComposeActivityScenarioConfig, + RoborazziComposeComposableConfig { + override fun configureToActivityScenario(scenario: ActivityScenario) { scenario.onActivity { activity -> activity.setDisplaySize(widthDp = widthDp, heightDp = heightDp) } @@ -106,7 +106,7 @@ data class RoborazziComposeSizeApplier(val widthDp: Int, val heightDp: Int) : recreate() } - override fun applyToComposable(content: @Composable () -> Unit): @Composable () -> Unit { + override fun configureToComposable(content: @Composable () -> Unit): @Composable () -> Unit { /** * WARNING: * For this to work, it requires that the Display is within the widthDp and heightDp dimensions @@ -127,19 +127,19 @@ data class RoborazziComposeSizeApplier(val widthDp: Int, val heightDp: Int) : } @ExperimentalRoborazziApi -fun RoborazziComposeApplierBuilder.colored( +fun RoborazziComposeConfigBuilder.colored( showBackground: Boolean, backgroundColor: Long = 0L -): RoborazziComposeApplierBuilder { - return with(RoborazziComposeBackgroundApplier(showBackground, backgroundColor)) +): RoborazziComposeConfigBuilder { + return with(RoborazziComposeBackgroundConfig(showBackground, backgroundColor)) } @ExperimentalRoborazziApi -data class RoborazziComposeBackgroundApplier( +data class RoborazziComposeBackgroundConfig( val showBackground: Boolean, val backgroundColor: Long -) : RoborazziComposeActivityScenarioApplier { - override fun applyToActivityScenario(scenario: ActivityScenario) { +) : RoborazziComposeActivityScenarioConfig { + override fun configureToActivityScenario(scenario: ActivityScenario) { when (showBackground) { false -> { scenario.onActivity { activity -> @@ -161,14 +161,14 @@ data class RoborazziComposeBackgroundApplier( } @ExperimentalRoborazziApi -fun RoborazziComposeApplierBuilder.uiMode(configurationUiMode: Int): RoborazziComposeApplierBuilder { - return with(UiModeApplier(configurationUiMode)) +fun RoborazziComposeConfigBuilder.uiMode(configurationUiMode: Int): RoborazziComposeConfigBuilder { + return with(UiModeConfig(configurationUiMode)) } @ExperimentalRoborazziApi -data class UiModeApplier(val uiMode: Int) : - RoborazziComposeSetupApplier { - override fun apply() { +data class UiModeConfig(val uiMode: Int) : + RoborazziComposeSetupConfig { + override fun configure() { val nightMode = when (uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) { true -> "night" @@ -179,28 +179,28 @@ data class UiModeApplier(val uiMode: Int) : } @ExperimentalRoborazziApi -fun RoborazziComposeApplierBuilder.locale(bcp47LanguageTag: String): RoborazziComposeApplierBuilder { - return with(LocaleApplier(bcp47LanguageTag)) +fun RoborazziComposeConfigBuilder.locale(bcp47LanguageTag: String): RoborazziComposeConfigBuilder { + return with(LocaleConfig(bcp47LanguageTag)) } @ExperimentalRoborazziApi -data class LocaleApplier(val locale: String) : - RoborazziComposeSetupApplier { - override fun apply() { +data class LocaleConfig(val locale: String) : + RoborazziComposeSetupConfig { + override fun configure() { val localeWithFallback = locale.ifBlank { "en" } setQualifiers("+$localeWithFallback") } } @ExperimentalRoborazziApi -fun RoborazziComposeApplierBuilder.fontScale(fontScale: Float): RoborazziComposeApplierBuilder { - return with(FontScaleApplier(fontScale)) +fun RoborazziComposeConfigBuilder.fontScale(fontScale: Float): RoborazziComposeConfigBuilder { + return with(FontScaleConfig(fontScale)) } @ExperimentalRoborazziApi -data class FontScaleApplier(val fontScale: Float) : - RoborazziComposeSetupApplier { - override fun apply() { +data class FontScaleConfig(val fontScale: Float) : + RoborazziComposeSetupConfig { + override fun configure() { setFontScale(fontScale) } } \ No newline at end of file