Add back local profile for tvOS
This commit is contained in:
@@ -6,11 +6,13 @@
|
||||
/// Using UIButton via UIViewRepresentable bypasses this issue.
|
||||
struct TVToolbarButton: UIViewRepresentable {
|
||||
let title: String
|
||||
var isEnabled: Bool = true
|
||||
let action: () -> Void
|
||||
|
||||
func makeUIView(context: Context) -> UIButton {
|
||||
let button = UIButton(type: .system)
|
||||
button.setTitle(title, for: .normal)
|
||||
button.isEnabled = isEnabled
|
||||
button.setContentHuggingPriority(.required, for: .horizontal)
|
||||
button.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
button.addTarget(context.coordinator, action: #selector(Coordinator.buttonTapped), for: .primaryActionTriggered)
|
||||
@@ -19,6 +21,7 @@
|
||||
|
||||
func updateUIView(_ uiView: UIButton, context: Context) {
|
||||
uiView.setTitle(title, for: .normal)
|
||||
uiView.isEnabled = isEnabled
|
||||
uiView.invalidateIntrinsicContentSize()
|
||||
uiView.sizeToFit()
|
||||
context.coordinator.action = action
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#if os(iOS) || os(macOS)
|
||||
import Foundation
|
||||
import Library
|
||||
import SwiftUI
|
||||
import Foundation
|
||||
import Library
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public struct EditProfileContentView: View {
|
||||
@MainActor
|
||||
public struct EditProfileContentView: View {
|
||||
public struct Context: Codable, Hashable {
|
||||
public let profileID: Int64
|
||||
public let readOnly: Bool
|
||||
@@ -76,6 +75,18 @@
|
||||
}
|
||||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#elseif os(tvOS)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
if !readOnly {
|
||||
TVToolbarButton(title: String(localized: "Save"), isEnabled: viewModel.isChanged) {
|
||||
Task {
|
||||
await viewModel.saveContent()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -104,6 +115,15 @@
|
||||
|
||||
@ViewBuilder
|
||||
private var defaultEditorView: some View {
|
||||
#if os(tvOS)
|
||||
ScrollView {
|
||||
TextField("", text: readOnly ? .constant(viewModel.profileContent) : $viewModel.profileContent, axis: .vertical)
|
||||
.lineLimit(1000)
|
||||
.font(Font.system(.caption2, design: .monospaced))
|
||||
.autocorrectionDisabled(true)
|
||||
.disabled(readOnly)
|
||||
}
|
||||
#else
|
||||
Group {
|
||||
if readOnly {
|
||||
TextEditor(text: .constant(viewModel.profileContent))
|
||||
@@ -117,7 +137,6 @@
|
||||
.textContentType(.init(rawValue: ""))
|
||||
.padding()
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#if os(iOS) || os(macOS)
|
||||
import Foundation
|
||||
import Library
|
||||
import SwiftUI
|
||||
import Foundation
|
||||
import Library
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public final class EditProfileContentViewModel: BaseViewModel {
|
||||
@MainActor
|
||||
public final class EditProfileContentViewModel: BaseViewModel {
|
||||
@Published public var profile: Profile?
|
||||
@Published public var profileContent = ""
|
||||
@Published public var isChanged = false
|
||||
@@ -69,6 +68,4 @@
|
||||
let profileContent = await profileContent
|
||||
try profile.write(profileContent)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ public struct NewProfileView: View {
|
||||
.multilineTextAlignment(.trailing)
|
||||
}
|
||||
Picker(selection: $viewModel.profileType) {
|
||||
#if !os(tvOS)
|
||||
Text("Local").tag(ProfileType.local)
|
||||
#if !os(tvOS)
|
||||
Text("iCloud").tag(ProfileType.icloud)
|
||||
#endif
|
||||
Text("Remote").tag(ProfileType.remote)
|
||||
@@ -190,6 +190,11 @@ public struct NewProfileView: View {
|
||||
.navigationTitle("New Profile")
|
||||
.disabled(viewModel.isSaving)
|
||||
.alert($viewModel.alert)
|
||||
.onChangeCompat(of: viewModel.createSucceeded) { newValue in
|
||||
if newValue {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
#if os(iOS)
|
||||
.fileImporter(
|
||||
isPresented: $viewModel.pickerPresented,
|
||||
|
||||
@@ -6,6 +6,7 @@ import SwiftUI
|
||||
@MainActor
|
||||
public final class NewProfileViewModel: BaseViewModel {
|
||||
@Published public var isSaving = false
|
||||
@Published public var createSucceeded = false
|
||||
@Published public var profileName = ""
|
||||
#if !os(tvOS)
|
||||
@Published public var profileType = ProfileType.local
|
||||
@@ -81,6 +82,7 @@ public final class NewProfileViewModel: BaseViewModel {
|
||||
if sendUpdateNotification {
|
||||
environments.profileUpdate.send()
|
||||
}
|
||||
createSucceeded = true
|
||||
dismiss?()
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
@@ -18,16 +18,14 @@ public struct ProfileActionToolbar: View {
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
#if os(iOS)
|
||||
#if os(iOS) || os(tvOS)
|
||||
iosBody
|
||||
#elseif os(tvOS)
|
||||
tvOSBody
|
||||
#elseif os(macOS)
|
||||
macOSBody
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
#if os(iOS) || os(tvOS)
|
||||
private var iosBody: some View {
|
||||
Section("Action") {
|
||||
if profile.type != .remote {
|
||||
@@ -49,12 +47,6 @@ public struct ProfileActionToolbar: View {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(tvOS)
|
||||
private var tvOSBody: some View {
|
||||
EmptyView()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
private var macOSBody: some View {
|
||||
VStack(spacing: 0) {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
#if os(iOS) || os(macOS)
|
||||
import SwiftUI
|
||||
import SwiftUI
|
||||
|
||||
public struct ProfileEditorKey: EnvironmentKey {
|
||||
public struct ProfileEditorKey: EnvironmentKey {
|
||||
public static let defaultValue: ((Binding<String>, Bool) -> AnyView)? = nil
|
||||
}
|
||||
}
|
||||
|
||||
public extension EnvironmentValues {
|
||||
public extension EnvironmentValues {
|
||||
var profileEditor: ((Binding<String>, Bool) -> AnyView)? {
|
||||
get { self[ProfileEditorKey.self] }
|
||||
set { self[ProfileEditorKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user