Add close button and swipe-left-to-close on view all pages
- X button in top app bar navigates back to notebook list - Swipe left gesture (>200px) on the page grid closes to notebook list - Both clear the notebook and view-all-pages state in SharedPreferences Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -159,6 +159,11 @@ fun EngPadNavGraph(
|
|||||||
?.set("selectedPageId", pageId)
|
?.set("selectedPageId", pageId)
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
},
|
},
|
||||||
|
onClose = {
|
||||||
|
onNotebookClosed()
|
||||||
|
onViewAllPagesChanged(false)
|
||||||
|
navController.popBackStack(Routes.NOTEBOOKS, false)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.graphics.Paint as AndroidPaint
|
|||||||
import android.graphics.Path as AndroidPath
|
import android.graphics.Path as AndroidPath
|
||||||
import androidx.compose.foundation.Canvas
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -39,6 +40,7 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
|
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
|
||||||
import androidx.compose.ui.graphics.graphicsLayer
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.graphics.nativeCanvas
|
import androidx.compose.ui.graphics.nativeCanvas
|
||||||
@@ -65,6 +67,7 @@ fun PageListScreen(
|
|||||||
pageSize: PageSize,
|
pageSize: PageSize,
|
||||||
database: EngPadDatabase,
|
database: EngPadDatabase,
|
||||||
onPageClick: (Long, PageSize) -> Unit,
|
onPageClick: (Long, PageSize) -> Unit,
|
||||||
|
onClose: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val repository = remember {
|
val repository = remember {
|
||||||
PageRepository(database.pageDao(), database.strokeDao())
|
PageRepository(database.pageDao(), database.strokeDao())
|
||||||
@@ -97,7 +100,14 @@ fun PageListScreen(
|
|||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
TopAppBar(title = { Text(notebookTitle) })
|
TopAppBar(
|
||||||
|
title = { Text(notebookTitle) },
|
||||||
|
navigationIcon = {
|
||||||
|
androidx.compose.material3.IconButton(onClick = onClose) {
|
||||||
|
Text("X")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
},
|
},
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
FloatingActionButton(onClick = { viewModel.addPage() }) {
|
FloatingActionButton(onClick = { viewModel.addPage() }) {
|
||||||
@@ -105,11 +115,31 @@ fun PageListScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
) { padding ->
|
) { padding ->
|
||||||
|
// Detect left swipe from right edge to close
|
||||||
|
var swipeCumulative by remember { mutableStateOf(0f) }
|
||||||
|
val swipeModifier = Modifier.pointerInput(Unit) {
|
||||||
|
detectHorizontalDragGestures(
|
||||||
|
onDragStart = { startOffset ->
|
||||||
|
swipeCumulative = 0f
|
||||||
|
},
|
||||||
|
onDragEnd = {
|
||||||
|
if (swipeCumulative < -200f) { // Swipe left threshold
|
||||||
|
onClose()
|
||||||
|
}
|
||||||
|
swipeCumulative = 0f
|
||||||
|
},
|
||||||
|
onHorizontalDrag = { _, dragAmount ->
|
||||||
|
swipeCumulative += dragAmount
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (pages.isEmpty()) {
|
if (pages.isEmpty()) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(padding),
|
.padding(padding)
|
||||||
|
.then(swipeModifier),
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
@@ -121,7 +151,8 @@ fun PageListScreen(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
.padding(8.dp),
|
.padding(8.dp)
|
||||||
|
.then(swipeModifier),
|
||||||
state = lazyGridState,
|
state = lazyGridState,
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
|||||||
Reference in New Issue
Block a user