ios: refactor views with ViewBuilder (#558)
This commit is contained in:
committed by
GitHub
parent
0c37282cd3
commit
4a2bfef4b3
@@ -27,12 +27,7 @@ struct FramedItemView: View {
|
||||
let v = ZStack(alignment: .bottomTrailing) {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
if let qi = chatItem.quotedItem {
|
||||
if let imgWidth = imgWidth, imgWidth < maxWidth {
|
||||
ciQuoteView(qi)
|
||||
.frame(maxWidth: imgWidth, alignment: .leading)
|
||||
} else {
|
||||
ciQuoteView(qi)
|
||||
}
|
||||
ciQuoteView(qi)
|
||||
}
|
||||
|
||||
if chatItem.formattedText == nil && chatItem.file == nil && isShortEmoji(chatItem.content.text) {
|
||||
@@ -58,12 +53,7 @@ struct FramedItemView: View {
|
||||
value: .white
|
||||
)
|
||||
} else {
|
||||
let v = ciMsgContentView (chatItem, showMember)
|
||||
if let imgWidth = imgWidth, imgWidth < maxWidth {
|
||||
v.frame(maxWidth: imgWidth, alignment: .leading)
|
||||
} else {
|
||||
v
|
||||
}
|
||||
ciMsgContentView (chatItem, showMember)
|
||||
}
|
||||
case let .link(_, preview):
|
||||
CILinkView(linkPreview: preview)
|
||||
@@ -100,8 +90,8 @@ struct FramedItemView: View {
|
||||
)
|
||||
}
|
||||
|
||||
private func ciQuoteView(_ qi: CIQuote) -> some View {
|
||||
ZStack(alignment: .topTrailing) {
|
||||
@ViewBuilder private func ciQuoteView(_ qi: CIQuote) -> some View {
|
||||
let v = ZStack(alignment: .topTrailing) {
|
||||
if case let .image(_, image) = qi.content,
|
||||
let data = Data(base64Encoded: dropImagePrefix(image)),
|
||||
let uiImage = UIImage(data: data) {
|
||||
@@ -123,6 +113,33 @@ struct FramedItemView: View {
|
||||
? (colorScheme == .light ? sentQuoteColorLight : sentQuoteColorDark)
|
||||
: Color(uiColor: .quaternarySystemFill)
|
||||
)
|
||||
|
||||
if let imgWidth = imgWidth, imgWidth < maxWidth {
|
||||
v.frame(maxWidth: imgWidth, alignment: .leading)
|
||||
} else {
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func ciMsgContentView(_ ci: ChatItem, _ showMember: Bool = false) -> some View {
|
||||
let v = MsgContentView(
|
||||
content: ci.content,
|
||||
formattedText: ci.formattedText,
|
||||
sender: showMember ? ci.memberDisplayName : nil,
|
||||
metaText: ci.timestampText,
|
||||
edited: ci.meta.itemEdited
|
||||
)
|
||||
.padding(.vertical, 6)
|
||||
.padding(.horizontal, 12)
|
||||
.overlay(DetermineWidth())
|
||||
.frame(minWidth: 0, alignment: .leading)
|
||||
.textSelection(.enabled)
|
||||
|
||||
if let imgWidth = imgWidth, imgWidth < maxWidth {
|
||||
v.frame(maxWidth: imgWidth, alignment: .leading)
|
||||
} else {
|
||||
v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,21 +161,6 @@ private func ciQuotedMsgView(_ qi: CIQuote) -> some View {
|
||||
.padding(.horizontal, 12)
|
||||
}
|
||||
|
||||
private func ciMsgContentView(_ ci: ChatItem, _ showMember: Bool = false) -> some View {
|
||||
MsgContentView(
|
||||
content: ci.content,
|
||||
formattedText: ci.formattedText,
|
||||
sender: showMember ? ci.memberDisplayName : nil,
|
||||
metaText: ci.timestampText,
|
||||
edited: ci.meta.itemEdited
|
||||
)
|
||||
.padding(.vertical, 6)
|
||||
.padding(.horizontal, 12)
|
||||
.overlay(DetermineWidth())
|
||||
.frame(minWidth: 0, alignment: .leading)
|
||||
.textSelection(.enabled)
|
||||
}
|
||||
|
||||
func chatItemFrameColor(_ ci: ChatItem, _ colorScheme: ColorScheme) -> Color {
|
||||
ci.chatDir.sent
|
||||
? (colorScheme == .light ? sentColorLight : sentColorDark)
|
||||
|
||||
@@ -16,14 +16,7 @@ struct ChatListNavLink: View {
|
||||
var body: some View {
|
||||
switch chat.chatInfo {
|
||||
case let .direct(contact):
|
||||
if contact.ready {
|
||||
contactNavLink(contact)
|
||||
} else {
|
||||
contactNavLink(contact)
|
||||
.onTapGesture {
|
||||
AlertManager.shared.showAlert(pendingContactAlert(chat, contact))
|
||||
}
|
||||
}
|
||||
contactNavLink(contact)
|
||||
case let .group(groupInfo):
|
||||
groupNavLink(groupInfo)
|
||||
case let .contactRequest(cReq):
|
||||
@@ -45,8 +38,8 @@ struct ChatListNavLink: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func contactNavLink(_ contact: Contact) -> some View {
|
||||
NavLinkPlain(
|
||||
@ViewBuilder private func contactNavLink(_ contact: Contact) -> some View {
|
||||
let v = NavLinkPlain(
|
||||
tag: chat.chatInfo.id,
|
||||
selection: $chatModel.chatId,
|
||||
destination: { chatView() },
|
||||
@@ -70,6 +63,14 @@ struct ChatListNavLink: View {
|
||||
}
|
||||
}
|
||||
.frame(height: 80)
|
||||
|
||||
if contact.ready {
|
||||
v
|
||||
} else {
|
||||
v.onTapGesture {
|
||||
AlertManager.shared.showAlert(pendingContactAlert(chat, contact))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func groupNavLink(_ groupInfo: GroupInfo) -> some View {
|
||||
|
||||
Reference in New Issue
Block a user