Reactors base note rendering to wrap the QuickAction menu

This commit is contained in:
Vitor Pamplona
2023-06-09 14:07:38 -04:00
parent a898196571
commit 1efc4c91e2
2 changed files with 61 additions and 27 deletions
@@ -179,19 +179,17 @@ fun NoteCompose(
val noteEvent = remember(noteState) { noteState?.note?.event } val noteEvent = remember(noteState) { noteState?.note?.event }
if (noteEvent == null) { if (noteEvent == null) {
var popupExpanded by remember { mutableStateOf(false) } LongPressToQuickAction(baseNote = baseNote, accountViewModel = accountViewModel) { showPopup ->
BlankNote(
BlankNote( remember {
remember { modifier.combinedClickable(
modifier.combinedClickable( onClick = { },
onClick = { }, onLongClick = showPopup
onLongClick = { popupExpanded = true } )
) },
}, isBoostedNote || isQuotedNote
isBoostedNote || isQuotedNote )
) }
NoteQuickActionMenu(baseNote, popupExpanded, { popupExpanded = false }, accountViewModel)
} else { } else {
CheckHiddenNoteCompose( CheckHiddenNoteCompose(
baseNote, baseNote,
@@ -384,7 +382,7 @@ fun NormalNote(
} else if (noteEvent is FileStorageHeaderEvent) { } else if (noteEvent is FileStorageHeaderEvent) {
FileStorageHeaderDisplay(baseNote) FileStorageHeaderDisplay(baseNote)
} else { } else {
NoteWithReactions( CheckNewAndRenderNote(
baseNote, baseNote,
routeForLastRead, routeForLastRead,
modifier, modifier,
@@ -403,7 +401,7 @@ fun NormalNote(
@Composable @Composable
@OptIn(ExperimentalFoundationApi::class) @OptIn(ExperimentalFoundationApi::class)
private fun NoteWithReactions( private fun CheckNewAndRenderNote(
baseNote: Note, baseNote: Note,
routeForLastRead: String? = null, routeForLastRead: String? = null,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@@ -418,9 +416,6 @@ private fun NoteWithReactions(
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
var isNew by remember { mutableStateOf<Boolean>(false) } var isNew by remember { mutableStateOf<Boolean>(false) }
var popupExpanded by remember { mutableStateOf(false) }
val scope = rememberCoroutineScope()
LaunchedEffect(key1 = routeForLastRead) { LaunchedEffect(key1 = routeForLastRead) {
launch(Dispatchers.IO) { launch(Dispatchers.IO) {
@@ -455,7 +450,43 @@ private fun NoteWithReactions(
} }
} }
val columnModifier = remember(backgroundColor) { LongPressToQuickAction(baseNote = baseNote, accountViewModel = accountViewModel) { showPopup ->
RenderNoteWithReactions(
backgroundColor,
showPopup,
modifier,
baseNote,
accountViewModel,
nav,
isBoostedNote,
isQuotedNote,
addMarginTop,
unPackReply,
makeItShort,
canPreview
)
}
}
@Composable
@OptIn(ExperimentalFoundationApi::class)
private fun RenderNoteWithReactions(
backgroundColor: Color,
showPopup: () -> Unit,
modifier: Modifier,
baseNote: Note,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
isBoostedNote: Boolean,
isQuotedNote: Boolean,
addMarginTop: Boolean,
unPackReply: Boolean,
makeItShort: Boolean,
canPreview: Boolean
) {
val scope = rememberCoroutineScope()
val columnModifier = remember(backgroundColor, showPopup) {
modifier modifier
.combinedClickable( .combinedClickable(
onClick = { onClick = {
@@ -465,7 +496,7 @@ private fun NoteWithReactions(
} }
} }
}, },
onLongClick = { popupExpanded = true } onLongClick = showPopup
) )
.background(backgroundColor) .background(backgroundColor)
} }
@@ -510,13 +541,6 @@ private fun NoteWithReactions(
accountViewModel, accountViewModel,
nav nav
) )
NoteQuickActionMenu(
baseNote,
popupExpanded,
{ popupExpanded = false },
accountViewModel
)
} }
if (!makeItShort && baseNote.event !is RepostEvent) { if (!makeItShort && baseNote.event !is RepostEvent) {
@@ -110,6 +110,16 @@ private fun VerticalDivider(color: Color) =
.width(1.dp) .width(1.dp)
) )
@Composable
fun LongPressToQuickAction(baseNote: Note, accountViewModel: AccountViewModel, content: @Composable (() -> Unit) -> Unit) {
var popupExpanded by remember { mutableStateOf(false) }
val showPopup = remember { { popupExpanded = true } }
content(showPopup)
NoteQuickActionMenu(baseNote, popupExpanded, { popupExpanded = false }, accountViewModel)
}
@Composable @Composable
fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit, accountViewModel: AccountViewModel) { fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit, accountViewModel: AccountViewModel) {
var showSelectTextDialog by remember(note) { mutableStateOf(false) } var showSelectTextDialog by remember(note) { mutableStateOf(false) }