diff --git a/ServicesKit/Sources/ServicesKit/ImageSizeService.swift b/ServicesKit/Sources/ServicesKit/ImageSizeService.swift index 3e5944d..7a06503 100644 --- a/ServicesKit/Sources/ServicesKit/ImageSizeService.swift +++ b/ServicesKit/Sources/ServicesKit/ImageSizeService.swift @@ -25,7 +25,7 @@ public class ImageSizeService { return calculate(for: url, width: Double(width), height: Double(height)) } - public func calculate(for url: URL, width: Double, height: Double) -> CGSize { + public func calculate(width: Double, height: Double) -> CGSize { let divider = Double(width) / UIScreen.main.bounds.size.width let calculatedHeight = Double(height) / divider @@ -34,6 +34,12 @@ public class ImageSizeService { height: (calculatedHeight > 0 && calculatedHeight < .infinity) ? calculatedHeight : UIScreen.main.bounds.width ) + return size + } + + public func calculate(for url: URL, width: Double, height: Double) -> CGSize { + let size = self.calculate(width: width, height: height) + self.memoryCacheData.insert(size, forKey: url) return size } diff --git a/Vernissage.xcodeproj/project.pbxproj b/Vernissage.xcodeproj/project.pbxproj index 1c57f74..0d69375 100644 --- a/Vernissage.xcodeproj/project.pbxproj +++ b/Vernissage.xcodeproj/project.pbxproj @@ -1316,7 +1316,7 @@ CODE_SIGN_ENTITLEMENTS = VernissageWidget/VernissageWidgetExtension.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 138; + CURRENT_PROJECT_VERSION = 139; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageWidget/Info.plist; @@ -1344,7 +1344,7 @@ ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground; CODE_SIGN_ENTITLEMENTS = VernissageWidget/VernissageWidgetExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 138; + CURRENT_PROJECT_VERSION = 139; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageWidget/Info.plist; @@ -1371,7 +1371,7 @@ CODE_SIGN_ENTITLEMENTS = VernissageShare/VernissageShareExtension.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 138; + CURRENT_PROJECT_VERSION = 139; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageShare/Info.plist; @@ -1398,7 +1398,7 @@ buildSettings = { CODE_SIGN_ENTITLEMENTS = VernissageShare/VernissageShareExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 138; + CURRENT_PROJECT_VERSION = 139; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageShare/Info.plist; @@ -1547,7 +1547,7 @@ CODE_SIGN_ENTITLEMENTS = Vernissage/Vernissage.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 138; + CURRENT_PROJECT_VERSION = 139; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES; @@ -1589,7 +1589,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CODE_SIGN_ENTITLEMENTS = Vernissage/Vernissage.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 138; + CURRENT_PROJECT_VERSION = 139; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES; diff --git a/Vernissage/Widgets/ImageRow.swift b/Vernissage/Widgets/ImageRow.swift index e422fd1..b39f774 100644 --- a/Vernissage/Widgets/ImageRow.swift +++ b/Vernissage/Widgets/ImageRow.swift @@ -73,13 +73,12 @@ struct ImageRow: View { } .onChange(of: selected, perform: { attachmentId in if let attachment = attachmentsData.first(where: { item in item.id == attachmentId }) { - let doubleImageWidth = Double(attachment.metaImageWidth) - let doubleImageHeight = Double(attachment.metaImageHeight) + let size = ImageSizeService.shared.calculate(width: Double(attachment.metaImageWidth), height: Double(attachment.metaImageHeight)) - if doubleImageWidth != self.imageWidth || doubleImageHeight != self.imageHeight { + if size.width != self.imageWidth || size.height != self.imageHeight { withAnimation(.linear(duration: 0.4)) { - self.imageWidth = doubleImageWidth - self.imageHeight = doubleImageHeight + self.imageWidth = size.width + self.imageHeight = size.height } } }