Skip to content

Commit 1d1977c

Browse files
authored
Merge pull request #151 from android/feature/xr/wrap-up
Miscellaneous XR fixups
2 parents 70e3cd7 + d7de2a6 commit 1d1977c

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
android:name="android.hardware.camera"
2424
android:required="true" />
2525

26+
<!-- Androidify can use XR features if they're available; they're not required. -->
27+
<uses-feature android:name="android.software.xr.api.spatial" android:required="false" />
28+
2629
<uses-permission android:name="android.permission.CAMERA" />
2730
<uses-sdk tools:overrideLibrary="com.google.ai.edge.aicore" />
2831

core/xr/src/main/java/com/android/developers/androidify/xr/MainPanelWorkaround.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,24 @@
1616
package com.android.developers.androidify.xr
1717

1818
import androidx.compose.runtime.Composable
19-
import androidx.compose.runtime.LaunchedEffect
19+
import androidx.compose.runtime.DisposableEffect
2020
import androidx.xr.compose.platform.LocalSession
2121
import androidx.xr.scenecore.scene
22-
import kotlinx.coroutines.delay
2322

2423
/*
25-
* A composable that attempts to continually hide the mainPanel.
24+
* A composable that hides the mainPanel when it is disposed. When placed outside of an (Application)Subspace,
25+
* this composable will be disposed after the Subspace, hiding the mainPanelEntity again.
2626
*
27-
* This is a temporary workaround for b/440325404, that causes the mainPanelEntity when an
27+
* This is a temporary workaround for b/440325404, that causes the mainPanelEntity to appear when an
2828
* ApplicationSubspace transitions out of the composition due to a race condition when transitioning
2929
* the two hierarchies.
3030
*/
3131
@Composable
3232
fun MainPanelWorkaround() {
33-
val session = LocalSession.current
34-
LaunchedEffect(null) {
35-
while (true) {
36-
delay(100L)
37-
session?.scene?.mainPanelEntity?.setEnabled(false)
33+
val session = LocalSession.current ?: return
34+
DisposableEffect(session) {
35+
onDispose {
36+
session.scene.mainPanelEntity.setEnabled(false)
3837
}
3938
}
4039
}

feature/creation/src/main/java/com/android/developers/androidify/creation/xr/EditScreenSpatial.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ fun EditScreenSpatial(
7575
onDropCallback: (Uri) -> Unit = {},
7676
) {
7777
DisableSharedTransition {
78+
MainPanelWorkaround()
7879
SquiggleBackgroundSubspace(minimumHeight = 600.dp) {
79-
MainPanelWorkaround()
8080
SpatialColumn(SubspaceModifier.fillMaxWidth()) {
8181
SpatialPanel(
8282
SubspaceModifier.offset(z = 10.dp)

feature/creation/src/main/java/com/android/developers/androidify/creation/xr/LoadingScreenSpatial.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ private const val squiggleSafeContentHeight = 0.6f
5252
fun LoadingScreenSpatial(
5353
onCancelPress: () -> Unit,
5454
) {
55+
MainPanelWorkaround()
5556
BackgroundSubspace(
5657
aspectRatio = 1.4f,
5758
minimumHeight = 500.dp,
5859
drawable = CreationR.drawable.squiggle_light,
5960
) {
60-
MainPanelWorkaround()
6161
Orbiter(
6262
position = ContentEdge.Top,
6363
offsetType = OrbiterOffsetType.OuterEdge,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import com.android.developers.androidify.xr.SquiggleBackgroundSubspace
3333

3434
@Composable
3535
fun AboutScreenSpatial(onBackPressed: () -> Unit, bottomButtons: @Composable () -> Unit) {
36+
MainPanelWorkaround()
3637
SquiggleBackgroundSubspace(500.dp) {
37-
MainPanelWorkaround()
3838
SpatialPanel {
3939
Orbiter(
4040
ContentEdge.Top,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ fun HomeScreenContentsSpatial(
6969
onAboutClicked: () -> Unit,
7070
) {
7171
DisableSharedTransition {
72+
MainPanelWorkaround()
7273
SquiggleBackgroundSubspace(minimumHeight = 600.dp) {
73-
MainPanelWorkaround()
7474
Orbiter(
7575
position = ContentEdge.Top,
7676
offsetType = OrbiterOffsetType.OuterEdge,

feature/results/src/main/java/com/android/developers/androidify/results/xr/ResultsScreenSpatial.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ fun ResultsScreenSpatial(
5959
) {
6060
var offsetPose by remember { mutableStateOf(Pose()) }
6161
DisableSharedTransition {
62+
MainPanelWorkaround()
6263
Subspace {
63-
MainPanelWorkaround()
64-
6564
SpatialPanel(
6665
SubspaceModifier
6766
.offset(z = 5.dp)

0 commit comments

Comments
 (0)