From f1b226378854bcf0ac3e243a57175ca5aa31ecfd Mon Sep 17 00:00:00 2001 From: Kimberly Crevecoeur Date: Fri, 6 Nov 2026 10:35:25 -0800 Subject: [PATCH 1/2] feat(ui/capture): add CaptureSlots, CaptureSlotScope, and CaptureRtlPolicy --- .../ui/components/capture/CaptureSlots.kt | 684 ++++++++++++++++++ .../ui/components/capture/TestTags.kt | 3 + .../ui/components/capture/CaptureSlotsTest.kt | 151 ++++ 3 files changed, 838 insertions(+) create mode 100644 ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureSlots.kt create mode 100644 ui/components/capture/src/test/java/com/google/jetpackcamera/ui/components/capture/CaptureSlotsTest.kt diff --git a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureSlots.kt b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureSlots.kt new file mode 100644 index 0000000000..ef837e58ff --- /dev/null +++ b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureSlots.kt @@ -0,0 +1,684 @@ +/* + * Copyright (C) 2026 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.jetpackcamera.ui.components.capture + +import androidx.compose.foundation.background +import androidx.compose.foundation.gestures.Orientation +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.text.BasicText +import androidx.compose.material3.SnackbarHostState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Immutable +import androidx.compose.runtime.ProvidableCompositionLocal +import androidx.compose.runtime.Stable +import androidx.compose.runtime.State +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp + +/** + * Shared dimension, typography, and color tokens for [CaptureSlots] placeholder scaffolding. + */ +internal object CaptureSlotTokens { + val PillCornerRadius = 24.dp + val ImageWellCornerRadius = 12.dp + val OverlayCornerRadius = 24.dp + + val IndicatorCrossAxisSize = 48.dp + val IndicatorStandardMainAxisSize = 96.dp + val IndicatorCompactMainAxisSize = 64.dp + val HorizontalTopBarHeight = 36.dp + val HorizontalTopBarStandardWidth = 120.dp + val HorizontalTopBarCompactWidth = 96.dp + + val ZoomCrossAxisSize = 48.dp + val ZoomStandardMainAxisSize = 176.dp + val ZoomCompactMainAxisSize = 148.dp + + val IconTouchTargetSize = 48.dp + val SecondaryActionStandardSize = 52.dp + val SecondaryActionCompactSize = 48.dp + + val ShutterStandardDiameter = 86.dp + val ShutterCompactDiameter = 72.dp + + val ModeToggleStandardWidth = 96.dp + val ModeToggleCompactWidth = 72.dp + val ModeToggleStandardHeight = 56.dp + val ModeToggleCompactHeight = 48.dp + + val CarouselStandardWidth = 180.dp + val CarouselCompactWidth = 140.dp + val CarouselHeight = 32.dp + + val ElapsedTimeWidth = 72.dp + val ElapsedTimeStandardHeight = 32.dp + val ElapsedTimeCompactHeight = 28.dp + + val QuickSettingsStandardWidth = 280.dp + val QuickSettingsCompactWidth = 240.dp + val QuickSettingsStandardHeight = 220.dp + val QuickSettingsCompactHeight = 160.dp + + val ErrorDialogWidth = 280.dp + val ErrorDialogHeight = 160.dp + + val PlaceholderLabelFontSize = 11.sp + val ViewfinderLabelFontSize = 14.sp + + val DefaultControlColor = Color(0xFF3949AB) + val IndicatorColor = Color(0xFF00897B) + val ZoomColor = Color(0xFF5E35B1) + val QuickSettingsButtonColor = Color(0xFF039BE5) + val ShutterColor = Color(0xFFE53935) + val FlipCameraColor = Color(0xFF43A047) + val ImageWellColor = Color(0xFFFB8C00) + val PauseAudioColor = Color(0xFFD81B60) + val ModeToggleColor = Color(0xFF8E24AA) + val CarouselColor = Color(0xFF546E7A) + val ElapsedTimeColor = Color(0xFFC62828) + val OverlayPlaceholderColor = Color(0xFF263238) + val ErrorDialogColor = Color(0xFFB71C1C) + val ViewfinderColor = Color(0xFF1E272C) + val PlaceholderLabelColor = Color.White +} + +/** + * Policy controlling whether spatial camera chrome containers mirror horizontally under + * right-to-left locales. + * + * Hardware-ergonomic camera chrome defaults to preserving physical left/right placement so + * controls stay anchored to the user's grip while inner text and directional icons follow the + * active locale's layout direction. + * + * @property mirrorSideRails Whether start and end side rails swap horizontal sides in RTL. + * @property mirrorCompactBottomBar Whether compact bottom-bar slots mirror horizontally in RTL. + */ +@Immutable +data class CaptureRtlPolicy( + val mirrorSideRails: Boolean = false, + val mirrorCompactBottomBar: Boolean = false +) + +/** + * CompositionLocal providing the active [CaptureRtlPolicy] for adaptive capture screen layouts. + */ +val LocalCaptureRtlPolicy: ProvidableCompositionLocal = + staticCompositionLocalOf { CaptureRtlPolicy() } + +/** + * Receiver scope provided to composables rendered inside [CaptureSlots]. + * + * Extends [PreviewOverlaySlotScope] with container axis orientation, compact-sizing hints, + * recording state, and a callback to dismiss an expanded Quick Settings surface. + */ +@Stable +interface CaptureSlotScope : PreviewOverlaySlotScope { + /** + * Primary axis along which the hosting container arranges its controls (for example, + * [Orientation.Vertical] in a side rail or [Orientation.Horizontal] in a bottom bar). + */ + val orientation: Orientation + + /** + * Whether the hosting container is height- or space-constrained and requests compact control + * dimensions. + */ + val isCompact: Boolean + + /** + * Whether an active video recording session is currently in progress. + */ + val isRecording: Boolean + + /** + * Requests dismissal of the Quick Settings overlay or sheet if it is currently open. + */ + fun dismissQuickSettings() +} + +private class StaticCaptureSlotScope( + override val orientation: Orientation, + override val isCompact: Boolean, + override val isOverViewfinder: Boolean, + override val isRecording: Boolean, + private val onDismissQuickSettings: () -> Unit +) : CaptureSlotScope { + override val cameraControlContainerColor: Color + get() = if (isOverViewfinder) { + CameraControlBackgroundStyle.BLACK_60.containerColor + } else { + CameraControlBackgroundStyle.WHITE_20.containerColor + } + + override fun dismissQuickSettings() { + onDismissQuickSettings() + } +} + +private class DelegatingCaptureSlotScope( + private val overlayScope: PreviewOverlaySlotScope, + override val orientation: Orientation, + override val isCompact: Boolean, + override val isRecording: Boolean, + private val onDismissQuickSettingsState: State<() -> Unit> +) : CaptureSlotScope, PreviewOverlaySlotScope by overlayScope { + override fun dismissQuickSettings() { + onDismissQuickSettingsState.value.invoke() + } +} + +/** + * Creates a standalone [CaptureSlotScope] backed by fixed state values. + * + * @param orientation Primary axis along which the hosting container arranges controls. + * @param isCompact Whether compact control sizing is requested. + * @param isOverViewfinder Whether the slot content overlaps the viewfinder. + * @param isRecording Whether video recording is currently active. + * @param onDismissQuickSettings Callback invoked when [CaptureSlotScope.dismissQuickSettings] is + * called. + * @return A [CaptureSlotScope] exposing the given state values. + */ +fun CaptureSlotScope( + orientation: Orientation = Orientation.Horizontal, + isCompact: Boolean = false, + isOverViewfinder: Boolean = true, + isRecording: Boolean = false, + onDismissQuickSettings: () -> Unit = {} +): CaptureSlotScope = StaticCaptureSlotScope( + orientation = orientation, + isCompact = isCompact, + isOverViewfinder = isOverViewfinder, + isRecording = isRecording, + onDismissQuickSettings = onDismissQuickSettings +) + +/** + * Remembers a [CaptureSlotScope] that delegates live viewfinder-overlap queries to this + * [PreviewOverlaySlotScope] while attaching container layout metadata. + */ +@Composable +internal fun PreviewOverlaySlotScope.rememberCaptureSlotScope( + orientation: Orientation = Orientation.Horizontal, + isCompact: Boolean = false, + isRecording: Boolean = false, + onDismissQuickSettings: () -> Unit = {} +): CaptureSlotScope { + val currentOnDismiss = rememberUpdatedState(onDismissQuickSettings) + return remember(this, orientation, isCompact, isRecording, currentOnDismiss) { + DelegatingCaptureSlotScope( + overlayScope = this, + orientation = orientation, + isCompact = isCompact, + isRecording = isRecording, + onDismissQuickSettingsState = currentOnDismiss + ) + } +} + +/** + * Hosts a [CaptureSlots] composable inside an [OverlapAwareStyleProvider], binding dynamic + * overlap styling and container layout metadata into a [CaptureSlotScope]. + */ +@Composable +internal fun OverlapAwareCaptureSlot( + modifier: Modifier = Modifier, + orientation: Orientation = Orientation.Horizontal, + isCompact: Boolean = false, + isRecording: Boolean = false, + onDismissQuickSettings: () -> Unit = {}, + content: @Composable CaptureSlotScope.(Modifier) -> Unit +) { + OverlapAwareStyleProvider(modifier = modifier) { + val slotScope = rememberCaptureSlotScope( + orientation = orientation, + isCompact = isCompact, + isRecording = isRecording, + onDismissQuickSettings = onDismissQuickSettings + ) + slotScope.content(Modifier) + } +} + +/** + * Slot table bundling the UI control composables placed by adaptive capture screen layouts. + * + * Each slot defaults to an empty composable (or `null` for [shutterStack]) so layouts and tests + * can populate only the controls relevant to a scenario while omitted controls collapse cleanly. + * + * @property topBar Horizontal status and indicator bar content used in top-bar layouts. + * @property indicatorColumn Vertical status indicator stack used in side-rail layouts; defaults to + * [topBar] when not overridden. + * @property topBarTrailingContent Optional trailing content aligned to the end of [topBar]. + * @property zoomControls Zoom control bar or button cluster, adapting to [CaptureSlotScope.orientation]. + * @property quickSettingsButton Trigger button that toggles the Quick Settings surface. + * @property captureButton Primary photo/video shutter button. + * @property flipCameraButton Lens-facing toggle button. + * @property imageWell Thumbnail button opening the most recently captured media item. + * @property pauseToggleButton Video recording pause/resume toggle button. + * @property audioToggleButton Video recording microphone mute/unmute toggle button. + * @property shutterStack Optional custom shutter cluster override receiving a [Modifier] and + * whether compact height sizing is active; when `null`, side rails compose the default shutter + * cluster from [flipCameraButton], [captureButton], [imageWell], and [pauseToggleButton]. + * @property captureModeToggle Photo/video capture mode toggle switch. + * @property captureModeCarousel Secondary sub-mode selector carousel. + * @property elapsedTimeDisplay Active video recording duration readout. + * @property viewfinderTopStart Overlay content anchored to the top-start of the viewfinder region. + * @property viewfinderTopEnd Overlay content anchored to the top-end of the viewfinder region. + * @property quickSettingsOverlay Expanded Quick Settings panel or sheet content. + * @property snackBar Transient message host paired with a [SnackbarHostState]. + * @property errorDialog In-hierarchy modal error dialog drawn above capture chrome. + */ +@Immutable +data class CaptureSlots( + val topBar: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val indicatorColumn: @Composable CaptureSlotScope.(Modifier) -> Unit = topBar, + val topBarTrailingContent: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val zoomControls: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val quickSettingsButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val captureButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val flipCameraButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val imageWell: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val pauseToggleButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val audioToggleButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val shutterStack: (@Composable CaptureSlotScope.(Modifier, Boolean) -> Unit)? = null, + val captureModeToggle: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val captureModeCarousel: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val elapsedTimeDisplay: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val viewfinderTopStart: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val viewfinderTopEnd: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val quickSettingsOverlay: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, + val snackBar: @Composable (Modifier, SnackbarHostState) -> Unit = { _, _ -> }, + val errorDialog: @Composable (Modifier) -> Unit = {} +) + +/** + * Minimal colored placeholder box representing a single camera control in Compose previews and + * layout geometry tests. + * + * Applies [modifier] before `.size(width, height)` so hosting layouts can prepend `Modifier.sizeIn` + * constraints to clamp dimensions in condensed windows. + * + * @param label Short debug label centered inside the control box. + * @param width Unclamped target width of the placeholder control. + * @param height Unclamped target height of the placeholder control. + * @param modifier [Modifier] applied ahead of the default size modifier. + * @param color Fill color of the placeholder shape. + * @param shape Clip shape of the placeholder box. + * @param testTag Optional semantics test tag attached to the outer box. + */ +@Composable +fun PlaceholderControlBox( + label: String, + width: Dp, + height: Dp, + modifier: Modifier = Modifier, + color: Color = CaptureSlotTokens.DefaultControlColor, + shape: Shape = RoundedCornerShape(CaptureSlotTokens.PillCornerRadius), + testTag: String? = null +) { + val taggedModifier = if (testTag != null) { + modifier.testTag(testTag) + } else { + modifier + } + Box( + modifier = taggedModifier + .size(width = width, height = height) + .clip(shape) + .background(color), + contentAlignment = Alignment.Center + ) { + BasicText( + text = label, + style = TextStyle( + color = CaptureSlotTokens.PlaceholderLabelColor, + fontSize = CaptureSlotTokens.PlaceholderLabelFontSize, + fontWeight = FontWeight.Medium, + textAlign = TextAlign.Center + ) + ) + } +} + +/** + * Minimal tinted placeholder surface representing the camera viewfinder in layout previews and + * structural tests, tagged with [PREVIEW_DISPLAY]. + * + * @param modifier [Modifier] applied to the viewfinder box before filling its allotted bounds. + * @param label Debug label centered inside the placeholder frame. + */ +@Composable +fun PlaceholderViewfinder(modifier: Modifier = Modifier, label: String = "Viewfinder") { + Box( + modifier = modifier + .testTag(PREVIEW_DISPLAY) + .fillMaxSize() + .background(CaptureSlotTokens.ViewfinderColor), + contentAlignment = Alignment.Center + ) { + BasicText( + text = label, + style = TextStyle( + color = CaptureSlotTokens.PlaceholderLabelColor, + fontSize = CaptureSlotTokens.ViewfinderLabelFontSize, + fontWeight = FontWeight.Medium, + textAlign = TextAlign.Center + ) + ) + } +} + +/** + * Factory of colored [PlaceholderControlBox]-backed [CaptureSlots] configurations for Compose + * previews and structural layout tests. + */ +object PlaceholderCaptureSlots { + /** + * Returns the default placeholder [CaptureSlots] set, delegating to [sideRail]. + * + * @param isCompactHeight Whether placeholder controls default to compact-height dimensions. + */ + fun default(isCompactHeight: Boolean = false): CaptureSlots = + sideRail(isCompactHeight = isCompactHeight) + + /** + * Builds placeholder [CaptureSlots] recycling existing capture test tags for side-rail and + * adaptive layout verification. + * + * @param isCompactHeight Whether controls default to compact-height dimensions even when the + * hosting [CaptureSlotScope.isCompact] flag is `false`. + * @param includeImageWell Whether to populate [CaptureSlots.imageWell] or leave it empty. + * @param includePauseSlot Whether to populate [CaptureSlots.pauseToggleButton] or leave it + * empty. + * @param includeElapsedTime Whether to populate [CaptureSlots.elapsedTimeDisplay] or leave it + * empty. + * @param tagQuickSettingsOverlay Whether the inner [CaptureSlots.quickSettingsOverlay] carries + * [QUICK_SETTINGS_BOTTOM_SHEET]; defaults to `false` so outer Quick Settings card containers + * can own that tag without duplicate semantics nodes. + * @param pauseSlotTag Optional test tag applied to [CaptureSlots.pauseToggleButton] when + * [includePauseSlot] is `true`. + * @param includeErrorDialog Whether to populate [CaptureSlots.errorDialog] with a placeholder + * tagged with [CAMERA_ERROR_DIALOG_TAG]. + */ + fun sideRail( + isCompactHeight: Boolean = false, + includeImageWell: Boolean = true, + includePauseSlot: Boolean = false, + includeElapsedTime: Boolean = false, + tagQuickSettingsOverlay: Boolean = false, + pauseSlotTag: String? = AUDIO_INPUT_TOGGLE, + includeErrorDialog: Boolean = false + ): CaptureSlots { + val indicatorSlot: @Composable CaptureSlotScope.(Modifier) -> Unit = { slotModifier -> + val compact = isCompactHeight || isCompact + if (orientation == Orientation.Vertical) { + PlaceholderControlBox( + label = "Ind", + width = CaptureSlotTokens.IndicatorCrossAxisSize, + height = if (compact) { + CaptureSlotTokens.IndicatorCompactMainAxisSize + } else { + CaptureSlotTokens.IndicatorStandardMainAxisSize + }, + modifier = slotModifier, + color = CaptureSlotTokens.IndicatorColor, + testTag = VIDEO_QUALITY_TAG + ) + } else { + PlaceholderControlBox( + label = "Ind", + width = if (compact) { + CaptureSlotTokens.HorizontalTopBarCompactWidth + } else { + CaptureSlotTokens.HorizontalTopBarStandardWidth + }, + height = CaptureSlotTokens.HorizontalTopBarHeight, + modifier = slotModifier, + color = CaptureSlotTokens.IndicatorColor, + testTag = VIDEO_QUALITY_TAG + ) + } + } + + return CaptureSlots( + topBar = indicatorSlot, + indicatorColumn = indicatorSlot, + zoomControls = { slotModifier -> + val compact = isCompactHeight || isCompact + val mainAxisSize = if (compact) { + CaptureSlotTokens.ZoomCompactMainAxisSize + } else { + CaptureSlotTokens.ZoomStandardMainAxisSize + } + val width = if (orientation == Orientation.Vertical) { + CaptureSlotTokens.ZoomCrossAxisSize + } else { + mainAxisSize + } + val height = if (orientation == Orientation.Vertical) { + mainAxisSize + } else { + CaptureSlotTokens.ZoomCrossAxisSize + } + PlaceholderControlBox( + label = "Zoom", + width = width, + height = height, + modifier = slotModifier, + color = CaptureSlotTokens.ZoomColor, + testTag = ZOOM_BUTTON_ROW_TAG + ) + }, + quickSettingsButton = { slotModifier -> + PlaceholderControlBox( + label = "QS", + width = CaptureSlotTokens.IconTouchTargetSize, + height = CaptureSlotTokens.IconTouchTargetSize, + modifier = slotModifier, + color = CaptureSlotTokens.QuickSettingsButtonColor, + shape = CircleShape, + testTag = QUICK_SETTINGS_DROP_DOWN + ) + }, + captureButton = { slotModifier -> + val compact = isCompactHeight || isCompact + val diameter = if (compact) { + CaptureSlotTokens.ShutterCompactDiameter + } else { + CaptureSlotTokens.ShutterStandardDiameter + } + PlaceholderControlBox( + label = "Cap", + width = diameter, + height = diameter, + modifier = slotModifier, + color = CaptureSlotTokens.ShutterColor, + shape = CircleShape, + testTag = CAPTURE_BUTTON + ) + }, + flipCameraButton = { slotModifier -> + val compact = isCompactHeight || isCompact + val size = if (compact) { + CaptureSlotTokens.SecondaryActionCompactSize + } else { + CaptureSlotTokens.SecondaryActionStandardSize + } + PlaceholderControlBox( + label = "Flip", + width = size, + height = size, + modifier = slotModifier, + color = CaptureSlotTokens.FlipCameraColor, + shape = CircleShape, + testTag = FLIP_CAMERA_BUTTON + ) + }, + imageWell = if (includeImageWell) { + { slotModifier -> + val compact = isCompactHeight || isCompact + val size = if (compact) { + CaptureSlotTokens.SecondaryActionCompactSize + } else { + CaptureSlotTokens.SecondaryActionStandardSize + } + PlaceholderControlBox( + label = "Well", + width = size, + height = size, + modifier = slotModifier, + color = CaptureSlotTokens.ImageWellColor, + shape = RoundedCornerShape(CaptureSlotTokens.ImageWellCornerRadius), + testTag = IMAGE_WELL_TAG + ) + } + } else { + {} + }, + pauseToggleButton = if (includePauseSlot) { + { slotModifier -> + PlaceholderControlBox( + label = "Pause", + width = CaptureSlotTokens.IconTouchTargetSize, + height = CaptureSlotTokens.IconTouchTargetSize, + modifier = slotModifier, + color = CaptureSlotTokens.PauseAudioColor, + shape = CircleShape, + testTag = pauseSlotTag + ) + } + } else { + {} + }, + audioToggleButton = { slotModifier -> + PlaceholderControlBox( + label = "Mic", + width = CaptureSlotTokens.IconTouchTargetSize, + height = CaptureSlotTokens.IconTouchTargetSize, + modifier = slotModifier, + color = CaptureSlotTokens.PauseAudioColor, + shape = CircleShape, + testTag = AUDIO_INPUT_TOGGLE + ) + }, + captureModeToggle = { slotModifier -> + val compact = isCompactHeight || isCompact + PlaceholderControlBox( + label = "Mode", + width = if (compact) { + CaptureSlotTokens.ModeToggleCompactWidth + } else { + CaptureSlotTokens.ModeToggleStandardWidth + }, + height = if (compact) { + CaptureSlotTokens.ModeToggleCompactHeight + } else { + CaptureSlotTokens.ModeToggleStandardHeight + }, + modifier = slotModifier, + color = CaptureSlotTokens.ModeToggleColor, + testTag = CAPTURE_MODE_TOGGLE_BUTTON + ) + }, + captureModeCarousel = { slotModifier -> + val compact = isCompactHeight || isCompact + PlaceholderControlBox( + label = "Modes", + width = if (compact) { + CaptureSlotTokens.CarouselCompactWidth + } else { + CaptureSlotTokens.CarouselStandardWidth + }, + height = CaptureSlotTokens.CarouselHeight, + modifier = slotModifier, + color = CaptureSlotTokens.CarouselColor, + testTag = CAPTURE_MODE_CAROUSEL + ) + }, + elapsedTimeDisplay = if (includeElapsedTime) { + { slotModifier -> + val compact = isCompactHeight || isCompact + PlaceholderControlBox( + label = "00:12", + width = CaptureSlotTokens.ElapsedTimeWidth, + height = if (compact) { + CaptureSlotTokens.ElapsedTimeCompactHeight + } else { + CaptureSlotTokens.ElapsedTimeStandardHeight + }, + modifier = slotModifier, + color = CaptureSlotTokens.ElapsedTimeColor, + testTag = ELAPSED_TIME_TAG + ) + } + } else { + {} + }, + quickSettingsOverlay = { slotModifier -> + val compact = isCompactHeight || isCompact + PlaceholderControlBox( + label = "Quick Settings", + width = if (compact) { + CaptureSlotTokens.QuickSettingsCompactWidth + } else { + CaptureSlotTokens.QuickSettingsStandardWidth + }, + height = if (compact) { + CaptureSlotTokens.QuickSettingsCompactHeight + } else { + CaptureSlotTokens.QuickSettingsStandardHeight + }, + modifier = slotModifier, + color = CaptureSlotTokens.OverlayPlaceholderColor, + shape = RoundedCornerShape(CaptureSlotTokens.OverlayCornerRadius), + testTag = if (tagQuickSettingsOverlay) QUICK_SETTINGS_BOTTOM_SHEET else null + ) + }, + errorDialog = if (includeErrorDialog) { + { dialogModifier -> + PlaceholderControlBox( + label = "Camera Error", + width = CaptureSlotTokens.ErrorDialogWidth, + height = CaptureSlotTokens.ErrorDialogHeight, + modifier = dialogModifier, + color = CaptureSlotTokens.ErrorDialogColor, + shape = RoundedCornerShape(CaptureSlotTokens.OverlayCornerRadius), + testTag = CAMERA_ERROR_DIALOG_TAG + ) + } + } else { + {} + } + ) + } +} diff --git a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/TestTags.kt b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/TestTags.kt index 73fe60d5c5..10a5fd9104 100644 --- a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/TestTags.kt +++ b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/TestTags.kt @@ -97,3 +97,6 @@ const val CAMERA_ERROR_DIALOG_TAG = "dialog_camera_error" const val CAMERA_ERROR_DIALOG_TITLE_TAG = "text_camera_error_title" const val CAMERA_ERROR_DIALOG_BODY_TAG = "text_camera_error_body" const val CAMERA_ERROR_DIALOG_CONFIRM_BUTTON_TAG = "btn_camera_error_confirm" + +/** Test tag for the compact controls container on the capture screen. */ +const val COMPACT_CONTROLS_TAG = "container_capture_controls_compact" diff --git a/ui/components/capture/src/test/java/com/google/jetpackcamera/ui/components/capture/CaptureSlotsTest.kt b/ui/components/capture/src/test/java/com/google/jetpackcamera/ui/components/capture/CaptureSlotsTest.kt new file mode 100644 index 0000000000..2ba4c2a4e8 --- /dev/null +++ b/ui/components/capture/src/test/java/com/google/jetpackcamera/ui/components/capture/CaptureSlotsTest.kt @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2026 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.jetpackcamera.ui.components.capture + +import androidx.compose.foundation.gestures.Orientation +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.sizeIn +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.getBoundsInRoot +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.height +import com.google.common.truth.Truth.assertThat +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner + +@RunWith(RobolectricTestRunner::class) +class CaptureSlotsTest { + + @get:Rule + val composeTestRule = createComposeRule() + + @Test + fun captureRtlPolicy_defaultsToUnmirrored_andPropagatesThroughCompositionLocal() { + var defaultPolicy: CaptureRtlPolicy? = null + var overriddenPolicy: CaptureRtlPolicy? = null + + composeTestRule.setContent { + defaultPolicy = LocalCaptureRtlPolicy.current + CompositionLocalProvider( + LocalCaptureRtlPolicy provides CaptureRtlPolicy( + mirrorSideRails = true, + mirrorCompactBottomBar = true + ) + ) { + overriddenPolicy = LocalCaptureRtlPolicy.current + } + } + + assertThat(defaultPolicy).isEqualTo( + CaptureRtlPolicy(mirrorSideRails = false, mirrorCompactBottomBar = false) + ) + assertThat(overriddenPolicy).isEqualTo( + CaptureRtlPolicy(mirrorSideRails = true, mirrorCompactBottomBar = true) + ) + } + + @Test + fun captureSlotScope_exposesMetadata_overlapContainerColors_andDismissCallback() { + var dismissedCount = 0 + val overViewfinderScope = CaptureSlotScope( + orientation = Orientation.Vertical, + isCompact = true, + isOverViewfinder = true, + isRecording = true, + onDismissQuickSettings = { dismissedCount++ } + ) + val offViewfinderScope = CaptureSlotScope( + orientation = Orientation.Horizontal, + isCompact = false, + isOverViewfinder = false, + isRecording = false + ) + + assertThat(overViewfinderScope.orientation).isEqualTo(Orientation.Vertical) + assertThat(overViewfinderScope.isCompact).isTrue() + assertThat(overViewfinderScope.isOverViewfinder).isTrue() + assertThat(overViewfinderScope.isRecording).isTrue() + assertThat(overViewfinderScope.cameraControlContainerColor).isEqualTo( + CameraControlBackgroundStyle.BLACK_60.containerColor + ) + + overViewfinderScope.dismissQuickSettings() + assertThat(dismissedCount).isEqualTo(1) + + assertThat(offViewfinderScope.orientation).isEqualTo(Orientation.Horizontal) + assertThat(offViewfinderScope.isCompact).isFalse() + assertThat(offViewfinderScope.isOverViewfinder).isFalse() + assertThat(offViewfinderScope.isRecording).isFalse() + assertThat(offViewfinderScope.cameraControlContainerColor).isEqualTo( + CameraControlBackgroundStyle.WHITE_20.containerColor + ) + } + + @Test + fun captureSlots_indicatorColumnDefaultsToTopBar_andPlaceholdersRecycleExistingTags() { + val customSlots = CaptureSlots( + topBar = { modifier -> + Box(modifier.size(48.dp).testTag(VIDEO_QUALITY_TAG)) + } + ) + val defaultPlaceholders = PlaceholderCaptureSlots.default() + val taggedOverlayPlaceholders = PlaceholderCaptureSlots.sideRail( + tagQuickSettingsOverlay = true + ) + val slotScope = CaptureSlotScope(orientation = Orientation.Vertical) + var useTaggedOverlay by mutableStateOf(false) + + composeTestRule.setContent { + Box(modifier = Modifier.size(400.dp)) { + PlaceholderViewfinder() + with(slotScope) { + customSlots.indicatorColumn(this, Modifier) + defaultPlaceholders.zoomControls( + this, + Modifier.sizeIn(maxHeight = 40.dp) + ) + if (useTaggedOverlay) { + taggedOverlayPlaceholders.quickSettingsOverlay(this, Modifier) + } else { + defaultPlaceholders.quickSettingsOverlay(this, Modifier) + } + } + } + } + + composeTestRule.onNodeWithTag(PREVIEW_DISPLAY).assertIsDisplayed() + composeTestRule.onNodeWithTag(VIDEO_QUALITY_TAG).assertIsDisplayed() + composeTestRule.onNodeWithTag(QUICK_SETTINGS_BOTTOM_SHEET).assertDoesNotExist() + + val clampedZoomBounds = composeTestRule.onNodeWithTag(ZOOM_BUTTON_ROW_TAG).getBoundsInRoot() + assertThat(clampedZoomBounds.height).isEqualTo(40.dp) + + useTaggedOverlay = true + composeTestRule.waitForIdle() + composeTestRule.onNodeWithTag(QUICK_SETTINGS_BOTTOM_SHEET).assertIsDisplayed() + } +} From 9414a2ce9c44af43f5712d4ac82f80c56f1d52ec Mon Sep 17 00:00:00 2001 From: Kimberly Crevecoeur Date: Wed, 11 Nov 2026 12:46:46 -0800 Subject: [PATCH 2/2] Consolidate CaptureSlotScope and internal CaptureSlots onto CaptureScaffold --- .../ui/components/capture/CaptureScaffold.kt | 58 +- .../ui/components/capture/CaptureSlots.kt | 562 +++++++----------- .../capture/OverlapAwareStyleProvider.kt | 66 +- .../ui/components/capture/TestTags.kt | 3 - .../ui/components/capture/CaptureSlotsTest.kt | 17 +- 5 files changed, 310 insertions(+), 396 deletions(-) diff --git a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureScaffold.kt b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureScaffold.kt index 577837dd27..7549f04e0f 100644 --- a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureScaffold.kt +++ b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureScaffold.kt @@ -25,6 +25,7 @@ import androidx.compose.animation.ExitTransition import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut +import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material3.MaterialTheme @@ -170,12 +171,25 @@ fun rememberCaptureScaffoldState(isInitiallyExpanded: Boolean = false): CaptureS /** * Receiver scope for [CaptureScaffold] slots. * - * Extends [PreviewOverlaySlotScope] with capture session state, Quick Settings controls, and zoom - * actions coordinated with the scaffold's [ZoomStateManager]. Properties are backed by - * `derivedStateOf` so that slots only recompose when a property they actually read changes. + * Extends [PreviewOverlaySlotScope] with container axis orientation, compact-sizing hints, capture + * session state, Quick Settings controls, and zoom actions coordinated with the scaffold's + * [ZoomStateManager]. Properties are backed by `derivedStateOf` so that slots only recompose when a + * property they actually read changes. */ @Stable sealed interface CaptureSlotScope : PreviewOverlaySlotScope { + /** + * Primary axis along which the hosting container arranges its controls (for example, + * [Orientation.Vertical] in a side rail or [Orientation.Horizontal] in a top or bottom bar). + */ + override val orientation: Orientation + + /** + * Whether the hosting container is height- or space-constrained and requests compact control + * dimensions. + */ + override val isCompact: Boolean + /** * Whether a video recording is currently active (recording or paused). */ @@ -219,6 +233,8 @@ sealed interface CaptureSlotScope : PreviewOverlaySlotScope { * Creates a [CaptureSlotScope] with static values for Compose `@Preview`s and unit tests. */ fun CaptureSlotScope( + orientation: Orientation = Orientation.Horizontal, + isCompact: Boolean = false, isOverViewfinder: Boolean = true, isRecording: Boolean = false, isQuickSettingsOpen: Boolean = false, @@ -228,6 +244,8 @@ fun CaptureSlotScope( onAnimateZoomTo: (Float, LensToZoom) -> Unit = { _, _ -> }, onSetAbsoluteZoom: (Float, LensToZoom) -> Unit = { _, _ -> } ): CaptureSlotScope = StaticCaptureSlotScope( + orientation = orientation, + isCompact = isCompact, isOverViewfinder = isOverViewfinder, isRecording = isRecording, isQuickSettingsOpen = isQuickSettingsOpen, @@ -239,6 +257,8 @@ fun CaptureSlotScope( ) private class StaticCaptureSlotScope( + override val orientation: Orientation, + override val isCompact: Boolean, override val isOverViewfinder: Boolean, override val isRecording: Boolean, override val isQuickSettingsOpen: Boolean, @@ -282,6 +302,12 @@ private class CaptureSlotScopeImpl( private val onAnimateZoomTo: (Float, LensToZoom) -> Unit, private val onSetAbsoluteZoom: (Float, LensToZoom) -> Unit ) : CaptureSlotScope { + override val orientation: Orientation + get() = overlayScope.orientation + + override val isCompact: Boolean + get() = overlayScope.isCompact + override val isOverViewfinder: Boolean get() = overlayScope.isOverViewfinder @@ -1095,22 +1121,16 @@ fun CaptureScaffold( onAnimateZoomTo, onSetAbsoluteZoom ) { - object : PreviewOverlaySlotScope { - override val isOverViewfinder: Boolean = false - override val cameraControlContainerColor: Color = - backgroundStyleFor(false).containerColor - }.let { overlayScope -> - CaptureSlotScopeImpl( - overlayScope = overlayScope, - isRecordingState = isVideoRecordingActive, - scaffoldState = state, - onToggleQuickSettings = onToggleQuickSettings, - onDismissQuickSettings = onDismissQuickSettings, - onIncrementZoom = onIncrementZoom, - onAnimateZoomTo = onAnimateZoomTo, - onSetAbsoluteZoom = onSetAbsoluteZoom - ) - } + CaptureSlotScopeImpl( + overlayScope = PreviewOverlaySlotScope(isOverViewfinder = false), + isRecordingState = isVideoRecordingActive, + scaffoldState = state, + onToggleQuickSettings = onToggleQuickSettings, + onDismissQuickSettings = onDismissQuickSettings, + onIncrementZoom = onIncrementZoom, + onAnimateZoomTo = onAnimateZoomTo, + onSetAbsoluteZoom = onSetAbsoluteZoom + ) } CaptureScaffoldLayout( diff --git a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureSlots.kt b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureSlots.kt index ef837e58ff..1516d46d64 100644 --- a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureSlots.kt +++ b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/CaptureSlots.kt @@ -27,10 +27,6 @@ import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable import androidx.compose.runtime.ProvidableCompositionLocal -import androidx.compose.runtime.Stable -import androidx.compose.runtime.State -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -102,7 +98,6 @@ internal object CaptureSlotTokens { val ShutterColor = Color(0xFFE53935) val FlipCameraColor = Color(0xFF43A047) val ImageWellColor = Color(0xFFFB8C00) - val PauseAudioColor = Color(0xFFD81B60) val ModeToggleColor = Color(0xFF8E24AA) val CarouselColor = Color(0xFF546E7A) val ElapsedTimeColor = Color(0xFFC62828) @@ -135,188 +130,70 @@ data class CaptureRtlPolicy( val LocalCaptureRtlPolicy: ProvidableCompositionLocal = staticCompositionLocalOf { CaptureRtlPolicy() } -/** - * Receiver scope provided to composables rendered inside [CaptureSlots]. - * - * Extends [PreviewOverlaySlotScope] with container axis orientation, compact-sizing hints, - * recording state, and a callback to dismiss an expanded Quick Settings surface. - */ -@Stable -interface CaptureSlotScope : PreviewOverlaySlotScope { - /** - * Primary axis along which the hosting container arranges its controls (for example, - * [Orientation.Vertical] in a side rail or [Orientation.Horizontal] in a bottom bar). - */ - val orientation: Orientation - - /** - * Whether the hosting container is height- or space-constrained and requests compact control - * dimensions. - */ - val isCompact: Boolean - - /** - * Whether an active video recording session is currently in progress. - */ - val isRecording: Boolean - - /** - * Requests dismissal of the Quick Settings overlay or sheet if it is currently open. - */ - fun dismissQuickSettings() -} - -private class StaticCaptureSlotScope( - override val orientation: Orientation, - override val isCompact: Boolean, - override val isOverViewfinder: Boolean, - override val isRecording: Boolean, - private val onDismissQuickSettings: () -> Unit -) : CaptureSlotScope { - override val cameraControlContainerColor: Color - get() = if (isOverViewfinder) { - CameraControlBackgroundStyle.BLACK_60.containerColor - } else { - CameraControlBackgroundStyle.WHITE_20.containerColor - } - - override fun dismissQuickSettings() { - onDismissQuickSettings() - } -} - -private class DelegatingCaptureSlotScope( - private val overlayScope: PreviewOverlaySlotScope, - override val orientation: Orientation, - override val isCompact: Boolean, - override val isRecording: Boolean, - private val onDismissQuickSettingsState: State<() -> Unit> -) : CaptureSlotScope, PreviewOverlaySlotScope by overlayScope { - override fun dismissQuickSettings() { - onDismissQuickSettingsState.value.invoke() - } -} - -/** - * Creates a standalone [CaptureSlotScope] backed by fixed state values. - * - * @param orientation Primary axis along which the hosting container arranges controls. - * @param isCompact Whether compact control sizing is requested. - * @param isOverViewfinder Whether the slot content overlaps the viewfinder. - * @param isRecording Whether video recording is currently active. - * @param onDismissQuickSettings Callback invoked when [CaptureSlotScope.dismissQuickSettings] is - * called. - * @return A [CaptureSlotScope] exposing the given state values. - */ -fun CaptureSlotScope( - orientation: Orientation = Orientation.Horizontal, - isCompact: Boolean = false, - isOverViewfinder: Boolean = true, - isRecording: Boolean = false, - onDismissQuickSettings: () -> Unit = {} -): CaptureSlotScope = StaticCaptureSlotScope( - orientation = orientation, - isCompact = isCompact, - isOverViewfinder = isOverViewfinder, - isRecording = isRecording, - onDismissQuickSettings = onDismissQuickSettings -) - -/** - * Remembers a [CaptureSlotScope] that delegates live viewfinder-overlap queries to this - * [PreviewOverlaySlotScope] while attaching container layout metadata. - */ -@Composable -internal fun PreviewOverlaySlotScope.rememberCaptureSlotScope( - orientation: Orientation = Orientation.Horizontal, - isCompact: Boolean = false, - isRecording: Boolean = false, - onDismissQuickSettings: () -> Unit = {} -): CaptureSlotScope { - val currentOnDismiss = rememberUpdatedState(onDismissQuickSettings) - return remember(this, orientation, isCompact, isRecording, currentOnDismiss) { - DelegatingCaptureSlotScope( - overlayScope = this, - orientation = orientation, - isCompact = isCompact, - isRecording = isRecording, - onDismissQuickSettingsState = currentOnDismiss - ) - } -} - /** * Hosts a [CaptureSlots] composable inside an [OverlapAwareStyleProvider], binding dynamic - * overlap styling and container layout metadata into a [CaptureSlotScope]. + * overlap styling and container layout metadata ([orientation], [isCompact]) into a + * [PreviewOverlaySlotScope]. */ @Composable internal fun OverlapAwareCaptureSlot( modifier: Modifier = Modifier, orientation: Orientation = Orientation.Horizontal, isCompact: Boolean = false, - isRecording: Boolean = false, - onDismissQuickSettings: () -> Unit = {}, - content: @Composable CaptureSlotScope.(Modifier) -> Unit + content: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit ) { - OverlapAwareStyleProvider(modifier = modifier) { - val slotScope = rememberCaptureSlotScope( - orientation = orientation, - isCompact = isCompact, - isRecording = isRecording, - onDismissQuickSettings = onDismissQuickSettings - ) - slotScope.content(Modifier) + OverlapAwareStyleProvider( + modifier = modifier, + orientation = orientation, + isCompact = isCompact + ) { + content(Modifier) } } /** * Slot table bundling the UI control composables placed by adaptive capture screen layouts. * - * Each slot defaults to an empty composable (or `null` for [shutterStack]) so layouts and tests - * can populate only the controls relevant to a scenario while omitted controls collapse cleanly. + * Each slot defaults to an empty composable so layouts and tests can populate only the controls + * relevant to a scenario while omitted controls collapse cleanly. Slots receive + * [PreviewOverlaySlotScope], which exposes live viewfinder overlap styling together with + * [PreviewOverlaySlotScope.orientation] and [PreviewOverlaySlotScope.isCompact] from the hosting + * layout container (and propagates directly into [CaptureSlotScope] when hosted by + * [CaptureScaffold]). * - * @property topBar Horizontal status and indicator bar content used in top-bar layouts. - * @property indicatorColumn Vertical status indicator stack used in side-rail layouts; defaults to - * [topBar] when not overridden. + * @property topBar Status indicator bar or column content adapting to + * [PreviewOverlaySlotScope.orientation]. * @property topBarTrailingContent Optional trailing content aligned to the end of [topBar]. - * @property zoomControls Zoom control bar or button cluster, adapting to [CaptureSlotScope.orientation]. + * @property zoomControls Zoom control bar or button cluster, adapting to + * [PreviewOverlaySlotScope.orientation]. * @property quickSettingsButton Trigger button that toggles the Quick Settings surface. * @property captureButton Primary photo/video shutter button. * @property flipCameraButton Lens-facing toggle button. * @property imageWell Thumbnail button opening the most recently captured media item. - * @property pauseToggleButton Video recording pause/resume toggle button. - * @property audioToggleButton Video recording microphone mute/unmute toggle button. - * @property shutterStack Optional custom shutter cluster override receiving a [Modifier] and - * whether compact height sizing is active; when `null`, side rails compose the default shutter - * cluster from [flipCameraButton], [captureButton], [imageWell], and [pauseToggleButton]. * @property captureModeToggle Photo/video capture mode toggle switch. * @property captureModeCarousel Secondary sub-mode selector carousel. * @property elapsedTimeDisplay Active video recording duration readout. - * @property viewfinderTopStart Overlay content anchored to the top-start of the viewfinder region. - * @property viewfinderTopEnd Overlay content anchored to the top-end of the viewfinder region. + * @property topStartContent Overlay content anchored to the top-start of the capture region. + * @property viewfinderTopEndContent Overlay content anchored to the top-end of the viewfinder. * @property quickSettingsOverlay Expanded Quick Settings panel or sheet content. * @property snackBar Transient message host paired with a [SnackbarHostState]. * @property errorDialog In-hierarchy modal error dialog drawn above capture chrome. */ @Immutable -data class CaptureSlots( - val topBar: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val indicatorColumn: @Composable CaptureSlotScope.(Modifier) -> Unit = topBar, - val topBarTrailingContent: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val zoomControls: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val quickSettingsButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val captureButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val flipCameraButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val imageWell: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val pauseToggleButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val audioToggleButton: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val shutterStack: (@Composable CaptureSlotScope.(Modifier, Boolean) -> Unit)? = null, - val captureModeToggle: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val captureModeCarousel: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val elapsedTimeDisplay: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val viewfinderTopStart: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val viewfinderTopEnd: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, - val quickSettingsOverlay: @Composable CaptureSlotScope.(Modifier) -> Unit = {}, +internal data class CaptureSlots( + val topBar: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val topBarTrailingContent: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val zoomControls: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val quickSettingsButton: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val captureButton: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val flipCameraButton: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val imageWell: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val captureModeToggle: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val captureModeCarousel: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val elapsedTimeDisplay: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val topStartContent: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val viewfinderTopEndContent: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, + val quickSettingsOverlay: @Composable PreviewOverlaySlotScope.(Modifier) -> Unit = {}, val snackBar: @Composable (Modifier, SnackbarHostState) -> Unit = { _, _ -> }, val errorDialog: @Composable (Modifier) -> Unit = {} ) @@ -337,7 +214,7 @@ data class CaptureSlots( * @param testTag Optional semantics test tag attached to the outer box. */ @Composable -fun PlaceholderControlBox( +internal fun PlaceholderControlBox( label: String, width: Dp, height: Dp, @@ -378,7 +255,7 @@ fun PlaceholderControlBox( * @param label Debug label centered inside the placeholder frame. */ @Composable -fun PlaceholderViewfinder(modifier: Modifier = Modifier, label: String = "Viewfinder") { +internal fun PlaceholderViewfinder(modifier: Modifier = Modifier, label: String = "Viewfinder") { Box( modifier = modifier .testTag(PREVIEW_DISPLAY) @@ -402,7 +279,7 @@ fun PlaceholderViewfinder(modifier: Modifier = Modifier, label: String = "Viewfi * Factory of colored [PlaceholderControlBox]-backed [CaptureSlots] configurations for Compose * previews and structural layout tests. */ -object PlaceholderCaptureSlots { +internal object PlaceholderCaptureSlots { /** * Returns the default placeholder [CaptureSlots] set, delegating to [sideRail]. * @@ -416,30 +293,24 @@ object PlaceholderCaptureSlots { * adaptive layout verification. * * @param isCompactHeight Whether controls default to compact-height dimensions even when the - * hosting [CaptureSlotScope.isCompact] flag is `false`. + * hosting [PreviewOverlaySlotScope.isCompact] flag is `false`. * @param includeImageWell Whether to populate [CaptureSlots.imageWell] or leave it empty. - * @param includePauseSlot Whether to populate [CaptureSlots.pauseToggleButton] or leave it - * empty. * @param includeElapsedTime Whether to populate [CaptureSlots.elapsedTimeDisplay] or leave it * empty. * @param tagQuickSettingsOverlay Whether the inner [CaptureSlots.quickSettingsOverlay] carries * [QUICK_SETTINGS_BOTTOM_SHEET]; defaults to `false` so outer Quick Settings card containers * can own that tag without duplicate semantics nodes. - * @param pauseSlotTag Optional test tag applied to [CaptureSlots.pauseToggleButton] when - * [includePauseSlot] is `true`. * @param includeErrorDialog Whether to populate [CaptureSlots.errorDialog] with a placeholder * tagged with [CAMERA_ERROR_DIALOG_TAG]. */ fun sideRail( isCompactHeight: Boolean = false, includeImageWell: Boolean = true, - includePauseSlot: Boolean = false, includeElapsedTime: Boolean = false, tagQuickSettingsOverlay: Boolean = false, - pauseSlotTag: String? = AUDIO_INPUT_TOGGLE, includeErrorDialog: Boolean = false - ): CaptureSlots { - val indicatorSlot: @Composable CaptureSlotScope.(Modifier) -> Unit = { slotModifier -> + ): CaptureSlots = CaptureSlots( + topBar = { slotModifier -> val compact = isCompactHeight || isCompact if (orientation == Orientation.Vertical) { PlaceholderControlBox( @@ -468,66 +339,80 @@ object PlaceholderCaptureSlots { testTag = VIDEO_QUALITY_TAG ) } - } - - return CaptureSlots( - topBar = indicatorSlot, - indicatorColumn = indicatorSlot, - zoomControls = { slotModifier -> - val compact = isCompactHeight || isCompact - val mainAxisSize = if (compact) { - CaptureSlotTokens.ZoomCompactMainAxisSize - } else { - CaptureSlotTokens.ZoomStandardMainAxisSize - } - val width = if (orientation == Orientation.Vertical) { - CaptureSlotTokens.ZoomCrossAxisSize - } else { - mainAxisSize - } - val height = if (orientation == Orientation.Vertical) { - mainAxisSize - } else { - CaptureSlotTokens.ZoomCrossAxisSize - } - PlaceholderControlBox( - label = "Zoom", - width = width, - height = height, - modifier = slotModifier, - color = CaptureSlotTokens.ZoomColor, - testTag = ZOOM_BUTTON_ROW_TAG - ) - }, - quickSettingsButton = { slotModifier -> - PlaceholderControlBox( - label = "QS", - width = CaptureSlotTokens.IconTouchTargetSize, - height = CaptureSlotTokens.IconTouchTargetSize, - modifier = slotModifier, - color = CaptureSlotTokens.QuickSettingsButtonColor, - shape = CircleShape, - testTag = QUICK_SETTINGS_DROP_DOWN - ) - }, - captureButton = { slotModifier -> - val compact = isCompactHeight || isCompact - val diameter = if (compact) { - CaptureSlotTokens.ShutterCompactDiameter - } else { - CaptureSlotTokens.ShutterStandardDiameter - } - PlaceholderControlBox( - label = "Cap", - width = diameter, - height = diameter, - modifier = slotModifier, - color = CaptureSlotTokens.ShutterColor, - shape = CircleShape, - testTag = CAPTURE_BUTTON - ) - }, - flipCameraButton = { slotModifier -> + }, + zoomControls = { slotModifier -> + val compact = isCompactHeight || isCompact + val mainAxisSize = if (compact) { + CaptureSlotTokens.ZoomCompactMainAxisSize + } else { + CaptureSlotTokens.ZoomStandardMainAxisSize + } + val width = if (orientation == Orientation.Vertical) { + CaptureSlotTokens.ZoomCrossAxisSize + } else { + mainAxisSize + } + val height = if (orientation == Orientation.Vertical) { + mainAxisSize + } else { + CaptureSlotTokens.ZoomCrossAxisSize + } + PlaceholderControlBox( + label = "Zoom", + width = width, + height = height, + modifier = slotModifier, + color = CaptureSlotTokens.ZoomColor, + testTag = ZOOM_BUTTON_ROW_TAG + ) + }, + quickSettingsButton = { slotModifier -> + PlaceholderControlBox( + label = "QS", + width = CaptureSlotTokens.IconTouchTargetSize, + height = CaptureSlotTokens.IconTouchTargetSize, + modifier = slotModifier, + color = CaptureSlotTokens.QuickSettingsButtonColor, + shape = CircleShape, + testTag = QUICK_SETTINGS_DROP_DOWN + ) + }, + captureButton = { slotModifier -> + val compact = isCompactHeight || isCompact + val diameter = if (compact) { + CaptureSlotTokens.ShutterCompactDiameter + } else { + CaptureSlotTokens.ShutterStandardDiameter + } + PlaceholderControlBox( + label = "Cap", + width = diameter, + height = diameter, + modifier = slotModifier, + color = CaptureSlotTokens.ShutterColor, + shape = CircleShape, + testTag = CAPTURE_BUTTON + ) + }, + flipCameraButton = { slotModifier -> + val compact = isCompactHeight || isCompact + val size = if (compact) { + CaptureSlotTokens.SecondaryActionCompactSize + } else { + CaptureSlotTokens.SecondaryActionStandardSize + } + PlaceholderControlBox( + label = "Flip", + width = size, + height = size, + modifier = slotModifier, + color = CaptureSlotTokens.FlipCameraColor, + shape = CircleShape, + testTag = FLIP_CAMERA_BUTTON + ) + }, + imageWell = if (includeImageWell) { + { slotModifier -> val compact = isCompactHeight || isCompact val size = if (compact) { CaptureSlotTokens.SecondaryActionCompactSize @@ -535,150 +420,105 @@ object PlaceholderCaptureSlots { CaptureSlotTokens.SecondaryActionStandardSize } PlaceholderControlBox( - label = "Flip", + label = "Well", width = size, height = size, modifier = slotModifier, - color = CaptureSlotTokens.FlipCameraColor, - shape = CircleShape, - testTag = FLIP_CAMERA_BUTTON + color = CaptureSlotTokens.ImageWellColor, + shape = RoundedCornerShape(CaptureSlotTokens.ImageWellCornerRadius), + testTag = IMAGE_WELL_TAG ) - }, - imageWell = if (includeImageWell) { - { slotModifier -> - val compact = isCompactHeight || isCompact - val size = if (compact) { - CaptureSlotTokens.SecondaryActionCompactSize - } else { - CaptureSlotTokens.SecondaryActionStandardSize - } - PlaceholderControlBox( - label = "Well", - width = size, - height = size, - modifier = slotModifier, - color = CaptureSlotTokens.ImageWellColor, - shape = RoundedCornerShape(CaptureSlotTokens.ImageWellCornerRadius), - testTag = IMAGE_WELL_TAG - ) - } - } else { - {} - }, - pauseToggleButton = if (includePauseSlot) { - { slotModifier -> - PlaceholderControlBox( - label = "Pause", - width = CaptureSlotTokens.IconTouchTargetSize, - height = CaptureSlotTokens.IconTouchTargetSize, - modifier = slotModifier, - color = CaptureSlotTokens.PauseAudioColor, - shape = CircleShape, - testTag = pauseSlotTag - ) - } - } else { - {} - }, - audioToggleButton = { slotModifier -> - PlaceholderControlBox( - label = "Mic", - width = CaptureSlotTokens.IconTouchTargetSize, - height = CaptureSlotTokens.IconTouchTargetSize, - modifier = slotModifier, - color = CaptureSlotTokens.PauseAudioColor, - shape = CircleShape, - testTag = AUDIO_INPUT_TOGGLE - ) - }, - captureModeToggle = { slotModifier -> + } + } else { + {} + }, + captureModeToggle = { slotModifier -> + val compact = isCompactHeight || isCompact + PlaceholderControlBox( + label = "Mode", + width = if (compact) { + CaptureSlotTokens.ModeToggleCompactWidth + } else { + CaptureSlotTokens.ModeToggleStandardWidth + }, + height = if (compact) { + CaptureSlotTokens.ModeToggleCompactHeight + } else { + CaptureSlotTokens.ModeToggleStandardHeight + }, + modifier = slotModifier, + color = CaptureSlotTokens.ModeToggleColor, + testTag = CAPTURE_MODE_TOGGLE_BUTTON + ) + }, + captureModeCarousel = { slotModifier -> + val compact = isCompactHeight || isCompact + PlaceholderControlBox( + label = "Modes", + width = if (compact) { + CaptureSlotTokens.CarouselCompactWidth + } else { + CaptureSlotTokens.CarouselStandardWidth + }, + height = CaptureSlotTokens.CarouselHeight, + modifier = slotModifier, + color = CaptureSlotTokens.CarouselColor, + testTag = CAPTURE_MODE_CAROUSEL + ) + }, + elapsedTimeDisplay = if (includeElapsedTime) { + { slotModifier -> val compact = isCompactHeight || isCompact PlaceholderControlBox( - label = "Mode", - width = if (compact) { - CaptureSlotTokens.ModeToggleCompactWidth - } else { - CaptureSlotTokens.ModeToggleStandardWidth - }, + label = "00:12", + width = CaptureSlotTokens.ElapsedTimeWidth, height = if (compact) { - CaptureSlotTokens.ModeToggleCompactHeight - } else { - CaptureSlotTokens.ModeToggleStandardHeight - }, - modifier = slotModifier, - color = CaptureSlotTokens.ModeToggleColor, - testTag = CAPTURE_MODE_TOGGLE_BUTTON - ) - }, - captureModeCarousel = { slotModifier -> - val compact = isCompactHeight || isCompact - PlaceholderControlBox( - label = "Modes", - width = if (compact) { - CaptureSlotTokens.CarouselCompactWidth + CaptureSlotTokens.ElapsedTimeCompactHeight } else { - CaptureSlotTokens.CarouselStandardWidth + CaptureSlotTokens.ElapsedTimeStandardHeight }, - height = CaptureSlotTokens.CarouselHeight, modifier = slotModifier, - color = CaptureSlotTokens.CarouselColor, - testTag = CAPTURE_MODE_CAROUSEL + color = CaptureSlotTokens.ElapsedTimeColor, + testTag = ELAPSED_TIME_TAG ) - }, - elapsedTimeDisplay = if (includeElapsedTime) { - { slotModifier -> - val compact = isCompactHeight || isCompact - PlaceholderControlBox( - label = "00:12", - width = CaptureSlotTokens.ElapsedTimeWidth, - height = if (compact) { - CaptureSlotTokens.ElapsedTimeCompactHeight - } else { - CaptureSlotTokens.ElapsedTimeStandardHeight - }, - modifier = slotModifier, - color = CaptureSlotTokens.ElapsedTimeColor, - testTag = ELAPSED_TIME_TAG - ) - } - } else { - {} - }, - quickSettingsOverlay = { slotModifier -> - val compact = isCompactHeight || isCompact + } + } else { + {} + }, + quickSettingsOverlay = { slotModifier -> + val compact = isCompactHeight || isCompact + PlaceholderControlBox( + label = "Quick Settings", + width = if (compact) { + CaptureSlotTokens.QuickSettingsCompactWidth + } else { + CaptureSlotTokens.QuickSettingsStandardWidth + }, + height = if (compact) { + CaptureSlotTokens.QuickSettingsCompactHeight + } else { + CaptureSlotTokens.QuickSettingsStandardHeight + }, + modifier = slotModifier, + color = CaptureSlotTokens.OverlayPlaceholderColor, + shape = RoundedCornerShape(CaptureSlotTokens.OverlayCornerRadius), + testTag = if (tagQuickSettingsOverlay) QUICK_SETTINGS_BOTTOM_SHEET else null + ) + }, + errorDialog = if (includeErrorDialog) { + { dialogModifier -> PlaceholderControlBox( - label = "Quick Settings", - width = if (compact) { - CaptureSlotTokens.QuickSettingsCompactWidth - } else { - CaptureSlotTokens.QuickSettingsStandardWidth - }, - height = if (compact) { - CaptureSlotTokens.QuickSettingsCompactHeight - } else { - CaptureSlotTokens.QuickSettingsStandardHeight - }, - modifier = slotModifier, - color = CaptureSlotTokens.OverlayPlaceholderColor, + label = "Camera Error", + width = CaptureSlotTokens.ErrorDialogWidth, + height = CaptureSlotTokens.ErrorDialogHeight, + modifier = dialogModifier, + color = CaptureSlotTokens.ErrorDialogColor, shape = RoundedCornerShape(CaptureSlotTokens.OverlayCornerRadius), - testTag = if (tagQuickSettingsOverlay) QUICK_SETTINGS_BOTTOM_SHEET else null + testTag = CAMERA_ERROR_DIALOG_TAG ) - }, - errorDialog = if (includeErrorDialog) { - { dialogModifier -> - PlaceholderControlBox( - label = "Camera Error", - width = CaptureSlotTokens.ErrorDialogWidth, - height = CaptureSlotTokens.ErrorDialogHeight, - modifier = dialogModifier, - color = CaptureSlotTokens.ErrorDialogColor, - shape = RoundedCornerShape(CaptureSlotTokens.OverlayCornerRadius), - testTag = CAMERA_ERROR_DIALOG_TAG - ) - } - } else { - {} } - ) - } + } else { + {} + } + ) } diff --git a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/OverlapAwareStyleProvider.kt b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/OverlapAwareStyleProvider.kt index 0a4cab812d..22559ebe18 100644 --- a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/OverlapAwareStyleProvider.kt +++ b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/OverlapAwareStyleProvider.kt @@ -15,6 +15,7 @@ */ package com.google.jetpackcamera.ui.components.capture +import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.layout.Box import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider @@ -36,7 +37,9 @@ import androidx.compose.ui.layout.onGloballyPositioned * viewfinder or over the background around it. * * Content can use [isOverViewfinder] to choose its own colors, or use - * [cameraControlContainerColor] to match the built-in camera controls. + * [cameraControlContainerColor] to match the built-in camera controls. Adaptive containers such as + * side rails and condensed panes also expose [orientation] and [isCompact] so controls can adapt + * their axis and dimensions to the hosting slot. */ @Stable interface PreviewOverlaySlotScope { @@ -53,10 +56,49 @@ interface PreviewOverlaySlotScope { * it. Using this color is optional. */ val cameraControlContainerColor: Color + + /** + * Primary axis along which the hosting container arranges its controls (for example, + * [Orientation.Vertical] in a side rail or [Orientation.Horizontal] in a top or bottom bar). + */ + val orientation: Orientation + get() = Orientation.Horizontal + + /** + * Whether the hosting container is height- or space-constrained and requests compact control + * dimensions. + */ + val isCompact: Boolean + get() = false +} + +/** + * Creates a standalone [PreviewOverlaySlotScope] backed by fixed values for non-overlapping + * surfaces, Compose previews, and unit tests. + */ +internal fun PreviewOverlaySlotScope( + isOverViewfinder: Boolean = true, + orientation: Orientation = Orientation.Horizontal, + isCompact: Boolean = false +): PreviewOverlaySlotScope = StaticPreviewOverlaySlotScope( + isOverViewfinder = isOverViewfinder, + orientation = orientation, + isCompact = isCompact +) + +private class StaticPreviewOverlaySlotScope( + override val isOverViewfinder: Boolean, + override val orientation: Orientation, + override val isCompact: Boolean +) : PreviewOverlaySlotScope { + override val cameraControlContainerColor: Color + get() = backgroundStyleFor(isOverViewfinder).containerColor } private class PreviewOverlaySlotScopeImpl( - private val isOverViewfinderState: State + private val isOverViewfinderState: State, + override val orientation: Orientation = Orientation.Horizontal, + override val isCompact: Boolean = false ) : PreviewOverlaySlotScope { override val isOverViewfinder: Boolean get() = isOverViewfinderState.value @@ -76,17 +118,23 @@ internal fun backgroundStyleFor(isOverlapping: Boolean): CameraControlBackground * Applies [LocalCameraControlBackgroundStyle] based on whether this * component's spatial bounds overlap with the [LocalOverlapTargetBounds]. * - * The [content] also receives the overlap result through [PreviewOverlaySlotScope], so that - * content supplied by callers outside this module can adapt its own styling. + * The [content] also receives the overlap result and container layout hints through + * [PreviewOverlaySlotScope], so that content supplied by callers outside this module can adapt its + * own styling and axis orientation. * * @param modifier The [Modifier] to be applied to the outer layout. * @param overlapThreshold The ratio of overlap (between 0.0 and 1.0) required to switch the style. - * @param content The composable content that will receive the computed [LocalCameraControlBackgroundStyle]. + * @param orientation Primary axis along which the hosting container arranges its controls. + * @param isCompact Whether compact control sizing is requested by the hosting container. + * @param content The composable content that will receive the computed + * [LocalCameraControlBackgroundStyle]. */ @Composable internal fun OverlapAwareStyleProvider( modifier: Modifier = Modifier, overlapThreshold: Float = 0.5f, + orientation: Orientation = Orientation.Horizontal, + isCompact: Boolean = false, content: @Composable PreviewOverlaySlotScope.() -> Unit ) { val targetBoundsState = LocalOverlapTargetBounds.current @@ -100,7 +148,13 @@ internal fun OverlapAwareStyleProvider( myArea > 0f && (intersectArea / myArea) >= overlapThreshold } } - val scope = remember(isOverlappingState) { PreviewOverlaySlotScopeImpl(isOverlappingState) } + val scope = remember(isOverlappingState, orientation, isCompact) { + PreviewOverlaySlotScopeImpl( + isOverViewfinderState = isOverlappingState, + orientation = orientation, + isCompact = isCompact + ) + } val style = backgroundStyleFor(isOverlappingState.value) Box( diff --git a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/TestTags.kt b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/TestTags.kt index 10a5fd9104..73fe60d5c5 100644 --- a/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/TestTags.kt +++ b/ui/components/capture/src/main/java/com/google/jetpackcamera/ui/components/capture/TestTags.kt @@ -97,6 +97,3 @@ const val CAMERA_ERROR_DIALOG_TAG = "dialog_camera_error" const val CAMERA_ERROR_DIALOG_TITLE_TAG = "text_camera_error_title" const val CAMERA_ERROR_DIALOG_BODY_TAG = "text_camera_error_body" const val CAMERA_ERROR_DIALOG_CONFIRM_BUTTON_TAG = "btn_camera_error_confirm" - -/** Test tag for the compact controls container on the capture screen. */ -const val COMPACT_CONTROLS_TAG = "container_capture_controls_compact" diff --git a/ui/components/capture/src/test/java/com/google/jetpackcamera/ui/components/capture/CaptureSlotsTest.kt b/ui/components/capture/src/test/java/com/google/jetpackcamera/ui/components/capture/CaptureSlotsTest.kt index 2ba4c2a4e8..0dce9b3461 100644 --- a/ui/components/capture/src/test/java/com/google/jetpackcamera/ui/components/capture/CaptureSlotsTest.kt +++ b/ui/components/capture/src/test/java/com/google/jetpackcamera/ui/components/capture/CaptureSlotsTest.kt @@ -78,11 +78,10 @@ class CaptureSlotsTest { isRecording = true, onDismissQuickSettings = { dismissedCount++ } ) - val offViewfinderScope = CaptureSlotScope( - orientation = Orientation.Horizontal, - isCompact = false, + val offViewfinderScope = PreviewOverlaySlotScope( isOverViewfinder = false, - isRecording = false + orientation = Orientation.Horizontal, + isCompact = false ) assertThat(overViewfinderScope.orientation).isEqualTo(Orientation.Vertical) @@ -99,17 +98,19 @@ class CaptureSlotsTest { assertThat(offViewfinderScope.orientation).isEqualTo(Orientation.Horizontal) assertThat(offViewfinderScope.isCompact).isFalse() assertThat(offViewfinderScope.isOverViewfinder).isFalse() - assertThat(offViewfinderScope.isRecording).isFalse() assertThat(offViewfinderScope.cameraControlContainerColor).isEqualTo( CameraControlBackgroundStyle.WHITE_20.containerColor ) } @Test - fun captureSlots_indicatorColumnDefaultsToTopBar_andPlaceholdersRecycleExistingTags() { + fun captureSlots_andPlaceholders_adaptAxisAndRecycleExistingTags() { val customSlots = CaptureSlots( topBar = { modifier -> Box(modifier.size(48.dp).testTag(VIDEO_QUALITY_TAG)) + }, + topStartContent = { modifier -> + Box(modifier.size(24.dp).testTag(FLIP_CAMERA_BUTTON)) } ) val defaultPlaceholders = PlaceholderCaptureSlots.default() @@ -123,7 +124,8 @@ class CaptureSlotsTest { Box(modifier = Modifier.size(400.dp)) { PlaceholderViewfinder() with(slotScope) { - customSlots.indicatorColumn(this, Modifier) + customSlots.topBar(this, Modifier) + customSlots.topStartContent(this, Modifier) defaultPlaceholders.zoomControls( this, Modifier.sizeIn(maxHeight = 40.dp) @@ -139,6 +141,7 @@ class CaptureSlotsTest { composeTestRule.onNodeWithTag(PREVIEW_DISPLAY).assertIsDisplayed() composeTestRule.onNodeWithTag(VIDEO_QUALITY_TAG).assertIsDisplayed() + composeTestRule.onNodeWithTag(FLIP_CAMERA_BUTTON).assertIsDisplayed() composeTestRule.onNodeWithTag(QUICK_SETTINGS_BOTTOM_SHEET).assertDoesNotExist() val clampedZoomBounds = composeTestRule.onNodeWithTag(ZOOM_BUTTON_ROW_TAG).getBoundsInRoot()