SimpleX-Chat/apps/ios/Shared/Views/Chat/ChatItem/CIInvalidJSONView.swift
Evgeny 24b0f0290b
core: pass event and response error without dedicated constructor (#5869)
* core: pass event and response error without dedicated constructor

* ios: WIP

* android, desktop: update UI for new API

* ios: fix parser

* fix showing invalid chats

* fix mobile api tests

* ios: split ChatResponse to 3 enums, decode API results on the same thread

* tweak types

* remove throws

* rename
2025-05-05 11:51:22 +01:00

55 lines
1.4 KiB
Swift

//
// CIInvalidJSONView.swift
// SimpleX (iOS)
//
// Created by JRoberts on 29.12.2022.
// Copyright © 2022 SimpleX Chat. All rights reserved.
//
import SwiftUI
import SimpleXChat
struct CIInvalidJSONView: View {
@EnvironmentObject var theme: AppTheme
var json: Data?
@State private var showJSON = false
var body: some View {
HStack(alignment: .bottom, spacing: 0) {
Text("invalid data")
.foregroundColor(.red)
.italic()
}
.padding(.horizontal, 12)
.padding(.vertical, 6)
.background(Color(uiColor: .tertiarySystemGroupedBackground))
.textSelection(.disabled)
.onTapGesture { showJSON = true }
.appSheet(isPresented: $showJSON) {
invalidJSONView(dataToString(json))
}
}
}
func invalidJSONView(_ json: String) -> some View {
VStack(alignment: .leading, spacing: 16) {
Button {
showShareSheet(items: [json])
} label: {
Image(systemName: "square.and.arrow.up")
}
.frame(maxWidth: .infinity, alignment: .trailing)
ScrollView {
Text(json)
}
}
.frame(maxHeight: .infinity)
.padding()
.modifier(ThemedBackground())
}
struct CIInvalidJSONView_Previews: PreviewProvider {
static var previews: some View {
CIInvalidJSONView(json: "{}".data(using: .utf8)!)
}
}