UPD: Use Scaffold as anchor
This commit is contained in:
parent
4a44f99b86
commit
d6588913fd
@ -1,27 +1,15 @@
|
|||||||
package come.stormborntales.notevault.ui.screens
|
package come.stormborntales.notevault.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.border
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.offset
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.wrapContentWidth
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.lazy.items
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.FabPosition
|
|
||||||
import androidx.compose.material3.FloatingActionButton
|
import androidx.compose.material3.FloatingActionButton
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@ -31,66 +19,47 @@ import androidx.compose.runtime.remember
|
|||||||
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.geometry.Offset
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.layout.boundsInWindow
|
|
||||||
import androidx.compose.ui.layout.onGloballyPositioned
|
|
||||||
import androidx.compose.ui.layout.positionInWindow
|
|
||||||
import androidx.compose.ui.text.input.KeyboardType.Companion.Text
|
|
||||||
import androidx.compose.ui.unit.DpOffset
|
|
||||||
import androidx.compose.ui.unit.IntOffset
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Popup
|
|
||||||
@Composable
|
@Composable
|
||||||
fun NotesScreen() {
|
fun NotesScreen() {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var menuExpanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
// Anchor reference
|
Scaffold(
|
||||||
Box(
|
floatingActionButton = {
|
||||||
modifier = Modifier
|
Box {
|
||||||
.fillMaxSize()
|
FloatingActionButton(onClick = { menuExpanded = true }) {
|
||||||
.padding(16.dp),
|
Icon(Icons.Default.Add, contentDescription = "Open menu")
|
||||||
contentAlignment = Alignment.BottomEnd
|
}
|
||||||
) {
|
|
||||||
// This Box will be the anchor for the menu
|
|
||||||
Box {
|
|
||||||
var anchor by remember { mutableStateOf<androidx.compose.ui.geometry.Rect?>(null) }
|
|
||||||
|
|
||||||
FloatingActionButton(
|
|
||||||
onClick = { expanded = true },
|
|
||||||
modifier = Modifier
|
|
||||||
.onGloballyPositioned { coordinates ->
|
|
||||||
anchor = coordinates.boundsInWindow()
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.MoreVert, contentDescription = "Open menu")
|
|
||||||
}
|
|
||||||
|
|
||||||
anchor?.let {
|
|
||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
expanded = expanded,
|
expanded = menuExpanded,
|
||||||
onDismissRequest = { expanded = false },
|
onDismissRequest = { menuExpanded = false },
|
||||||
// This attaches the dropdown directly to the FAB
|
|
||||||
offset = DpOffset(0.dp, 0.dp),
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.TopEnd)
|
.wrapContentWidth()
|
||||||
) {
|
) {
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text("Option 1") },
|
text = { Text("Option 1") },
|
||||||
onClick = {
|
onClick = {
|
||||||
expanded = false
|
menuExpanded = false
|
||||||
// Handle Option 1
|
// Handle action
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text("Option 2") },
|
text = { Text("Option 2") },
|
||||||
onClick = {
|
onClick = {
|
||||||
expanded = false
|
menuExpanded = false
|
||||||
// Handle Option 2
|
// Handle action
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
content = { innerPadding ->
|
||||||
|
// Dein Hauptinhalt hier, falls benötigt
|
||||||
|
Box(modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(innerPadding)) {
|
||||||
|
Text("Inhalt deiner App", modifier = Modifier.align(Alignment.Center))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user