Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import androidx.xr.compose.platform.LocalSession
import androidx.xr.compose.platform.LocalSpatialCapabilities
import androidx.xr.compose.platform.LocalSpatialConfiguration
import androidx.xr.scenecore.scene

/** Check if the device is XR-enabled, but is not yet rendering spatial UI. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,111 +15,9 @@
*/
package com.android.developers.androidify.xr

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.compositionLocalWithComputedDefaultOf
import androidx.compose.ui.tooling.preview.Devices.PIXEL_7_PRO
import androidx.compose.ui.tooling.preview.Devices.PIXEL_TABLET
import androidx.compose.ui.tooling.preview.Preview
import androidx.xr.compose.platform.SpatialCapabilities
import androidx.xr.compose.platform.SpatialConfiguration
import androidx.xr.runtime.Session

/**
* Preview for a layout that could go into Full Space Mode.
*/
@Composable
fun SupportsFullSpaceModeRequestProvider(contents: @Composable () -> Unit) {
CompositionLocalProvider(LocalSpatialConfiguration provides HasSpatialFeatureSpatialConfiguration) {
CompositionLocalProvider(LocalSpatialCapabilities provides SupportsFullSpaceModeRequestCapabilities) {
CompositionLocalProvider(LocalSession provides null) {
contents()
}
}
}
}

private object HasSpatialFeatureSpatialConfiguration : SpatialConfiguration {
override val hasXrSpatialFeature: Boolean
get() = true
}

private object SupportsFullSpaceModeRequestCapabilities : SpatialCapabilities {
override val isSpatialUiEnabled: Boolean
get() = false
override val isContent3dEnabled: Boolean
get() = true
override val isAppEnvironmentEnabled: Boolean
get() = true
override val isPassthroughControlEnabled: Boolean
get() = true
override val isSpatialAudioEnabled: Boolean
get() = true
}

/**
* Workaround composition locals for b/441901724.
* Any composable referencing XR composition locals will fail to preview instead of gracefully
* degrading due to failing to resolve XR capabilities.
*
* This can be removed when the default for XR capabilities under the preview is no capabilities
* instead of throwing an exception.
* */
val LocalSpatialCapabilities: ProvidableCompositionLocal<SpatialCapabilities> =
compositionLocalWithComputedDefaultOf {
runCatching {
androidx.xr.compose.platform.LocalSpatialCapabilities.currentValue
}.getOrDefault(NoSpatialCapabilities)
}

/**
* Workaround composition locals for b/441901724.
* Any composable referencing XR composition locals will fail to preview instead of gracefully
* degrading due to failing to resolve XR capabilities.
*
* This can be removed when the default for XR capabilities under the preview is no capabilities
* instead of throwing an exception.
* */
val LocalSpatialConfiguration: ProvidableCompositionLocal<SpatialConfiguration> =
compositionLocalWithComputedDefaultOf {
runCatching {
androidx.xr.compose.platform.LocalSpatialConfiguration.currentValue
}.getOrDefault(LacksSpatialFeatureSpatialConfiguration)
}

/**
* Workaround composition locals for b/441901724.
* Any composable referencing XR composition locals will fail to preview instead of gracefully
* degrading due to failing to resolve XR capabilities.
*
* This can be removed when the default for XR capabilities under the preview is no capabilities
* instead of throwing an exception.
* */
val LocalSession: ProvidableCompositionLocal<Session?> =
compositionLocalWithComputedDefaultOf {
runCatching {
androidx.xr.compose.platform.LocalSession.currentValue
}.getOrNull()
}

private object NoSpatialCapabilities : SpatialCapabilities {
override val isSpatialUiEnabled: Boolean
get() = false
override val isContent3dEnabled: Boolean
get() = false
override val isAppEnvironmentEnabled: Boolean
get() = false
override val isPassthroughControlEnabled: Boolean
get() = false
override val isSpatialAudioEnabled: Boolean
get() = false
}

private object LacksSpatialFeatureSpatialConfiguration : SpatialConfiguration {
override val hasXrSpatialFeature: Boolean
get() = false
}

