Remove duplicated code

This commit is contained in:
Marcin Czachurski 2023-05-05 14:59:06 +02:00
parent 96dff90608
commit 8d76cfdcd3
2 changed files with 4 additions and 12 deletions

View File

@ -240,18 +240,14 @@ struct StatusView: View {
}
if let imageHeight = self.imageHeight, let imageWidth = self.imageWidth, imageHeight > 0 && imageWidth > 0 {
return self.calculateHeight(width: Double(imageWidth), height: Double(imageHeight))
let calculatedSize = ImageSizeService.shared.calculate(width: Double(imageWidth), height: Double(imageHeight))
return calculatedSize.height
}
// If we don't have image height and width in metadata, we have to use some constant height.
return UIScreen.main.bounds.width * 0.75
}
private func calculateHeight(width: Double, height: Double) -> CGFloat {
let divider = width / UIScreen.main.bounds.size.width
return height / divider
}
private func getMainStatus(status: StatusModel) async throws -> StatusModel {
guard let inReplyToId = status.inReplyToId else {
return status

View File

@ -224,7 +224,8 @@ struct ImageViewer: View {
private func calculateStartingOffset() -> CGSize {
// Image size on the screen.
let imageOnScreenHeight = self.calculateHeight(width: self.imageWidth, height: self.imageHeight)
let calculatedSize = ImageSizeService.shared.calculate(width: self.imageWidth, height: self.imageHeight)
let imageOnScreenHeight = calculatedSize.height
// Calculate full space for image.
let safeAreaInsetsTop = UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 20.0
@ -254,9 +255,4 @@ struct ImageViewer: View {
return 88.0
}
}
private func calculateHeight(width: Double, height: Double) -> CGFloat {
let divider = width / UIScreen.main.bounds.size.width
return height / divider
}
}