diff --git a/app/src/main/java/com/anindra/messages/MainActivity.kt b/app/src/main/java/com/anindra/messages/MainActivity.kt index b491d4b7..c459fc46 100644 --- a/app/src/main/java/com/anindra/messages/MainActivity.kt +++ b/app/src/main/java/com/anindra/messages/MainActivity.kt @@ -2093,14 +2093,17 @@ open class MainActivity : FragmentActivity() { label = stringResource(R.string.access_nav) ) { target -> if (target == "list") { - // In a two-pane window the list is its own column, - // so this pane is empty until a chat is opened — and - // says so, rather than showing a blank half screen. - androidx.compose.foundation.layout.Box( - Modifier.fillMaxSize().background(MaterialTheme.colorScheme.surface), - contentAlignment = Alignment.Center - ) { - if (twoPaneLayout) { + // A phone draws the list underneath this stack, so + // this pane must stay transparent there: an opaque + // surface here covered the whole inbox and left the + // screen black while the list was still composed + // underneath it. Only a split window owns this pane, + // and only it gets the empty-state card. + if (twoPaneLayout) { + androidx.compose.foundation.layout.Box( + Modifier.fillMaxSize().background(MaterialTheme.colorScheme.surface), + contentAlignment = Alignment.Center + ) { androidx.compose.material3.Text( text = stringResource(R.string.two_pane_empty), style = MaterialTheme.typography.bodyLarge, @@ -2108,6 +2111,8 @@ open class MainActivity : FragmentActivity() { modifier = Modifier.padding(horizontal = 24.dp) ) } + } else { + androidx.compose.foundation.layout.Box(Modifier.fillMaxSize()) } } else { androidx.compose.foundation.layout.Box(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.surface)) { diff --git a/app/src/test/java/com/anindra/messages/ui/ListPaneTransparencyTest.kt b/app/src/test/java/com/anindra/messages/ui/ListPaneTransparencyTest.kt new file mode 100644 index 00000000..aa4191ca --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/ListPaneTransparencyTest.kt @@ -0,0 +1,40 @@ +package com.anindra.messages.ui + +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.File + +/** + * On a phone the conversation list is drawn underneath the route stack, so the + * stack's "list" pane must stay transparent. It once painted an opaque surface + * there and covered the whole inbox: the list was still composed and clickable, + * but the screen was black. + */ +class ListPaneTransparencyTest { + + private val activity: String by lazy { + val main = generateSequence(File("").absoluteFile) { it.parentFile } + .map { File(it, "app/src/main") } + .firstOrNull { File(it, "java").isDirectory } + ?: error("app/src/main not found") + File(main, "java/com/anindra/messages/MainActivity.kt").readText() + } + + @Test + fun theListPaneIsOnlyOpaqueInASplitWindow() { + val branch = activity.substringAfter("""if (target == "list") {""") + val splitPart = branch.substringBefore("} else {") + val phonePart = branch.substringAfter("} else {").substringBefore("} else {") + assertTrue( + "the opaque pane and its empty-state card belong to the split window", + splitPart.contains("if (twoPaneLayout)") && + splitPart.contains("background(MaterialTheme.colorScheme.surface)") && + splitPart.contains("R.string.two_pane_empty") + ) + assertTrue( + "a phone gets a transparent pane, or the list underneath is hidden", + phonePart.contains("Box(Modifier.fillMaxSize())") && + !phonePart.contains("colorScheme.surface") + ) + } +} diff --git a/app/src/test/java/com/anindra/messages/ui/TwoPaneLayoutTest.kt b/app/src/test/java/com/anindra/messages/ui/TwoPaneLayoutTest.kt index 7d452315..cfcbd37c 100644 --- a/app/src/test/java/com/anindra/messages/ui/TwoPaneLayoutTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/TwoPaneLayoutTest.kt @@ -68,8 +68,8 @@ class TwoPaneLayoutTest { @Test fun anEmptyRightPaneSaysWhatToDo() { assertTrue( - "with no chat open the right pane is not a blank half screen", - Regex("""if \(twoPaneLayout\) \{[\s\S]{0,400}?R\.string\.two_pane_empty""") + "with no chat open the split window is not a blank half screen", + Regex("""if \(twoPaneLayout\) \{[\s\S]{0,500}?R\.string\.two_pane_empty""") .containsMatchIn(activity) ) }