Skip to content

Commit bef67d0

Browse files
committed
Pull out the squiggle used in Home so it can be used in Create too
1 parent 13472ba commit bef67d0

File tree

2 files changed

+84
-32
lines changed

2 files changed

+84
-32
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.android.developers.androidify.xr
17+
18+
import androidx.compose.runtime.Composable
19+
import androidx.compose.ui.unit.dp
20+
import androidx.xr.compose.spatial.Subspace
21+
import androidx.xr.compose.subspace.SpatialBox
22+
import androidx.xr.compose.subspace.SpatialBoxScope
23+
import androidx.xr.compose.subspace.SpatialPanel
24+
import androidx.xr.compose.subspace.SubspaceComposable
25+
import androidx.xr.compose.subspace.layout.SubspaceModifier
26+
import androidx.xr.compose.subspace.layout.aspectRatio
27+
import androidx.xr.compose.subspace.layout.fillMaxWidth
28+
import androidx.xr.compose.subspace.layout.movable
29+
import androidx.xr.compose.subspace.layout.offset
30+
import androidx.xr.compose.subspace.layout.resizable
31+
import com.android.developers.androidify.theme.components.SquiggleBackgroundFull
32+
33+
/**
34+
* A composable for a Subspace with a Squiggle background.
35+
* This Subspace is generally the top-level Subspace. It contains a full-sized squiggle background
36+
* that is grabbable and movable, allowing all child components to move with the background.
37+
*/
38+
@Composable
39+
fun SquiggleBackgroundSubspace(
40+
content:
41+
@SubspaceComposable @Composable
42+
SpatialBoxScope.() -> Unit,
43+
) {
44+
Subspace {
45+
SpatialPanel(
46+
SubspaceModifier
47+
.movable()
48+
.resizable()
49+
.fillMaxWidth(1f)
50+
.aspectRatio(1.7f),
51+
) {
52+
SquiggleBackgroundFull()
53+
Subspace {
54+
SpatialBox(SubspaceModifier.offset(z = 10.dp), content = content)
55+
}
56+
}
57+
}
58+
}

feature/home/src/main/java/com/android/developers/androidify/home/xr/HomeScreenSpatial.kt

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import androidx.xr.compose.subspace.layout.SpatialAlignment
4242
import androidx.xr.compose.subspace.layout.SubspaceModifier
4343
import androidx.xr.compose.subspace.layout.aspectRatio
4444
import androidx.xr.compose.subspace.layout.fillMaxHeight
45+
import androidx.xr.compose.subspace.layout.fillMaxSize
4546
import androidx.xr.compose.subspace.layout.fillMaxWidth
4647
import androidx.xr.compose.subspace.layout.movable
4748
import androidx.xr.compose.subspace.layout.offset
@@ -58,6 +59,7 @@ import com.android.developers.androidify.util.TabletPreview
5859
import com.android.developers.androidify.xr.DisableSharedTransition
5960
import com.android.developers.androidify.xr.MainPanelWorkaround
6061
import com.android.developers.androidify.xr.RequestHomeSpaceIconButton
62+
import com.android.developers.androidify.xr.SquiggleBackgroundSubspace
6163

6264
@Composable
6365
fun HomeScreenContentsSpatial(
@@ -67,43 +69,35 @@ fun HomeScreenContentsSpatial(
6769
onAboutClicked: () -> Unit,
6870
) {
6971
DisableSharedTransition {
70-
Subspace {
72+
SquiggleBackgroundSubspace {
7173
MainPanelWorkaround()
74+
Orbiter(
75+
position = ContentEdge.Top,
76+
offsetType = OrbiterOffsetType.OuterEdge,
77+
offset = 32.dp,
78+
alignment = Alignment.End,
79+
) {
80+
RequestHomeSpaceIconButton(
81+
modifier = Modifier
82+
.size(64.dp, 64.dp)
83+
.padding(8.dp),
84+
)
85+
}
86+
SpatialPanel(SubspaceModifier.fillMaxSize()) {
87+
HomeScreenSpatialMainContent(dancingBotLink, onClickLetsGo, onAboutClicked)
88+
}
7289
SpatialPanel(
7390
SubspaceModifier
91+
.fillMaxWidth(0.2f)
92+
.fillMaxHeight(0.8f)
93+
.aspectRatio(0.77f)
94+
.resizable(maintainAspectRatio = true)
7495
.movable()
75-
.resizable()
76-
.fillMaxWidth(1f)
77-
.aspectRatio(1.7f),
96+
.align(SpatialAlignment.CenterRight)
97+
.offset(z = 10.dp)
98+
.rotate(0f, 0f, 5f),
7899
) {
79-
Orbiter(
80-
position = ContentEdge.Top,
81-
offsetType = OrbiterOffsetType.OuterEdge,
82-
offset = 32.dp,
83-
alignment = Alignment.End,
84-
) {
85-
RequestHomeSpaceIconButton(
86-
modifier = Modifier
87-
.size(64.dp, 64.dp)
88-
.padding(8.dp),
89-
)
90-
}
91-
HomeScreenSpatialMainContent(dancingBotLink, onClickLetsGo, onAboutClicked)
92-
Subspace {
93-
SpatialPanel(
94-
SubspaceModifier
95-
.fillMaxWidth(0.2f)
96-
.fillMaxHeight(0.8f)
97-
.aspectRatio(0.77f)
98-
.resizable(maintainAspectRatio = true)
99-
.movable()
100-
.align(SpatialAlignment.CenterRight)
101-
.offset(z = 10.dp)
102-
.rotate(0f, 0f, 5f),
103-
) {
104-
VideoPlayer(videoLink)
105-
}
106-
}
100+
VideoPlayer(videoLink)
107101
}
108102
}
109103
}

0 commit comments

Comments
 (0)