metatext-app-ios-iphone-ipad/Shared/Views/AddIdentityView.swift

67 lines
1.6 KiB
Swift
Raw Normal View History

// Copyright © 2020 Metabolist. All rights reserved.
import SwiftUI
struct AddIdentityView: View {
@StateObject var viewModel: AddIdentityViewModel
2020-08-07 03:41:59 +02:00
@EnvironmentObject var rootViewModel: RootViewModel
var body: some View {
Form {
2020-08-03 17:20:51 +02:00
#if os(macOS)
2020-08-03 07:54:47 +02:00
Spacer()
2020-08-03 17:20:51 +02:00
urlTextField
#else
urlTextField
.autocapitalization(.none)
.disableAutocorrection(true)
.keyboardType(.URL)
#endif
Group {
if viewModel.loading {
ProgressView()
} else {
Button(
action: viewModel.goTapped,
label: { Text("go") })
}
}
.frame(maxWidth: .infinity, alignment: .center)
2020-08-03 17:20:51 +02:00
#if os(macOS)
2020-08-03 07:54:47 +02:00
Spacer()
2020-08-03 17:20:51 +02:00
#endif
}
2020-08-03 17:20:51 +02:00
.paddingIfMac()
.alertItem($viewModel.alertItem)
2020-08-07 03:41:59 +02:00
.onReceive(viewModel.addedIdentityID) { id in
withAnimation {
rootViewModel.newIdentitySelected(id: id)
}
}
}
}
extension AddIdentityView {
private var urlTextField: some View {
TextField("add-identity.instance-url", text: $viewModel.urlFieldText)
}
}
2020-08-03 17:20:51 +02:00
private extension View {
func paddingIfMac() -> some View {
#if os(macOS)
return padding()
#else
return self
#endif
}
}
2020-07-31 23:40:57 +02:00
#if DEBUG
struct AddAccountView_Previews: PreviewProvider {
static var previews: some View {
2020-08-03 17:20:51 +02:00
AddIdentityView(viewModel: AddIdentityViewModel(environment: .development))
}
}
2020-07-31 23:40:57 +02:00
#endif