contacts: fix edit contact page layout spacing
- Commit
e48721bca6e161dd1dc66ae6a3b448e8f45a06d0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 02:44 UTC (4 days ago)
- Parents
4675633
The add-phone button nearly overlaid the email field, and similar spacing drift existed elsewhere on the edit-contact page. Root causes: EditContactDetailGroups stacked the phone, email and address FormDetailGroups with no gap between them, so each group's full-width add button sat flush on the next group's outlined field and its floating label. FormDetailGroup added a Spacer child on top of its Column spacedBy, collecting the arrangement gap on both sides and inflating in-group gaps to about 20dp while inter-group gaps were 0dp. EditContactBirthday emitted a hidden trailing 8dp spacer and EditContactPage emitted a second section gap before it, doubling that gap; date rows used 8dp and custom-label rows 4dp against the form's 12dp field rhythm, and the page ended with two stacked section gaps. Fix with proper Compose layout only, no absolute offsets and no functionality change: FormDetailGroup now relies solely on Arrangement.spacedBy(Spacing.md) for rows, custom-label fields and its add button; the three detail groups are wrapped in a Column with Arrangement.spacedBy(12.dp), as are the SIM phone/email fields; birthday no longer emits a trailing spacer and the page supplies a single 12dp gap to the date rows; date rows use 12dp (8dp for their tightly related custom-label sub-field); the preferred-method clear row goes 4dp to 8dp; duplicate section and bottom gaps in EditContactPage are removed. No screenshot preview exists for EditContact (declared exception in MetadataPreviews), so no captures were regenerated. AGENTS.md needed no change: no documented file, feature or verification command changed. Verified: :contacts:lint, :contacts:lintVitalRelease and :library:ui:lint pass. :contacts:testDevUnitTest runs 596 tests with the 2 pre-existing InsertOrEdit number failures that also fail on unmodified HEAD; the new EditLayoutSpacingTest bounds tests (add-phone clears email, add-email clears addresses, add buttons do not overlap) pass. :library:ui:testDebugUnitTest was run in the same combined invocation before the contacts test failure stopped the build.
Diff
contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactBirthday.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactBirthday.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactBirthday.ktindex dbbd7715e4..43a7b4ed1f 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactBirthday.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactBirthday.kt@@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.width import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier@@ -68,6 +67,7 @@ fun EditContactBirthday( if (birthday != null) Spacer(Modifier.width(RemoveButtonWidth)) } }-- Spacer(Modifier.height(8.dp))+ // No trailing Spacer here: gap to the next field is the caller's, in the+ // page's single rhythm. Emitting one made birthday-to-dates 8dp while+ // every other field gap on the page was 12-16dp. }
contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactCommPrefSection.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactCommPrefSection.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactCommPrefSection.ktindex e270e9c583..a98dd18527 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactCommPrefSection.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactCommPrefSection.kt@@ -67,7 +67,7 @@ fun EditContactCommPrefSection( onUpdate(draft.copy(commPref = CommPref(0, number, platform))) } if (current != null) {- Spacer(Modifier.height(4.dp))+ Spacer(Modifier.height(8.dp)) Row { Spacer(Modifier.weight(1f)) IconButton(onClick = { onUpdate(draft.copy(commPref = null)) }) {
contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDateDetails.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDateDetails.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDateDetails.ktindex 738d565343..b344e323ab 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDateDetails.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDateDetails.kt@@ -110,7 +110,8 @@ fun ColumnScope.EditContactDateDetails( } } if (isCustom) {- Spacer(Modifier.height(4.dp))+ // Tightly related sub-field: 8dp, vs 12dp between separate dates.+ Spacer(Modifier.height(8.dp)) OutlinedTextField( value = detail.label, onValueChange = { newLabel ->@@ -122,7 +123,8 @@ fun ColumnScope.EditContactDateDetails( modifier = Modifier.fillMaxWidth() ) }- Spacer(Modifier.height(8.dp))+ // Also the gap above the add button when this is the last date.+ Spacer(Modifier.height(12.dp)) } FilledTonalButton( onClick = { onDetailsChange(details + ContactDetail.default<Event>()) },
contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDetailGroups.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDetailGroups.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDetailGroups.ktindex f5428429eb..cd89e9fa5b 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDetailGroups.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactDetailGroups.kt@@ -1,9 +1,8 @@ package com.vayunmathur.contacts.ui +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.height import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect@@ -74,6 +73,14 @@ fun EditContactDetailGroups( SimContactFields(draft, onUpdate) return }+ // The three groups are one stack: without a gap between them each group's+ // full-width add button sat flush on the next group's outlined field, its+ // bottom edge touching the field's floating label (add-phone over email).+ // 12.dp matches the gap between fields inside each group.+ Column(+ modifier = Modifier.fillMaxWidth(),+ verticalArrangement = Arrangement.spacedBy(12.dp),+ ) { val phoneCtx = LocalContext.current FormDetailGroup( items = draft.phoneNumbers,@@ -160,6 +167,7 @@ fun EditContactDetailGroups( addIcon = { IconLocationOn() }, expandOnEnter = true, )+ } } /**@@ -173,7 +181,7 @@ internal fun SimContactFields( ) { val phone = draft.phoneNumbers.take(SIM_MAX_PHONE_NUMBERS).firstOrNull() val email = draft.emails.take(SIM_MAX_EMAILS).firstOrNull()- Column(Modifier.fillMaxWidth()) {+ Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(12.dp)) { OutlinedTextField( value = phone?.value.orEmpty(), onValueChange = { v ->@@ -189,7 +197,6 @@ internal fun SimContactFields( keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Phone), modifier = Modifier.fillMaxWidth(), )- Spacer(Modifier.height(16.dp)) OutlinedTextField( value = email?.value.orEmpty(), onValueChange = { v ->
contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.ktindex cd99ba75e7..e064e1fdfc 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.kt@@ -225,7 +225,7 @@ fun EditContactPage(backStack: NavBackStack<Route>, viewModel: ContactViewModel, onUpdate = { viewModel.updateEditDraft { _ -> it } }, isSimAccount = isSimAccount, )- Spacer(Modifier.height(smallGap))+ Spacer(Modifier.height(gap)) // Preferred call/message method: SIM ADN rows have no Data rows to keep it. if (!isSimAccount) {@@ -238,10 +238,12 @@ fun EditContactPage(backStack: NavBackStack<Route>, viewModel: ContactViewModel, } if (!isSimAccount) {- Spacer(Modifier.height(gap))+ // Single section gap (the CommPref block above already emitted+ // one); a second here doubled birthday's top gap to 2x gap. EditContactBirthday(backStack, currentDraft.birthday) { v -> viewModel.updateEditDraft { it.copy(birthday = v) } }+ Spacer(Modifier.height(12.dp)) EditContactDateDetails( backStack = backStack, details = currentDraft.dates,@@ -282,9 +284,9 @@ fun EditContactPage(backStack: NavBackStack<Route>, viewModel: ContactViewModel, contactId = editRoute.contactId, onUpdate = { viewModel.updateEditDraft { _ -> it } }, )- Spacer(Modifier.height(gap)) } + // Bottom padding only - one gap, not this plus another above it. Spacer(Modifier.height(gap)) } }
contacts/src/test/java/com/vayunmathur/contacts/ui/EditLayoutSpacingTest.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/ui/EditLayoutSpacingTest.kt b/contacts/src/test/java/com/vayunmathur/contacts/ui/EditLayoutSpacingTest.ktnew file mode 100644index 0000000000..4390f8a974--- /dev/null+++ b/contacts/src/test/java/com/vayunmathur/contacts/ui/EditLayoutSpacingTest.kt@@ -0,0 +1,100 @@+package com.vayunmathur.contacts.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.hasClickAction+import androidx.compose.ui.test.hasText+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onAllNodesWithText+import com.vayunmathur.contacts.data.Address+import com.vayunmathur.contacts.data.CDKEmail+import com.vayunmathur.contacts.data.CDKPhone+import com.vayunmathur.contacts.data.CDKStructuredPostal+import com.vayunmathur.contacts.data.Email+import com.vayunmathur.contacts.data.PhoneNumber+import com.vayunmathur.contacts.platform.ContactViewModel+import com.vayunmathur.library.ui.DynamicTheme+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertTrue++/**+ * Layout regression for the edit form: each detail group's add button must+ * clear the next group's field (add-phone over email), and rows inside a+ * group must keep a real gap above their add button. Bounds are semantics+ * layout bounds, so this fails if the groups are stacked flush again.+ */+@RunWith(RobolectricTestRunner::class)+class EditLayoutSpacingTest {+ @get:Rule val rule = createComposeRule()++ private var current by mutableStateOf(+ ContactViewModel.ContactDraft(+ firstName = "Aisha",+ lastName = "Rahman",+ phoneNumbers = listOf(PhoneNumber(1, "+14155550102", CDKPhone.TYPE_MOBILE)),+ emails = listOf(Email(3, "[email protected]", CDKEmail.TYPE_HOME)),+ addresses = listOf(Address(5, "1200 Market St", CDKStructuredPostal.TYPE_HOME)),+ ),+ )++ private fun render() {+ rule.setContent {+ DynamicTheme {+ Column {+ EditContactDetailGroups(+ current,+ mobileIndex = 0,+ homeEmailIndex = 0,+ onUpdate = { current = it },+ )+ }+ }+ }+ rule.waitForIdle()+ }++ private fun buttonBounds(text: String) =+ rule+ .onAllNodes(hasClickAction() and hasText(text, substring = true))+ .fetchSemanticsNodes()+ .first()+ .boundsInRoot++ private fun labelTop(text: String) =+ rule+ .onAllNodesWithText(text, substring = false)+ .fetchSemanticsNodes()+ .first()+ .boundsInRoot.top++ @Test+ fun addPhoneButtonClearsEmailField() {+ render()+ val addPhone = buttonBounds("Add phone")+ val gap = labelTop("Email") - addPhone.bottom+ assertTrue(gap >= 4f, "Add phone bottom=${addPhone.bottom} must clear Email label, gap=$gap")+ }++ @Test+ fun addEmailButtonClearsAddressField() {+ render()+ val addEmail = buttonBounds("Add email")+ val gap = labelTop("Addresses") - addEmail.bottom+ assertTrue(gap >= 4f, "Add email bottom=${addEmail.bottom} must clear Addresses label, gap=$gap")+ }++ @Test+ fun addButtonsAreBelowTheirRowsInOrder() {+ render()+ val phone = buttonBounds("Add phone")+ val email = buttonBounds("Add email")+ val address = buttonBounds("Add address")+ assertTrue(phone.bottom <= email.top, "phone/email add buttons overlap: $phone vs $email")+ assertTrue(email.bottom <= address.top, "email/address add buttons overlap: $email vs $address")+ }+}
library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.ktindex f9aa3fbae4..a8e1d86bfa 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt@@ -12,7 +12,6 @@ import com.vayunmathur.library.util.expandFromLine import com.vayunmathur.library.util.sharedContainer import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.text.KeyboardActions@@ -261,7 +260,11 @@ fun <T> FormDetailGroup( */ expandOnEnter: Boolean = false, ) {- Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(Spacing.sm)) {+ // One gap for every child: rows, their custom-label fields and the add+ // button all sit Spacing.md apart. Do not add Spacer children on top of+ // spacedBy - each one also collects the arrangement gap on both sides,+ // which inflated row gaps while leaving gaps between groups at zero.+ Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(Spacing.md)) { // Hoisted out of the row loop so the add button below can unfurl the same way the rows do. val enterModifier = if (expandOnEnter) Modifier.expandFromLine() else Modifier items.forEachIndexed { index, item ->@@ -338,7 +341,6 @@ fun <T> FormDetailGroup( ) } if (isCustom(item) && onLabelChange != null) {- Spacer(Modifier.height(Spacing.xs)) OutlinedTextField( value = customLabel(item), onValueChange = { v -> onLabelChange(index, v) },@@ -348,7 +350,6 @@ fun <T> FormDetailGroup( modifier = Modifier.fillMaxWidth(), ) }- Spacer(Modifier.height(Spacing.xs)) } FilledTonalButton( onClick = onAdd,