Change settings view and fix selected image on carousel.
This commit is contained in:
parent
1e482169ac
commit
0b30cfaf7f
|
@ -1106,7 +1106,7 @@
|
|||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 58;
|
||||
CURRENT_PROJECT_VERSION = 59;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = B2U9FEKYP8;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
|
@ -1143,7 +1143,7 @@
|
|||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 58;
|
||||
CURRENT_PROJECT_VERSION = 59;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = B2U9FEKYP8;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
|
|
|
@ -23,9 +23,13 @@ extension Status {
|
|||
func getAllImageMediaAttachments() -> [MediaAttachment] {
|
||||
if let reblog = self.reblog {
|
||||
// If status is rebloged the we have to check if orginal status contains image.
|
||||
return reblog.mediaAttachments.filter { mediaAttachment in mediaAttachment.type == .image }
|
||||
return reblog.mediaAttachments
|
||||
.sorted(by: { (lhs, rhs) in lhs.id < rhs.id })
|
||||
.filter { mediaAttachment in mediaAttachment.type == .image }
|
||||
}
|
||||
|
||||
return self.mediaAttachments.filter { mediaAttachment in mediaAttachment.type == .image }
|
||||
return self.mediaAttachments
|
||||
.sorted(by: { (lhs, rhs) in lhs.id < rhs.id })
|
||||
.filter { mediaAttachment in mediaAttachment.type == .image }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import Foundation
|
||||
import PixelfedKit
|
||||
|
||||
public class AttachmentModel: ObservableObject {
|
||||
public class AttachmentModel: ObservableObject, Identifiable {
|
||||
public let id: String
|
||||
public let type: MediaAttachment.MediaAttachmentType
|
||||
public let url: URL
|
||||
|
|
|
@ -16,17 +16,31 @@ struct MediaSettingsView: View {
|
|||
var body: some View {
|
||||
Section("Media settings") {
|
||||
|
||||
Toggle("Always show NSFW (sensitive)", isOn: $showSensitive)
|
||||
.onChange(of: showSensitive) { newValue in
|
||||
self.applicationState.showSensitive = newValue
|
||||
ApplicationSettingsHandler.shared.setShowSensitive(value: newValue)
|
||||
Toggle(isOn: $showSensitive) {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Always show NSFW")
|
||||
Text("Force show all NFSW (sensitive) media without warnings")
|
||||
.font(.footnote)
|
||||
.foregroundColor(.lightGrayColor)
|
||||
}
|
||||
}
|
||||
.onChange(of: showSensitive) { newValue in
|
||||
self.applicationState.showSensitive = newValue
|
||||
ApplicationSettingsHandler.shared.setShowSensitive(value: newValue)
|
||||
}
|
||||
|
||||
Toggle("Show photo description", isOn: $showPhotoDescription)
|
||||
.onChange(of: showPhotoDescription) { newValue in
|
||||
self.applicationState.showPhotoDescription = newValue
|
||||
ApplicationSettingsHandler.shared.setShowPhotoDescription(value: newValue)
|
||||
Toggle(isOn: $showPhotoDescription) {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Show alternative text")
|
||||
Text("Show alternative text if present on status details screen")
|
||||
.font(.footnote)
|
||||
.foregroundColor(.lightGrayColor)
|
||||
}
|
||||
}
|
||||
.onChange(of: showPhotoDescription) { newValue in
|
||||
self.applicationState.showPhotoDescription = newValue
|
||||
ApplicationSettingsHandler.shared.setShowPhotoDescription(value: newValue)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
let defaultSettings = ApplicationSettingsHandler.shared.getDefaultSettings()
|
||||
|
|
|
@ -18,7 +18,6 @@ struct SupportView: View {
|
|||
.font(.title)
|
||||
VStack(alignment: .leading) {
|
||||
Text(product.displayName)
|
||||
.font(.caption)
|
||||
Text(product.description)
|
||||
.font(.footnote)
|
||||
.foregroundColor(.lightGrayColor)
|
||||
|
|
|
@ -21,27 +21,23 @@ struct StatusView: View {
|
|||
@State var imageWidth: Int32?
|
||||
@State var imageHeight: Int32?
|
||||
|
||||
@State private var showImageViewer = false
|
||||
@State private var state: ViewState = .loading
|
||||
|
||||
@State private var statusViewModel: StatusModel?
|
||||
|
||||
@State private var selectedAttachmentId: String?
|
||||
@State private var selectedAttachmentModel: AttachmentModel?
|
||||
@State private var tappedAttachmentModel: AttachmentModel?
|
||||
@State private var exifCamera: String?
|
||||
@State private var exifExposure: String?
|
||||
@State private var exifCreatedDate: String?
|
||||
@State private var exifLens: String?
|
||||
@State private var description: String?
|
||||
|
||||
@State var image: Image?
|
||||
|
||||
|
||||
var body: some View {
|
||||
self.mainBody()
|
||||
.navigationTitle("Details")
|
||||
.fullScreenCover(isPresented: $showImageViewer, content: {
|
||||
if let statusViewModel = self.statusViewModel {
|
||||
ImagesViewer(statusViewModel: statusViewModel, selectedAttachmentId: selectedAttachmentId ?? String.empty())
|
||||
}
|
||||
.fullScreenCover(item: $tappedAttachmentModel, content: { attachmentModel in
|
||||
ImagesViewer(attachmentModel: attachmentModel)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -58,7 +54,7 @@ struct StatusView: View {
|
|||
ScrollView {
|
||||
VStack (alignment: .leading) {
|
||||
ImagesCarousel(attachments: statusViewModel.mediaAttachments,
|
||||
selectedAttachmentId: $selectedAttachmentId,
|
||||
selectedAttachment: $selectedAttachmentModel,
|
||||
exifCamera: $exifCamera,
|
||||
exifExposure: $exifExposure,
|
||||
exifCreatedDate: $exifCreatedDate,
|
||||
|
@ -66,12 +62,7 @@ struct StatusView: View {
|
|||
description: $description)
|
||||
.onTapGesture {
|
||||
withoutAnimation {
|
||||
if let attachment = self.statusViewModel?.mediaAttachments.first(where: { $0.id == self.selectedAttachmentId }),
|
||||
let data = attachment.data,
|
||||
let uiImage = UIImage(data: data) {
|
||||
self.image = Image(uiImage: uiImage)
|
||||
self.showImageViewer.toggle()
|
||||
}
|
||||
self.tappedAttachmentModel = self.selectedAttachmentModel
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,7 +164,6 @@ struct StatusView: View {
|
|||
}
|
||||
|
||||
self.statusViewModel = statusModel
|
||||
self.selectedAttachmentId = statusModel.mediaAttachments.first?.id ?? String.empty()
|
||||
|
||||
// If we have status in database then we can update data.
|
||||
// TODO: It seems that Pixelfed didn't support status edit, thus we don't need to update status.
|
||||
|
|
|
@ -14,7 +14,7 @@ struct ImagesCarousel: View {
|
|||
@State private var selected: String
|
||||
@State private var heightWasPrecalculated: Bool
|
||||
|
||||
@Binding public var selectedAttachmentId: String?
|
||||
@Binding public var selectedAttachment: AttachmentModel?
|
||||
@Binding public var exifCamera: String?
|
||||
@Binding public var exifExposure: String?
|
||||
@Binding public var exifCreatedDate: String?
|
||||
|
@ -22,14 +22,14 @@ struct ImagesCarousel: View {
|
|||
@Binding public var description: String?
|
||||
|
||||
init(attachments: [AttachmentModel],
|
||||
selectedAttachmentId: Binding<String?>,
|
||||
selectedAttachment: Binding<AttachmentModel?>,
|
||||
exifCamera: Binding<String?>,
|
||||
exifExposure: Binding<String?>,
|
||||
exifCreatedDate: Binding<String?>,
|
||||
exifLens: Binding<String?>,
|
||||
description: Binding<String?>
|
||||
) {
|
||||
_selectedAttachmentId = selectedAttachmentId
|
||||
_selectedAttachment = selectedAttachment
|
||||
_exifCamera = exifCamera
|
||||
_exifExposure = exifExposure
|
||||
_exifCreatedDate = exifCreatedDate
|
||||
|
@ -81,9 +81,8 @@ struct ImagesCarousel: View {
|
|||
.frame(height: self.imageHeight)
|
||||
.tabViewStyle(PageTabViewStyle())
|
||||
.onChange(of: selected, perform: { index in
|
||||
self.selectedAttachmentId = selected
|
||||
|
||||
if let attachment = attachments.first(where: { item in item.id == index }) {
|
||||
self.selectedAttachment = attachment
|
||||
self.exifCamera = attachment.exifCamera
|
||||
self.exifExposure = attachment.exifExposure
|
||||
self.exifCreatedDate = attachment.exifCreatedDate
|
||||
|
|
|
@ -8,9 +8,8 @@ import SwiftUI
|
|||
|
||||
struct ImagesViewer: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
private let statusViewModel: StatusModel
|
||||
private let selectedAttachmentId: String
|
||||
|
||||
private let attachmentModel: AttachmentModel
|
||||
private let image: Image
|
||||
private let closeDragDistance = UIScreen.main.bounds.height / 1.8
|
||||
private let imageHeight: Double
|
||||
|
@ -27,13 +26,10 @@ struct ImagesViewer: View {
|
|||
@State private var currentOffset = CGSize.zero
|
||||
@State private var accumulatedOffset = CGSize.zero
|
||||
|
||||
init(statusViewModel: StatusModel, selectedAttachmentId: String) {
|
||||
self.statusViewModel = statusViewModel
|
||||
self.selectedAttachmentId = selectedAttachmentId
|
||||
init(attachmentModel: AttachmentModel) {
|
||||
self.attachmentModel = attachmentModel
|
||||
|
||||
if let attachment = statusViewModel.mediaAttachments.first(where: { $0.id == selectedAttachmentId }),
|
||||
let data = attachment.data,
|
||||
let uiImage = UIImage(data: data) {
|
||||
if let data = attachmentModel.data, let uiImage = UIImage(data: data) {
|
||||
self.image = Image(uiImage: uiImage)
|
||||
self.imageHeight = uiImage.size.height
|
||||
self.imageWidth = uiImage.size.width
|
||||
|
@ -48,7 +44,7 @@ struct ImagesViewer: View {
|
|||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.tag(selectedAttachmentId)
|
||||
.tag(attachmentModel.id)
|
||||
.offset(currentOffset)
|
||||
.rotationEffect(rotationAngle)
|
||||
.scaleEffect(finalMagnification + currentMagnification)
|
||||
|
|
Loading…
Reference in New Issue