Refactor disable_animation setting

Pass it down from the top instead of using a function which goes around
our settings store
This commit is contained in:
William Casarin
2023-04-22 12:08:24 -07:00
parent 084c86eb0e
commit 357e8adf86
21 changed files with 74 additions and 44 deletions

View File

@@ -125,7 +125,7 @@ struct EditMetadataView: View {
var TopSection: some View {
ZStack(alignment: .top) {
GeometryReader { geo in
BannerImageView(pubkey: damus_state.pubkey, profiles: damus_state.profiles)
BannerImageView(pubkey: damus_state.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
.aspectRatio(contentMode: .fill)
.frame(width: geo.size.width, height: BANNER_HEIGHT)
.clipped()

View File

@@ -35,7 +35,7 @@ struct MaybeAnonPfpView: View {
.frame(width: size, height: size)
} else {
NavigationLink(destination: ProfileView(damus_state: state, pubkey: pubkey)) {
ProfilePicView(pubkey: pubkey, size: size, highlight: .none, profiles: state.profiles)
ProfilePicView(pubkey: pubkey, size: size, highlight: .none, profiles: state.profiles, disable_animation: state.settings.disable_animation)
}
}
}

View File

@@ -53,13 +53,17 @@ struct EditProfilePictureView: View {
.overlay(Circle().stroke(highlight_color(highlight), lineWidth: pfp_line_width(highlight)))
.padding(2)
}
var disable_animation: Bool {
damus_state?.settings.disable_animation ?? false
}
var body: some View {
ZStack {
Color(uiColor: .systemBackground)
KFAnimatedImage(get_profile_url())
.imageContext(.pfp)
.imageContext(.pfp, disable_animation: disable_animation)
.cancelOnDisappear(true)
.configure { view in
view.framePreloadCount = 3
@@ -87,12 +91,12 @@ struct EditProfilePictureView: View {
}
struct InnerProfilePicView: View {
let url: URL?
let fallbackUrl: URL?
let pubkey: String
let size: CGFloat
let highlight: Highlight
let disable_animation: Bool
var PlaceholderColor: Color {
return id_to_color(pubkey)
@@ -111,7 +115,7 @@ struct InnerProfilePicView: View {
Color(uiColor: .systemBackground)
KFAnimatedImage(url)
.imageContext(.pfp)
.imageContext(.pfp, disable_animation: disable_animation)
.onFailure(fallbackUrl: fallbackUrl, cacheKey: url?.absoluteString)
.cancelOnDisappear(true)
.configure { view in
@@ -133,19 +137,21 @@ struct ProfilePicView: View {
let size: CGFloat
let highlight: Highlight
let profiles: Profiles
let disable_animation: Bool
@State var picture: String?
init (pubkey: String, size: CGFloat, highlight: Highlight, profiles: Profiles, picture: String? = nil) {
init (pubkey: String, size: CGFloat, highlight: Highlight, profiles: Profiles, disable_animation: Bool, picture: String? = nil) {
self.pubkey = pubkey
self.profiles = profiles
self.size = size
self.highlight = highlight
self._picture = State(initialValue: picture)
self.disable_animation = disable_animation
}
var body: some View {
InnerProfilePicView(url: get_profile_url(picture: picture, pubkey: pubkey, profiles: profiles), fallbackUrl: URL(string: robohash(pubkey)), pubkey: pubkey, size: size, highlight: highlight)
InnerProfilePicView(url: get_profile_url(picture: picture, pubkey: pubkey, profiles: profiles), fallbackUrl: URL(string: robohash(pubkey)), pubkey: pubkey, size: size, highlight: highlight, disable_animation: disable_animation)
.onReceive(handle_notify(.profile_updated)) { notif in
let updated = notif.object as! ProfileUpdate
@@ -185,7 +191,9 @@ struct ProfilePicView_Previews: PreviewProvider {
pubkey: pubkey,
size: 100,
highlight: .none,
profiles: make_preview_profiles(pubkey))
profiles: make_preview_profiles(pubkey),
disable_animation: false
)
}
}

View File

@@ -165,7 +165,7 @@ struct ProfileView: View {
return AnyView(
VStack(spacing: 0) {
ZStack {
BannerImageView(pubkey: profile.pubkey, profiles: damus_state.profiles)
BannerImageView(pubkey: profile.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
.aspectRatio(contentMode: .fill)
.frame(width: proxy.size.width, height: minY > 0 ? bannerHeight + minY : bannerHeight)
.clipped()
@@ -332,7 +332,7 @@ struct ProfileView: View {
func nameSection(profile_data: Profile?) -> some View {
return Group {
HStack(alignment: .center) {
ProfilePicView(pubkey: profile.pubkey, size: pfp_size, highlight: .custom(imageBorderColor(), 4.0), profiles: damus_state.profiles)
ProfilePicView(pubkey: profile.pubkey, size: pfp_size, highlight: .custom(imageBorderColor(), 4.0), profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
.padding(.top, -(pfp_size / 2.0))
.offset(y: pfpOffset())
.scaleEffect(pfpScale())
@@ -340,7 +340,8 @@ struct ProfileView: View {
is_zoomed.toggle()
}
.fullScreenCover(isPresented: $is_zoomed) {
ProfilePicImageView(pubkey: profile.pubkey, profiles: damus_state.profiles) }
ProfilePicImageView(pubkey: profile.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
}
Spacer()