|
15 | 15 | */ |
16 | 16 | package com.android.developers.androidify.xr |
17 | 17 |
|
18 | | -import androidx.compose.runtime.Composable |
19 | | -import androidx.compose.runtime.CompositionLocalProvider |
20 | | -import androidx.compose.runtime.ProvidableCompositionLocal |
21 | | -import androidx.compose.runtime.compositionLocalWithComputedDefaultOf |
22 | 18 | import androidx.compose.ui.tooling.preview.Devices.PIXEL_7_PRO |
23 | 19 | import androidx.compose.ui.tooling.preview.Devices.PIXEL_TABLET |
24 | 20 | import androidx.compose.ui.tooling.preview.Preview |
25 | | -import androidx.xr.compose.platform.SpatialCapabilities |
26 | | -import androidx.xr.compose.platform.SpatialConfiguration |
27 | | -import androidx.xr.runtime.Session |
28 | | - |
29 | | -/** |
30 | | - * Preview for a layout that could go into Full Space Mode. |
31 | | - */ |
32 | | -@Composable |
33 | | -fun SupportsFullSpaceModeRequestProvider(contents: @Composable () -> Unit) { |
34 | | - CompositionLocalProvider(LocalSpatialConfiguration provides HasSpatialFeatureSpatialConfiguration) { |
35 | | - CompositionLocalProvider(LocalSpatialCapabilities provides SupportsFullSpaceModeRequestCapabilities) { |
36 | | - CompositionLocalProvider(LocalSession provides null) { |
37 | | - contents() |
38 | | - } |
39 | | - } |
40 | | - } |
41 | | -} |
42 | | - |
43 | | -private object HasSpatialFeatureSpatialConfiguration : SpatialConfiguration { |
44 | | - override val hasXrSpatialFeature: Boolean |
45 | | - get() = true |
46 | | -} |
47 | | - |
48 | | -private object SupportsFullSpaceModeRequestCapabilities : SpatialCapabilities { |
49 | | - override val isSpatialUiEnabled: Boolean |
50 | | - get() = false |
51 | | - override val isContent3dEnabled: Boolean |
52 | | - get() = true |
53 | | - override val isAppEnvironmentEnabled: Boolean |
54 | | - get() = true |
55 | | - override val isPassthroughControlEnabled: Boolean |
56 | | - get() = true |
57 | | - override val isSpatialAudioEnabled: Boolean |
58 | | - get() = true |
59 | | -} |
60 | | - |
61 | | -/** |
62 | | - * Workaround composition locals for b/441901724. |
63 | | - * Any composable referencing XR composition locals will fail to preview instead of gracefully |
64 | | - * degrading due to failing to resolve XR capabilities. |
65 | | - * |
66 | | - * This can be removed when the default for XR capabilities under the preview is no capabilities |
67 | | - * instead of throwing an exception. |
68 | | - * */ |
69 | | -val LocalSpatialCapabilities: ProvidableCompositionLocal<SpatialCapabilities> = |
70 | | - compositionLocalWithComputedDefaultOf { |
71 | | - runCatching { |
72 | | - androidx.xr.compose.platform.LocalSpatialCapabilities.currentValue |
73 | | - }.getOrDefault(NoSpatialCapabilities) |
74 | | - } |
75 | | - |
76 | | -/** |
77 | | - * Workaround composition locals for b/441901724. |
78 | | - * Any composable referencing XR composition locals will fail to preview instead of gracefully |
79 | | - * degrading due to failing to resolve XR capabilities. |
80 | | - * |
81 | | - * This can be removed when the default for XR capabilities under the preview is no capabilities |
82 | | - * instead of throwing an exception. |
83 | | - * */ |
84 | | -val LocalSpatialConfiguration: ProvidableCompositionLocal<SpatialConfiguration> = |
85 | | - compositionLocalWithComputedDefaultOf { |
86 | | - runCatching { |
87 | | - androidx.xr.compose.platform.LocalSpatialConfiguration.currentValue |
88 | | - }.getOrDefault(LacksSpatialFeatureSpatialConfiguration) |
89 | | - } |
90 | | - |
91 | | -/** |
92 | | - * Workaround composition locals for b/441901724. |
93 | | - * Any composable referencing XR composition locals will fail to preview instead of gracefully |
94 | | - * degrading due to failing to resolve XR capabilities. |
95 | | - * |
96 | | - * This can be removed when the default for XR capabilities under the preview is no capabilities |
97 | | - * instead of throwing an exception. |
98 | | - * */ |
99 | | -val LocalSession: ProvidableCompositionLocal<Session?> = |
100 | | - compositionLocalWithComputedDefaultOf { |
101 | | - runCatching { |
102 | | - androidx.xr.compose.platform.LocalSession.currentValue |
103 | | - }.getOrNull() |
104 | | - } |
105 | | - |
106 | | -private object NoSpatialCapabilities : SpatialCapabilities { |
107 | | - override val isSpatialUiEnabled: Boolean |
108 | | - get() = false |
109 | | - override val isContent3dEnabled: Boolean |
110 | | - get() = false |
111 | | - override val isAppEnvironmentEnabled: Boolean |
112 | | - get() = false |
113 | | - override val isPassthroughControlEnabled: Boolean |
114 | | - get() = false |
115 | | - override val isSpatialAudioEnabled: Boolean |
116 | | - get() = false |
117 | | -} |
118 | | - |
119 | | -private object LacksSpatialFeatureSpatialConfiguration : SpatialConfiguration { |
120 | | - override val hasXrSpatialFeature: Boolean |
121 | | - get() = false |
122 | | -} |
123 | 21 |
|
124 | 22 | @Preview(device = PIXEL_TABLET, name = "Android XR (Home Space Mode)") |
125 | 23 | annotation class XrHomeSpaceMediumPreview |
|
0 commit comments