fix header padding

This commit is contained in:
spaced4ndy
2024-04-17 16:54:08 +04:00
parent 9050be0ea5
commit 63f2b15f02
2 changed files with 18 additions and 16 deletions

View File

@@ -40,19 +40,20 @@ struct FramedItemView: View {
var body: some View {
let v = ZStack(alignment: .bottomTrailing) {
VStack(alignment: .leading, spacing: 0) {
let firstHeaderPadBottom = chatItem.quotedItem == nil && chatItem.meta.itemForwarded == nil
if let di = chatItem.meta.itemDeleted {
switch di {
case let .moderated(_, byGroupMember):
framedItemHeader(icon: "flag", caption: Text("moderated by \(byGroupMember.displayName)").italic())
framedItemHeader(icon: "flag", caption: Text("moderated by \(byGroupMember.displayName)").italic(), padBottom: firstHeaderPadBottom)
case .blocked:
framedItemHeader(icon: "hand.raised", caption: Text("blocked").italic())
framedItemHeader(icon: "hand.raised", caption: Text("blocked").italic(), padBottom: firstHeaderPadBottom)
case .blockedByAdmin:
framedItemHeader(icon: "hand.raised", caption: Text("blocked by admin").italic())
framedItemHeader(icon: "hand.raised", caption: Text("blocked by admin").italic(), padBottom: firstHeaderPadBottom)
case .deleted:
framedItemHeader(icon: "trash", caption: Text("marked deleted").italic())
framedItemHeader(icon: "trash", caption: Text("marked deleted").italic(), padBottom: firstHeaderPadBottom)
}
} else if chatItem.meta.isLive {
framedItemHeader(caption: Text("LIVE"))
framedItemHeader(caption: Text("LIVE"), padBottom: firstHeaderPadBottom)
}
if let qi = chatItem.quotedItem {
@@ -66,7 +67,7 @@ struct FramedItemView: View {
}
}
} else if let itemForwarded = chatItem.meta.itemForwarded {
framedItemHeader(icon: "arrowshape.turn.up.forward", caption: Text(itemForwarded.text(chat.chatInfo.chatType)).italic(), pad: true)
framedItemHeader(icon: "arrowshape.turn.up.forward", caption: Text(itemForwarded.text(chat.chatInfo.chatType)).italic(), padBottom: true)
}
ChatItemContentView(chat: chat, chatItem: chatItem, revealed: $revealed, msgContentView: framedMsgContentView)
@@ -165,7 +166,7 @@ struct FramedItemView: View {
)
}
@ViewBuilder func framedItemHeader(icon: String? = nil, caption: Text, pad: Bool = true) -> some View {
@ViewBuilder func framedItemHeader(icon: String? = nil, caption: Text, padBottom: Bool) -> some View {
let v = HStack(spacing: 6) {
if let icon = icon {
Image(systemName: icon)
@@ -180,7 +181,7 @@ struct FramedItemView: View {
.foregroundColor(.secondary)
.padding(.horizontal, 12)
.padding(.top, 6)
.padding(.bottom, pad || (chatItem.quotedItem == nil && chatItem.meta.itemForwarded == nil) ? 6 : 0)
.padding(.bottom, padBottom ? 6 : 0)
.overlay(DetermineWidth())
.frame(minWidth: msgWidth, alignment: .leading)
.background(chatItemFrameContextColor(chatItem, colorScheme))

View File

@@ -87,14 +87,14 @@ fun FramedItemView(
}
@Composable
fun FramedItemHeader(caption: String, italic: Boolean, icon: Painter? = null, pad: Boolean = true) {
fun FramedItemHeader(caption: String, italic: Boolean, icon: Painter? = null, padBottom: Boolean) {
val sentColor = CurrentColors.collectAsState().value.appColors.sentMessage
val receivedColor = CurrentColors.collectAsState().value.appColors.receivedMessage
Row(
Modifier
.background(if (sent) sentColor.toQuote() else receivedColor.toQuote())
.fillMaxWidth()
.padding(start = 8.dp, top = 6.dp, end = 12.dp, bottom = if (pad || (ci.quotedItem == null && ci.meta.itemForwarded == null)) 6.dp else 0.dp),
.padding(start = 8.dp, top = 6.dp, end = 12.dp, bottom = if (padBottom) 6.dp else 0.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically
) {
@@ -202,28 +202,29 @@ fun FramedItemView(
Box(contentAlignment = Alignment.BottomEnd) {
Column(Modifier.width(IntrinsicSize.Max)) {
PriorityLayout(Modifier, CHAT_IMAGE_LAYOUT_ID) {
val firstHeaderPadBottom = ci.quotedItem == null && ci.meta.itemForwarded == null
if (ci.meta.itemDeleted != null) {
when (ci.meta.itemDeleted) {
is CIDeleted.Moderated -> {
FramedItemHeader(String.format(stringResource(MR.strings.moderated_item_description), ci.meta.itemDeleted.byGroupMember.chatViewName), true, painterResource(MR.images.ic_flag))
FramedItemHeader(String.format(stringResource(MR.strings.moderated_item_description), ci.meta.itemDeleted.byGroupMember.chatViewName), true, painterResource(MR.images.ic_flag), padBottom = firstHeaderPadBottom)
}
is CIDeleted.Blocked -> {
FramedItemHeader(stringResource(MR.strings.blocked_item_description), true, painterResource(MR.images.ic_back_hand))
FramedItemHeader(stringResource(MR.strings.blocked_item_description), true, painterResource(MR.images.ic_back_hand), padBottom = firstHeaderPadBottom)
}
is CIDeleted.BlockedByAdmin -> {
FramedItemHeader(stringResource(MR.strings.blocked_by_admin_item_description), true, painterResource(MR.images.ic_back_hand))
FramedItemHeader(stringResource(MR.strings.blocked_by_admin_item_description), true, painterResource(MR.images.ic_back_hand), padBottom = firstHeaderPadBottom)
}
is CIDeleted.Deleted -> {
FramedItemHeader(stringResource(MR.strings.marked_deleted_description), true, painterResource(MR.images.ic_delete))
FramedItemHeader(stringResource(MR.strings.marked_deleted_description), true, painterResource(MR.images.ic_delete), padBottom = firstHeaderPadBottom)
}
}
} else if (ci.meta.isLive) {
FramedItemHeader(stringResource(MR.strings.live), false)
FramedItemHeader(stringResource(MR.strings.live), false, padBottom = firstHeaderPadBottom)
}
if (ci.quotedItem != null) {
ciQuoteView(ci.quotedItem)
} else if (ci.meta.itemForwarded != null) {
FramedItemHeader(ci.meta.itemForwarded.text(chatInfo.chatType), true, painterResource(MR.images.ic_forward), pad = true)
FramedItemHeader(ci.meta.itemForwarded.text(chatInfo.chatType), true, painterResource(MR.images.ic_forward), padBottom = true)
}
if (ci.file == null && ci.formattedText == null && !ci.meta.isLive && isShortEmoji(ci.content.text)) {
Box(Modifier.padding(vertical = 6.dp, horizontal = 12.dp)) {