mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3095 Chats | Fix | Misc. fixes and scroll to reply (naive implementation) (#1865)
This commit is contained in:
parent
c02de4699e
commit
e5013afb34
4 changed files with 74 additions and 26 deletions
|
@ -89,7 +89,6 @@ class DiscussionViewModel @Inject constructor(
|
|||
}
|
||||
)
|
||||
}
|
||||
|
||||
is Params.SpaceLevelChat -> {
|
||||
val targetSpaceView = spaceViews.get(vmParams.space)
|
||||
val spaceLevelChat = targetSpaceView?.getValue<Id>(Relations.CHAT_ID)
|
||||
|
|
|
@ -146,7 +146,8 @@ fun BubblePreview() {
|
|||
onAttachmentClicked = {},
|
||||
onEditMessage = {},
|
||||
onMarkupLinkClicked = {},
|
||||
onReply = {}
|
||||
onReply = {},
|
||||
onScrollToReplyClicked = {}
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -172,7 +173,8 @@ fun BubbleEditedPreview() {
|
|||
onAttachmentClicked = {},
|
||||
onEditMessage = {},
|
||||
onMarkupLinkClicked = {},
|
||||
onReply = {}
|
||||
onReply = {},
|
||||
onScrollToReplyClicked = {}
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -205,6 +207,7 @@ fun BubbleWithAttachmentPreview() {
|
|||
onAttachmentClicked = {},
|
||||
onEditMessage = {},
|
||||
onMarkupLinkClicked = {},
|
||||
onReply = {}
|
||||
onReply = {},
|
||||
onScrollToReplyClicked = {}
|
||||
)
|
||||
}
|
|
@ -1,8 +1,16 @@
|
|||
package com.anytypeio.anytype.feature_discussions.ui
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.animation.expandIn
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.animation.shrinkOut
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
|
@ -288,7 +296,10 @@ fun DiscussionScreen(
|
|||
chatBoxFocusRequester.requestFocus()
|
||||
}
|
||||
},
|
||||
onReplyMessage = onReplyMessage,
|
||||
onReplyMessage = {
|
||||
onReplyMessage(it)
|
||||
chatBoxFocusRequester.requestFocus()
|
||||
},
|
||||
onMarkupLinkClicked = onMarkupLinkClicked
|
||||
)
|
||||
// Jump to bottom button shows up when user scrolls past a threshold.
|
||||
|
@ -751,6 +762,31 @@ private fun ChatBox(
|
|||
}
|
||||
}
|
||||
}
|
||||
AnimatedVisibility(
|
||||
visible = attachments.isNotEmpty() || textState.text.isNotEmpty(),
|
||||
exit = fadeOut() + scaleOut(),
|
||||
enter = fadeIn() + scaleIn()
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 4.dp, vertical = 8.dp)
|
||||
.clip(CircleShape)
|
||||
.align(Alignment.Bottom)
|
||||
.clickable {
|
||||
onMessageSent(textState.text)
|
||||
clearText()
|
||||
resetScroll()
|
||||
}
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.ic_send_message),
|
||||
contentDescription = "Send message button",
|
||||
modifier = Modifier
|
||||
.align(Alignment.Center)
|
||||
.padding(horizontal = 4.dp, vertical = 4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -890,6 +926,7 @@ fun Messages(
|
|||
onReplyMessage: (DiscussionView.Message) -> Unit,
|
||||
onMarkupLinkClicked: (String) -> Unit
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
LazyColumn(
|
||||
modifier = modifier,
|
||||
reverseLayout = true,
|
||||
|
@ -942,7 +979,16 @@ fun Messages(
|
|||
onReply = {
|
||||
onReplyMessage(msg)
|
||||
},
|
||||
reply = msg.reply
|
||||
reply = msg.reply,
|
||||
onScrollToReplyClicked = { reply ->
|
||||
// Naive implementation
|
||||
val idx = messages.indexOfFirst { it.id == reply.msg }
|
||||
if (idx != -1) {
|
||||
scope.launch {
|
||||
scrollState.animateScrollToItem(index = idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
if (msg.isUserAuthor) {
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
@ -1074,7 +1120,8 @@ fun Bubble(
|
|||
onEditMessage: () -> Unit,
|
||||
onReply: () -> Unit,
|
||||
onAttachmentClicked: (DiscussionView.Message.Attachment) -> Unit,
|
||||
onMarkupLinkClicked: (String) -> Unit
|
||||
onMarkupLinkClicked: (String) -> Unit,
|
||||
onScrollToReplyClicked: (DiscussionView.Message.Reply) -> Unit
|
||||
) {
|
||||
var showDropdownMenu by remember { mutableStateOf(false) }
|
||||
Column(
|
||||
|
@ -1102,6 +1149,9 @@ fun Bubble(
|
|||
color = colorResource(R.color.navigation_panel_icon),
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
)
|
||||
.clickable {
|
||||
onScrollToReplyClicked(reply)
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = reply.author,
|
||||
|
@ -1112,10 +1162,7 @@ fun Bubble(
|
|||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
color = if (isUserAuthor)
|
||||
colorResource(id = R.color.text_white)
|
||||
else
|
||||
colorResource(id = R.color.text_primary),
|
||||
color = colorResource(id = R.color.text_white)
|
||||
)
|
||||
Text(
|
||||
modifier = Modifier.padding(
|
||||
|
@ -1126,10 +1173,7 @@ fun Bubble(
|
|||
text = reply.text,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
color = if (isUserAuthor)
|
||||
colorResource(id = R.color.text_white)
|
||||
else
|
||||
colorResource(id = R.color.text_primary),
|
||||
color = colorResource(id = R.color.text_white),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1203,15 +1247,14 @@ fun Bubble(
|
|||
append(part.part)
|
||||
}
|
||||
}
|
||||
|
||||
if (isEdited) {
|
||||
withStyle(
|
||||
style = SpanStyle(color = colorResource(id = R.color.text_tertiary))
|
||||
) {
|
||||
append(
|
||||
" (${stringResource(R.string.chats_message_edited)})"
|
||||
)
|
||||
}
|
||||
}
|
||||
if (isEdited) {
|
||||
withStyle(
|
||||
style = SpanStyle(color = colorResource(id = R.color.text_tertiary))
|
||||
) {
|
||||
append(
|
||||
" (${stringResource(R.string.chats_message_edited)})"
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
android:viewportWidth="32"
|
||||
android:viewportHeight="32">
|
||||
<path
|
||||
android:pathData="M5.406,25.615C4.709,24.9 5.032,24.094 5.564,23.088L8.329,17.813C8.688,17.153 8.966,16.915 9.565,16.899L25.466,16.285C25.653,16.277 25.758,16.154 25.758,16.001C25.75,15.855 25.653,15.724 25.466,15.717L9.565,15.164C8.943,15.141 8.658,14.88 8.329,14.235L5.511,8.829C5.009,7.869 4.717,7.094 5.406,6.387C5.953,5.827 6.823,5.934 7.692,6.333L25.518,14.481C25.998,14.696 26.38,14.934 26.635,15.195C27.122,15.694 27.122,16.308 26.635,16.807C26.38,17.068 25.998,17.306 25.518,17.521L7.789,25.63C6.793,26.083 5.946,26.167 5.406,25.615Z"
|
||||
android:fillColor="@color/glyph_selected"/>
|
||||
android:pathData="M0,16C0,7.163 7.163,0 16,0C24.837,0 32,7.163 32,16C32,24.837 24.837,32 16,32C7.163,32 0,24.837 0,16Z"
|
||||
android:fillColor="@color/glyph_button"/>
|
||||
<path
|
||||
android:pathData="M10.259,21.769C9.815,21.34 10.02,20.857 10.359,20.253L12.118,17.088C12.347,16.692 12.524,16.549 12.905,16.54L23.024,16.171C23.143,16.166 23.21,16.093 23.21,16C23.205,15.913 23.143,15.835 23.024,15.83L12.905,15.498C12.509,15.484 12.328,15.328 12.118,14.941L10.325,11.697C10.006,11.122 9.82,10.656 10.259,10.232C10.607,9.896 11.16,9.96 11.713,10.2L23.057,15.088C23.362,15.217 23.605,15.36 23.767,15.517C24.077,15.816 24.077,16.185 23.767,16.484C23.605,16.641 23.362,16.784 23.057,16.913L11.775,21.778C11.141,22.05 10.602,22.101 10.259,21.769Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
</vector>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue