Fix size of image container before we donload image from server

This commit is contained in:
Marcin Czachurski 2023-05-03 13:45:29 +02:00
parent d2f5867ac5
commit 96dff90608
3 changed files with 17 additions and 12 deletions

View File

@ -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
}

View File

@ -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;

View File

@ -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
}
}
}