Skip to content

Commit

Permalink
images: use user settings store
Browse files Browse the repository at this point in the history
  • Loading branch information
ericholguin committed Sep 21, 2023
1 parent 2280ef5 commit ca6a14d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion damus/Components/ImageCarousel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ struct ImageCarousel: View {
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.fullScreenCover(isPresented: $open_sheet) {
ImageView(video_controller: state.video, urls: urls, disable_animation: state.settings.disable_animation)
ImageView(video_controller: state.video, urls: urls, settings: state.settings)
}
.frame(height: height)
.onChange(of: selectedIndex) { value in
Expand Down
9 changes: 4 additions & 5 deletions damus/Views/Images/ImageContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import Kingfisher
struct ImageContainerView: View {
let video_controller: VideoController
let url: MediaUrl
let settings: UserSettingsStore

@State private var image: UIImage?
@State private var showShareSheet = false

let disable_animation: Bool

private struct ImageHandler: ImageModifier {
@Binding var handler: UIImage?

Expand All @@ -29,13 +28,13 @@ struct ImageContainerView: View {

func Img(url: URL) -> some View {
KFAnimatedImage(url)
.imageContext(.note, disable_animation: disable_animation)
.imageContext(.note, disable_animation: settings.disable_animation)
.configure { view in
view.framePreloadCount = 3
}
.imageModifier(ImageHandler(handler: $image))
.clipped()
.modifier(ImageContextMenuModifier(url: url, image: image, showShareSheet: $showShareSheet))
.modifier(ImageContextMenuModifier(url: url, image: image, settings: settings, showShareSheet: $showShareSheet))
.sheet(isPresented: $showShareSheet) {
ShareSheet(activityItems: [url])
}
Expand All @@ -57,6 +56,6 @@ let test_image_url = URL(string: "https://jb55.com/red-me.jpg")!

struct ImageContainerView_Previews: PreviewProvider {
static var previews: some View {
ImageContainerView(video_controller: test_damus_state().video, url: .image(test_image_url), disable_animation: false)
ImageContainerView(video_controller: test_damus_state().video, url: .image(test_image_url), settings: test_damus_state().settings)
}
}
6 changes: 3 additions & 3 deletions damus/Views/Images/ImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct ImageView: View {
@State private var selectedIndex = 0
@State var showMenu = true

let disable_animation: Bool
let settings: UserSettingsStore

var tabViewIndicator: some View {
HStack(spacing: 10) {
Expand All @@ -42,7 +42,7 @@ struct ImageView: View {
TabView(selection: $selectedIndex) {
ForEach(urls.indices, id: \.self) { index in
ZoomableScrollView {
ImageContainerView(video_controller: video_controller, url: urls[index], disable_animation: disable_animation)
ImageContainerView(video_controller: video_controller, url: urls[index], settings: settings)
.aspectRatio(contentMode: .fit)
.padding(.top, Theme.safeAreaInsets?.top)
.padding(.bottom, Theme.safeAreaInsets?.bottom)
Expand Down Expand Up @@ -85,6 +85,6 @@ struct ImageView: View {
struct ImageView_Previews: PreviewProvider {
static var previews: some View {
let url: MediaUrl = .image(URL(string: "https://jb55.com/red-me.jpg")!)
ImageView(video_controller: test_damus_state().video, urls: [url], disable_animation: false)
ImageView(video_controller: test_damus_state().video, urls: [url], settings: test_damus_state().settings)
}
}
13 changes: 6 additions & 7 deletions damus/Views/Images/ProfilePicImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import Kingfisher

struct ProfileImageContainerView: View {
let url: URL?
let settings: UserSettingsStore

@State private var image: UIImage?
@State private var showShareSheet = false

let disable_animation: Bool

private struct ImageHandler: ImageModifier {
@Binding var handler: UIImage?

Expand All @@ -27,13 +26,13 @@ struct ProfileImageContainerView: View {
var body: some View {

KFAnimatedImage(url)
.imageContext(.pfp, disable_animation: disable_animation)
.imageContext(.pfp, disable_animation: settings.disable_animation)
.configure { view in
view.framePreloadCount = 3
}
.imageModifier(ImageHandler(handler: $image))
.clipShape(Circle())
.modifier(ImageContextMenuModifier(url: url, image: image, showShareSheet: $showShareSheet))
.modifier(ImageContextMenuModifier(url: url, image: image, settings: settings, showShareSheet: $showShareSheet))
.sheet(isPresented: $showShareSheet) {
ShareSheet(activityItems: [url])
}
Expand Down Expand Up @@ -64,7 +63,7 @@ struct NavDismissBarView: View {
struct ProfilePicImageView: View {
let pubkey: Pubkey
let profiles: Profiles
let disable_animation: Bool
let settings: UserSettingsStore

@Environment(\.presentationMode) var presentationMode

Expand All @@ -74,7 +73,7 @@ struct ProfilePicImageView: View {
.ignoresSafeArea()

ZoomableScrollView {
ProfileImageContainerView(url: get_profile_url(picture: nil, pubkey: pubkey, profiles: profiles), disable_animation: disable_animation)
ProfileImageContainerView(url: get_profile_url(picture: nil, pubkey: pubkey, profiles: profiles), settings: settings)
.aspectRatio(contentMode: .fit)
.padding(.top, Theme.safeAreaInsets?.top)
.padding(.bottom, Theme.safeAreaInsets?.bottom)
Expand All @@ -94,7 +93,7 @@ struct ProfileZoomView_Previews: PreviewProvider {
ProfilePicImageView(
pubkey: test_pubkey,
profiles: make_preview_profiles(test_pubkey),
disable_animation: false
settings: test_damus_state().settings
)
}
}
2 changes: 1 addition & 1 deletion damus/Views/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ struct ProfileView: View {
is_zoomed.toggle()
}
.fullScreenCover(isPresented: $is_zoomed) {
ProfilePicImageView(pubkey: profile.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
ProfilePicImageView(pubkey: profile.pubkey, profiles: damus_state.profiles, settings: damus_state.settings)
}

Spacer()
Expand Down

0 comments on commit ca6a14d

Please sign in to comment.