session-ios/Session/Conversations/Message Cells/Content Views/OpenGroupInvitationView_Swi...

90 lines
2.8 KiB
Swift

// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
import SwiftUI
import SessionUIKit
import SessionMessagingKit
struct OpenGroupInvitationView_SwiftUI: View {
private let name: String
private let url: String
private let textColor: ThemeValue
private let isOutgoing: Bool
private static let iconSize: CGFloat = 24
private static let iconImageViewSize: CGFloat = 48
init(
name: String,
url: String,
textColor: ThemeValue,
isOutgoing: Bool
) {
self.name = name
self.url = {
if let range = url.range(of: "?public_key=") {
return String(url[..<range.lowerBound])
}
return url
}()
self.textColor = textColor
self.isOutgoing = isOutgoing
}
var body: some View {
HStack(
alignment: .center,
spacing: Values.mediumSpacing
) {
// Icon
let iconName = (isOutgoing ? "Globe" : "Plus")
if let iconImage = UIImage(named: iconName)?
.resizedImage(to: CGSize(width: Self.iconSize, height: Self.iconSize))?
.withRenderingMode(.alwaysTemplate)
{
Image(uiImage: iconImage)
.foregroundColor(themeColor: (isOutgoing ? .messageBubble_outgoingText : .textPrimary))
.background(
Circle()
.fill(themeColor: (isOutgoing ? .messageBubble_overlay : .primary))
.frame(
width: Self.iconImageViewSize,
height: Self.iconImageViewSize
)
)
}
// Text
VStack(
spacing: 2
) {
Text(name)
.bold()
.font(.system(size: Values.largeFontSize))
.foregroundColor(themeColor: textColor)
Text("view_open_group_invitation_description".localized())
.font(.system(size: Values.smallFontSize))
.foregroundColor(themeColor: textColor)
.padding(.bottom, 2)
Text(url)
.font(.system(size: Values.verySmallFontSize))
.foregroundColor(themeColor: textColor)
.multilineTextAlignment(.leading)
}
}
}
}
struct OpenGroupInvitationView_SwiftUI_Previews: PreviewProvider {
static var previews: some View {
OpenGroupInvitationView_SwiftUI(
name: "Session",
url: "",
textColor: .messageBubble_outgoingText,
isOutgoing: true
)
}
}