Fix image blinking after touch.

This commit is contained in:
Marcin Czachursk 2023-01-08 15:43:55 +01:00
parent f10a32537c
commit 4c831a7f6a
5 changed files with 26 additions and 19 deletions

View File

@ -12,7 +12,7 @@ struct SignInView: View {
@State private var serverAddress: String = "" @State private var serverAddress: String = ""
var onSignInStateChenge: (_ applicationViewMode: ApplicationViewMode) -> Void? var onSignInStateChenge: ((_ applicationViewMode: ApplicationViewMode) -> Void)?
var body: some View { var body: some View {
VStack { VStack {
@ -32,7 +32,7 @@ struct SignInView: View {
try await AuthorizationService.shared.signIn(serverAddress: serverAddress, { accountData in try await AuthorizationService.shared.signIn(serverAddress: serverAddress, { accountData in
DispatchQueue.main.async { DispatchQueue.main.async {
self.applicationState.accountData = accountData self.applicationState.accountData = accountData
onSignInStateChenge(.mainView) onSignInStateChenge?(.mainView)
} }
}) })
} }
@ -47,6 +47,6 @@ struct SignInView: View {
struct SignInView_Previews: PreviewProvider { struct SignInView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
SignInView { applicationViewMode in } SignInView()
} }
} }

View File

@ -24,9 +24,11 @@ struct StatusView: View {
ScrollView { ScrollView {
if let statusData = self.statusData { if let statusData = self.statusData {
VStack (alignment: .leading) { VStack (alignment: .leading) {
ImagesCarousel(attachments: statusData.attachments()) { attachmentData in ImagesCarousel(attachments: statusData.attachments(),
self.setAttachment(attachmentData) exifCamera: $exifCamera,
} exifExposure: $exifExposure,
exifCreatedDate: $exifCreatedDate,
exifLens: $exifLens)
VStack(alignment: .leading) { VStack(alignment: .leading) {
NavigationLink(destination: UserProfileView( NavigationLink(destination: UserProfileView(

View File

@ -15,7 +15,7 @@ struct CommentsSection: View {
@State public var withDivider = true @State public var withDivider = true
@State private var context: Context? @State private var context: Context?
var onNewStatus: (_ context: Status) -> Void? var onNewStatus: ((_ context: Status) -> Void)?
private let contentWidth = Int(UIScreen.main.bounds.width) - 50 private let contentWidth = Int(UIScreen.main.bounds.width) - 50
@ -122,7 +122,7 @@ struct CommentsSection: View {
favourited: status.favourited, favourited: status.favourited,
favouritesCount: status.favouritesCount, favouritesCount: status.favouritesCount,
bookmarked: status.bookmarked) { bookmarked: status.bookmarked) {
onNewStatus(status) self.onNewStatus?(status)
} }
.foregroundColor(self.getInteractionRowTextColor()) .foregroundColor(self.getInteractionRowTextColor())
.padding(.horizontal, 16) .padding(.horizontal, 16)
@ -133,7 +133,7 @@ struct CommentsSection: View {
} }
CommentsSection(statusId: status.id, withDivider: false) { context in CommentsSection(statusId: status.id, withDivider: false) { context in
onNewStatus(context) self.onNewStatus?(context)
} }
} }
} }
@ -167,6 +167,6 @@ struct CommentsSection: View {
struct CommentsSection_Previews: PreviewProvider { struct CommentsSection_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
CommentsSection(statusId: "", withDivider: true) { context in } CommentsSection(statusId: "", withDivider: true)
} }
} }

View File

@ -11,10 +11,13 @@ struct ImagesCarousel: View {
@State private var height: Double = 0.0 @State private var height: Double = 0.0
@State private var selectedAttachmentId = "" @State private var selectedAttachmentId = ""
var onAttachmentChange: (_ attachmentData: AttachmentData) -> Void? @Binding public var exifCamera: String?
@Binding public var exifExposure: String?
@Binding public var exifCreatedDate: String?
@Binding public var exifLens: String?
var body: some View { var body: some View {
TabView(selection: $selectedAttachmentId) { TabView() {
ForEach(attachments, id: \.id) { attachment in ForEach(attachments, id: \.id) { attachment in
if let image = UIImage(data: attachment.data) { if let image = UIImage(data: attachment.data) {
Image(uiImage: image) Image(uiImage: image)
@ -28,7 +31,10 @@ struct ImagesCarousel: View {
.tabViewStyle(PageTabViewStyle()) .tabViewStyle(PageTabViewStyle())
.onChange(of: selectedAttachmentId, perform: { index in .onChange(of: selectedAttachmentId, perform: { index in
if let attachment = attachments.first(where: { item in item.id == index }) { if let attachment = attachments.first(where: { item in item.id == index }) {
onAttachmentChange(attachment) self.exifCamera = attachment.exifCamera
self.exifExposure = attachment.exifExposure
self.exifCreatedDate = attachment.exifCreatedDate
self.exifLens = attachment.exifLens
} }
}) })
.onAppear { .onAppear {
@ -57,8 +63,7 @@ struct ImagesCarousel: View {
struct ImagesCarousel_Previews: PreviewProvider { struct ImagesCarousel_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
ImagesCarousel(attachments: []) { attachmentData in ImagesCarousel(attachments: [], exifCamera: .constant(""), exifExposure: .constant(""), exifCreatedDate: .constant(""), exifLens: .constant(""))
// ImagesCarousel(attachments: [])
}
} }
} }

View File

@ -16,13 +16,13 @@ struct InteractionRow: View {
@State var favouritesCount = 0 @State var favouritesCount = 0
@State var bookmarked = false @State var bookmarked = false
var onNewStatus: () -> Void? var onNewStatus: (() -> Void)?
var body: some View { var body: some View {
HStack (alignment: .top) { HStack (alignment: .top) {
Button { Button {
HapticService.shared.touch() HapticService.shared.touch()
onNewStatus() onNewStatus?()
} label: { } label: {
HStack(alignment: .center) { HStack(alignment: .center) {
Image(systemName: "message") Image(systemName: "message")
@ -127,7 +127,7 @@ struct InteractionRow: View {
struct InteractionRow_Previews: PreviewProvider { struct InteractionRow_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
InteractionRow() { } InteractionRow()
.previewLayout(.fixed(width: 300, height: 70)) .previewLayout(.fixed(width: 300, height: 70))
} }
} }