@Preview(device = PIXEL_TABLET, name = "Android XR (Home Space Mode)")
annotation class XrHomeSpaceMediumPreview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LifecycleStartEffect
import androidx.xr.compose.platform.LocalSpatialCapabilities
import com.android.developers.androidify.camera.xr.CameraLayoutSpatial
import com.android.developers.androidify.theme.AndroidifyTheme
import com.android.developers.androidify.theme.TertiaryContainer
Expand All @@ -59,7 +60,6 @@ import com.android.developers.androidify.util.allowsFullContent
import com.android.developers.androidify.util.isWidthAtLeastMedium
import com.android.developers.androidify.util.shouldShowTabletopLayout
import com.android.developers.androidify.util.supportsTabletop
import com.android.developers.androidify.xr.LocalSpatialCapabilities

@Composable
internal fun CameraLayout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package com.android.developers.androidify.creation

import androidx.compose.runtime.Composable
import androidx.xr.compose.platform.LocalSpatialCapabilities
import com.android.developers.androidify.util.areBothWindowDimensionsAtLeastMedium
import com.android.developers.androidify.xr.LocalSpatialCapabilities

enum class EditScreenLayoutType {
Compact,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.android.developers.androidify.creation.EditScreen
import com.android.developers.androidify.creation.EditScreenLayoutType
import com.android.developers.androidify.creation.fakeDropBehaviourFactory
import com.android.developers.androidify.theme.SharedElementContextPreview
import com.android.developers.androidify.xr.SupportsFullSpaceModeRequestProvider
import com.android.developers.androidify.xr.XrHomeSpaceCompactPreview
import com.android.developers.androidify.xr.XrHomeSpaceMediumPreview

Expand All @@ -32,24 +31,22 @@ import com.android.developers.androidify.xr.XrHomeSpaceMediumPreview
@Composable
private fun EditScreenMediumXrHomeSpaceModePreview() {
SharedElementContextPreview {
SupportsFullSpaceModeRequestProvider {
EditScreen(
snackbarHostState = SnackbarHostState(),
dropBehaviourFactory = fakeDropBehaviourFactory,
onCameraPressed = { },
uiState = CreationState(),
onChooseImageClicked = {},
onPromptOptionSelected = {},
onUndoPressed = {},
onPromptGenerationPressed = {},
onBotColorSelected = {},
onStartClicked = {},
onDropCallback = {},
onBackPressed = {},
onAboutPressed = {},
layoutType = EditScreenLayoutType.Medium,
)
}
EditScreen(
snackbarHostState = SnackbarHostState(),
dropBehaviourFactory = fakeDropBehaviourFactory,
onCameraPressed = { },
uiState = CreationState(),
onChooseImageClicked = {},
onPromptOptionSelected = {},
onUndoPressed = {},
onPromptGenerationPressed = {},
onBotColorSelected = {},
onStartClicked = {},
onDropCallback = {},
onBackPressed = {},
onAboutPressed = {},
layoutType = EditScreenLayoutType.Medium,
)
}
}

Expand All @@ -58,23 +55,21 @@ private fun EditScreenMediumXrHomeSpaceModePreview() {
@Composable
private fun EditScreenCompactXrHomeSpaceModePreview() {
SharedElementContextPreview {
SupportsFullSpaceModeRequestProvider {
EditScreen(
snackbarHostState = SnackbarHostState(),
dropBehaviourFactory = fakeDropBehaviourFactory,
onCameraPressed = { },
uiState = CreationState(),
onChooseImageClicked = {},
onPromptOptionSelected = {},
onUndoPressed = {},
onPromptGenerationPressed = {},
onBotColorSelected = {},
onStartClicked = {},
onDropCallback = {},
onBackPressed = {},
onAboutPressed = {},
layoutType = EditScreenLayoutType.Compact,
)
}
EditScreen(
snackbarHostState = SnackbarHostState(),
dropBehaviourFactory = fakeDropBehaviourFactory,
onCameraPressed = { },
uiState = CreationState(),
onChooseImageClicked = {},
onPromptOptionSelected = {},
onUndoPressed = {},
onPromptGenerationPressed = {},
onBotColorSelected = {},
onStartClicked = {},
onDropCallback = {},
onBackPressed = {},
onAboutPressed = {},
layoutType = EditScreenLayoutType.Compact,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.android.developers.androidify.theme.components.AboutButton
import com.android.developers.androidify.theme.components.AndroidifyTopAppBar
import com.android.developers.androidify.util.LargeScreensPreview
import com.android.developers.androidify.xr.RequestFullSpaceIconButton
import com.android.developers.androidify.xr.SupportsFullSpaceModeRequestProvider
import com.android.developers.androidify.xr.XrHomeSpaceMediumPreview
import com.android.developers.androidify.xr.couldRequestFullSpace

Expand Down Expand Up @@ -120,15 +119,13 @@ private fun HomeScreenLargeScreensPreview() {
@XrHomeSpaceMediumPreview
@Composable
private fun HomeScreenLargeScreensHomeSpaceModePreview() {
SupportsFullSpaceModeRequestProvider {
SharedElementContextPreview {
HomeScreenContents(
layoutType = HomeScreenLayoutType.Medium,
onClickLetsGo = { },
videoLink = "",
dancingBotLink = "https://services.google.com/fh/files/misc/android_dancing.gif",
onAboutClicked = {},
)
}
SharedElementContextPreview {
HomeScreenContents(
layoutType = HomeScreenLayoutType.Medium,
onClickLetsGo = { },
videoLink = "",
dancingBotLink = "https://services.google.com/fh/files/misc/android_dancing.gif",
onAboutClicked = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.compose.runtime.Composable
import com.android.developers.androidify.home.HomeScreenContents
import com.android.developers.androidify.home.HomeScreenLayoutType
import com.android.developers.androidify.theme.SharedElementContextPreview
import com.android.developers.androidify.xr.SupportsFullSpaceModeRequestProvider
import com.android.developers.androidify.xr.XrHomeSpaceCompactPreview
import com.android.developers.androidify.xr.XrHomeSpaceMediumPreview

Expand All @@ -29,31 +28,27 @@ import com.android.developers.androidify.xr.XrHomeSpaceMediumPreview
@Composable
private fun HomeScreenMediumXrHomeSpaceModePreview() {
SharedElementContextPreview {
SupportsFullSpaceModeRequestProvider {
HomeScreenContents(
layoutType = HomeScreenLayoutType.Medium,
onClickLetsGo = { },
videoLink = "",
dancingBotLink = "https://services.google.com/fh/files/misc/android_dancing.gif",
onAboutClicked = {},
)
}
HomeScreenContents(
layoutType = HomeScreenLayoutType.Medium,
onClickLetsGo = { },
videoLink = "",
dancingBotLink = "https://services.google.com/fh/files/misc/android_dancing.gif",
onAboutClicked = {},
)
}
}

@ExperimentalMaterial3ExpressiveApi
@XrHomeSpaceCompactPreview
@Composable
private fun HomeScreenCompactXrHomeSpaceModePreview() {
SupportsFullSpaceModeRequestProvider {
SharedElementContextPreview {
HomeScreenContents(
layoutType = HomeScreenLayoutType.Compact,
onClickLetsGo = {},
videoLink = "",
dancingBotLink = "https://services.google.com/fh/files/misc/android_dancing.gif",
onAboutClicked = {},
)
}
SharedElementContextPreview {
HomeScreenContents(
layoutType = HomeScreenLayoutType.Compact,
onClickLetsGo = {},
videoLink = "",
dancingBotLink = "https://services.google.com/fh/files/misc/android_dancing.gif",
onAboutClicked = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package com.android.developers.androidify.results

import androidx.compose.runtime.Composable
import androidx.xr.compose.platform.LocalSpatialCapabilities
import com.android.developers.androidify.util.allowsFullContent
import com.android.developers.androidify.xr.LocalSpatialCapabilities

enum class ResultsLayoutType {
Verbose,
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mlkitSegmentation = "16.0.0-beta1"
playServicesBase = "18.9.0"
timber = "5.0.1"
workRuntimeKtx = "2.10.5"
xr-compose = "1.0.0-alpha07"
xr-compose = "1.0.0-alpha11"

[libraries]
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" }
Expand Down
Loading