ProfilePicImageView.swift (3213B)
1 // 2 // ProfileZoomView.swift 3 // damus 4 // 5 // Created by scoder1747 on 12/27/22. 6 // 7 import SwiftUI 8 import Kingfisher 9 10 struct ProfileImageContainerView: View { 11 let url: URL? 12 let settings: UserSettingsStore 13 14 @State private var image: UIImage? 15 @State private var showShareSheet = false 16 17 private struct ImageHandler: ImageModifier { 18 @Binding var handler: UIImage? 19 20 func modify(_ image: UIImage) -> UIImage { 21 handler = image 22 return image 23 } 24 } 25 26 var body: some View { 27 28 KFAnimatedImage(url) 29 .imageContext(.pfp, disable_animation: settings.disable_animation) 30 .configure { view in 31 view.framePreloadCount = 3 32 } 33 .imageModifier(ImageHandler(handler: $image)) 34 .clipShape(Circle()) 35 .modifier(ImageContextMenuModifier(url: url, image: image, settings: settings, showShareSheet: $showShareSheet)) 36 .sheet(isPresented: $showShareSheet) { 37 ShareSheet(activityItems: [url]) 38 } 39 } 40 } 41 42 struct NavDismissBarView: View { 43 44 @Environment(\.presentationMode) var presentationMode 45 let showBackgroundCircle: Bool 46 47 init(showBackgroundCircle: Bool = true) { 48 self.showBackgroundCircle = showBackgroundCircle 49 } 50 51 var body: some View { 52 HStack { 53 Button(action: { 54 presentationMode.wrappedValue.dismiss() 55 }, label: { 56 if showBackgroundCircle { 57 Image("close") 58 .frame(width: 33, height: 33) 59 .background(.regularMaterial) 60 .clipShape(Circle()) 61 } 62 else { 63 Image("close") 64 .frame(width: 33, height: 33) 65 } 66 }) 67 68 Spacer() 69 } 70 .padding() 71 } 72 } 73 74 struct ProfilePicImageView: View { 75 let pubkey: Pubkey 76 let profiles: Profiles 77 let settings: UserSettingsStore 78 79 @Environment(\.presentationMode) var presentationMode 80 81 var body: some View { 82 ZStack { 83 Color(.systemBackground) 84 .ignoresSafeArea() 85 86 ZoomableScrollView { 87 ProfileImageContainerView(url: get_profile_url(picture: nil, pubkey: pubkey, profiles: profiles), settings: settings) 88 .aspectRatio(contentMode: .fit) 89 .padding(.top, Theme.safeAreaInsets?.top) 90 .padding(.bottom, Theme.safeAreaInsets?.bottom) 91 .padding(.horizontal) 92 } 93 .ignoresSafeArea() 94 .modifier(SwipeToDismissModifier(minDistance: 50, onDismiss: { 95 presentationMode.wrappedValue.dismiss() 96 })) 97 } 98 .overlay(NavDismissBarView(), alignment: .top) 99 } 100 } 101 102 struct ProfileZoomView_Previews: PreviewProvider { 103 static var previews: some View { 104 ProfilePicImageView( 105 pubkey: test_pubkey, 106 profiles: make_preview_profiles(test_pubkey), 107 settings: test_damus_state.settings 108 ) 109 } 110 }