mirror of https://github.com/oxen-io/session-ios
				
				
				
			WIP: refactor open group invitation view with SwiftUI
							parent
							
								
									a943df4f9e
								
							
						
					
					
						commit
						0c7b64b41c
					
				| @ -0,0 +1,89 @@ | |||||||
|  | // 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 | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in New Issue