Skip to content

Commit 32dcfe8

Browse files
committed
fix(ui): scale pinned notes grid to match column settings
PinnedNotesGrid hardcoded a two-column Row/Column layout, making pinned notes unresponsive to adaptiveScaling and manualColumns. Replace with BoxWithConstraints that derives columnCount using the same logic as the outer LazyVerticalStaggeredGrid (Adaptive 150dp or Fixed manualColumns), then distributes notes across N columns via a single remember(notes, columnCount) derivation. The FullLine/non-lazy structure from 1e02895 is preserved, so the pop-in fix remains intact.
1 parent b171807 commit 32dcfe8

1 file changed

Lines changed: 28 additions & 29 deletions

File tree

android/app/src/main/java/dev/dettmer/simplenotes/ui/main/components/NotesStaggeredGrid.kt

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.dettmer.simplenotes.ui.main.components
22

33
import androidx.compose.foundation.layout.Arrangement
4+
import androidx.compose.foundation.layout.BoxWithConstraints
45
import androidx.compose.foundation.layout.Column
56
import androidx.compose.foundation.layout.PaddingValues
67
import androidx.compose.foundation.layout.Row
@@ -13,6 +14,7 @@ import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan
1314
import androidx.compose.foundation.lazy.staggeredgrid.items
1415
import androidx.compose.runtime.Composable
1516
import androidx.compose.runtime.remember
17+
import kotlin.math.max
1618
import androidx.compose.ui.Modifier
1719
import androidx.compose.ui.res.stringResource
1820
import androidx.compose.ui.unit.dp
@@ -80,6 +82,8 @@ fun NotesStaggeredGrid(
8082
item(key = "pinned_notes_body", contentType = "PinnedSection", span = StaggeredGridItemSpan.FullLine) {
8183
PinnedNotesGrid(
8284
notes = pinnedNotes,
85+
adaptiveScaling = adaptiveScaling,
86+
manualColumns = manualColumns,
8387
showSyncStatus = showSyncStatus,
8488
selectedNoteIds = selectedNoteIds,
8589
isSelectionMode = isSelectionMode,
@@ -140,43 +144,38 @@ fun NotesStaggeredGrid(
140144
@Composable
141145
private fun PinnedNotesGrid(
142146
notes: List<Note>,
147+
adaptiveScaling: Boolean,
148+
manualColumns: Int,
143149
showSyncStatus: Boolean,
144150
selectedNoteIds: Set<String>,
145151
isSelectionMode: Boolean,
146152
timestampTicker: Long,
147153
onNoteClick: (Note) -> Unit,
148154
onNoteLongClick: (Note) -> Unit
149155
) {
150-
val leftNotes = remember(notes) { notes.filterIndexed { i, _ -> i % 2 == 0 } }
151-
val rightNotes = remember(notes) { notes.filterIndexed { i, _ -> i % 2 == 1 } }
152-
Row(
153-
modifier = Modifier.fillMaxWidth(),
154-
horizontalArrangement = Arrangement.spacedBy(12.dp)
155-
) {
156-
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(12.dp)) {
157-
leftNotes.forEach { note ->
158-
NoteCardGrid(
159-
note = note,
160-
showSyncStatus = showSyncStatus,
161-
isSelected = selectedNoteIds.contains(note.id),
162-
isSelectionMode = isSelectionMode,
163-
timestampTicker = timestampTicker,
164-
onClick = { onNoteClick(note) },
165-
onLongClick = { onNoteLongClick(note) }
166-
)
167-
}
156+
BoxWithConstraints(modifier = Modifier.fillMaxWidth()) {
157+
val columnCount = if (adaptiveScaling) max(1, (maxWidth / 150.dp).toInt()) else manualColumns
158+
val columnedNotes = remember(notes, columnCount) {
159+
(0 until columnCount).map { col -> notes.filterIndexed { i, _ -> i % columnCount == col } }
168160
}
169-
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(12.dp)) {
170-
rightNotes.forEach { note ->
171-
NoteCardGrid(
172-
note = note,
173-
showSyncStatus = showSyncStatus,
174-
isSelected = selectedNoteIds.contains(note.id),
175-
isSelectionMode = isSelectionMode,
176-
timestampTicker = timestampTicker,
177-
onClick = { onNoteClick(note) },
178-
onLongClick = { onNoteLongClick(note) }
179-
)
161+
Row(
162+
modifier = Modifier.fillMaxWidth(),
163+
horizontalArrangement = Arrangement.spacedBy(12.dp)
164+
) {
165+
columnedNotes.forEach { columnNotes ->
166+
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(12.dp)) {
167+
columnNotes.forEach { note ->
168+
NoteCardGrid(
169+
note = note,
170+
showSyncStatus = showSyncStatus,
171+
isSelected = selectedNoteIds.contains(note.id),
172+
isSelectionMode = isSelectionMode,
173+
timestampTicker = timestampTicker,
174+
onClick = { onNoteClick(note) },
175+
onLongClick = { onNoteLongClick(note) }
176+
)
177+
}
178+
}
180179
}
181180
}
182181
}

0 commit comments

Comments
 (0)