Files
simplex-chat/apps/ios/Shared/Views/Chat/ChatItem/CIGroupInvitationView.swift
Evgeny @ SimpleX Chat 56b4ca73cc ios: exact alignment and spacing (#7945)
* ios: exact alignment and spacing

* ios: previews of the views changed for alignment and spacing

* ci: iOS references of exact alignment and spacing

* ios: single check and the time under a received emoji keep their places

* ios: deleted text, link strip text, What's new, app version, QR cards and onion hosts keep master's layout; info headers get more space above the avatar; chat row preview with contact requests

* ci: iOS references of the review round and of chat rows with contact requests

* ios: keep master's tags, requests, group icon, footers, compose strips

* ci: iOS references of the views back on master's layout

* ios: the pull request holds only the agreed changes, without previews of reverted ones

* ios: contact request view as on master
2026-11-01 07:46:07 +00:00

173 lines
6.9 KiB
Swift

//
// CIGroupInvitationView.swift
// SimpleX (iOS)
//
// Created by JRoberts on 15.07.2022.
// Copyright © 2022 SimpleX Chat. All rights reserved.
//
// Spec: spec/client/chat-view.md
import SwiftUI
import SimpleXChat
// Spec: spec/client/chat-view.md#CIGroupInvitationView
struct CIGroupInvitationView: View {
@EnvironmentObject var chatModel: ChatModel
@EnvironmentObject var theme: AppTheme
@Environment(\.showTimestamp) var showTimestamp: Bool
@ObservedObject var chat: Chat
var chatItem: ChatItem
var groupInvitation: CIGroupInvitation
var memberRole: GroupMemberRole
var chatIncognito: Bool = false
@State private var frameWidth: CGFloat = 0
@State private var inProgress = false
@State private var progressByTimeout = false
@AppStorage(DEFAULT_SHOW_SENT_VIA_RPOXY) private var showSentViaProxy = false
var body: some View {
let action = !chatItem.chatDir.sent && groupInvitation.status == .pending
let v = ItemWithMeta {
CIMetaView(chat: chat, chatItem: chatItem, metaColor: theme.colors.secondary, showStatus: false, showEdited: false)
} content: { inlineMeta in
ZStack(alignment: Alignment(horizontal: .trailing, vertical: .lastTextBaseline)) {
ZStack {
VStack(alignment: .leading) {
groupInfoView(action)
.padding(.horizontal, 2)
.padding(.top, 8)
.padding(.bottom, 6)
.overlay(DetermineWidth())
Divider().frame(width: frameWidth)
if chat.chatInfo.groupInfo != nil {
Text(chatItem.chatDir.sent ? String.localizedStringWithFormat(NSLocalizedString("For %@ only", comment: ""), groupInvitation.localDisplayName) : NSLocalizedString("For you only", comment: ""))
.font(.caption)
.foregroundColor(theme.colors.secondary)
.overlay(DetermineWidth())
}
if action {
VStack(alignment: .leading, spacing: 2) {
groupInvitationText()
.overlay(DetermineWidth())
(
Text(chatIncognito ? "Tap to join incognito" : "Tap to join")
.foregroundColor(inProgress ? theme.colors.secondary : chatIncognito ? .indigo : theme.colors.primary)
.font(.callout)
+ metaReserve(inlineMeta)
)
.overlay(DetermineWidth())
}
} else {
(
groupInvitationText()
+ metaReserve(inlineMeta)
)
.overlay(DetermineWidth())
}
}
.padding(.bottom, 2)
if progressByTimeout {
ProgressView().scaleEffect(2)
}
}
if let inlineMeta {
inlineMeta
}
}
.padding(.horizontal, 12)
.padding(.vertical, 6)
.background { chatItemFrameColor(chatItem, theme).modifier(ChatTailPadding()) }
.if(inlineMeta == nil) { $0.modifier(ChatItemClipped(chatItem, tailVisible: false)) }
}
.textSelection(.disabled)
.onPreferenceChange(DetermineWidth.Key.self) { frameWidth = $0 }
.onChange(of: inProgress) { inProgress in
if inProgress {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
progressByTimeout = inProgress
}
} else {
progressByTimeout = false
}
}
if action {
v.simultaneousGesture(TapGesture().onEnded {
inProgress = true
joinGroup(groupInvitation.groupId) {
await MainActor.run { inProgress = false }
}
})
.disabled(inProgress)
} else {
v
}
}
private func groupInfoView(_ action: Bool) -> some View {
var color: Color
if action && !inProgress {
color = chatIncognito ? .indigo : theme.colors.primary
} else {
color = Color(uiColor: .tertiaryLabel)
}
return HStack(alignment: .top) {
ProfileImage(
imageStr: groupInvitation.groupProfile.image,
icon: Image(systemName: "person.2.circle.fill"),
size: 44,
color: color
)
.padding(.trailing, 4)
VStack(alignment: .leading) {
let p = groupInvitation.groupProfile
Text(p.displayName).font(.headline).lineLimit(2)
if p.fullName != "" && p.displayName != p.fullName {
Text(p.fullName).font(.subheadline).lineLimit(2)
}
}
.frame(minHeight: 44)
}
}
private func groupInvitationText() -> Text {
Text(groupInvitationStr())
.font(.callout)
}
private func metaReserve(_ inlineMeta: CIMetaView?) -> Text {
inlineMeta == nil
? Text(verbatim: "")
: Text(verbatim: " ") + ciMetaText(chatItem.meta, chatTTL: nil, encrypted: nil, colorMode: .transparent, showStatus: false, showEdited: false, showViaProxy: showSentViaProxy, showTimesamp: showTimestamp)
}
private func groupInvitationStr() -> LocalizedStringKey {
if chatItem.chatDir.sent {
return "You sent group invitation"
} else {
switch groupInvitation.status {
case .pending: return "You are invited to group"
case .accepted: return "You joined this group"
case .rejected: return "You rejected group invitation"
case .expired: return "Group invitation expired"
}
}
}
}
struct CIGroupInvitationView_Previews: PreviewProvider {
static var previews: some View {
Group {
let ci = previewDated(ChatItem.getGroupInvitationSample())
CIGroupInvitationView(chat: Chat.sampleData, chatItem: ci, groupInvitation: CIGroupInvitation.getSample(groupProfile: GroupProfile(displayName: "team", fullName: "team")), memberRole: .admin).modifier(ChatItemClipped(ci, tailVisible: true))
CIGroupInvitationView(chat: Chat.sampleData, chatItem: ci, groupInvitation: CIGroupInvitation.getSample(status: .accepted), memberRole: .admin).modifier(ChatItemClipped(ci, tailVisible: true))
}
}
}