Work around SwiftUI on bugs on iPadOS so that we can add accounts on the iPad
This commit is contained in:
parent
efcbdd642a
commit
31b506b85a
@ -495,7 +495,6 @@ private extension MasterTimelineViewController {
|
|||||||
var snapshot = NSDiffableDataSourceSnapshot<Int, Article>()
|
var snapshot = NSDiffableDataSourceSnapshot<Int, Article>()
|
||||||
snapshot.appendSections([0])
|
snapshot.appendSections([0])
|
||||||
snapshot.appendItems(coordinator.articles, toSection: 0)
|
snapshot.appendItems(coordinator.articles, toSection: 0)
|
||||||
print("********* article count: \(coordinator.articles.count)")
|
|
||||||
|
|
||||||
dataSource.apply(snapshot, animatingDifferences: animate) { [weak self] in
|
dataSource.apply(snapshot, animatingDifferences: animate) { [weak self] in
|
||||||
self?.restoreSelectionIfNecessary()
|
self?.restoreSelectionIfNecessary()
|
||||||
|
@ -11,34 +11,16 @@ import Account
|
|||||||
|
|
||||||
struct SettingsAddAccountView : View {
|
struct SettingsAddAccountView : View {
|
||||||
@Environment(\.presentationMode) var presentation
|
@Environment(\.presentationMode) var presentation
|
||||||
@State private var selectedAccountType: AccountType = nil
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
|
NavigationLink(destination: SettingsLocalAccountView(name: "")) {
|
||||||
Button(action: {
|
|
||||||
self.selectedAccountType = AccountType.onMyMac
|
|
||||||
}) {
|
|
||||||
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: Account.defaultLocalAccountName)
|
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: Account.defaultLocalAccountName)
|
||||||
}
|
}
|
||||||
|
NavigationLink(destination: SettingsFeedbinAccountView(viewModel: SettingsFeedbinAccountView.ViewModel())) {
|
||||||
Button(action: {
|
|
||||||
self.selectedAccountType = AccountType.feedbin
|
|
||||||
}) {
|
|
||||||
SettingsAccountLabelView(accountImage: "accountFeedbin", accountLabel: "Feedbin")
|
SettingsAccountLabelView(accountImage: "accountFeedbin", accountLabel: "Feedbin")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
.sheet(item: $selectedAccountType) { accountType in
|
|
||||||
if accountType == .onMyMac {
|
|
||||||
SettingsLocalAccountView(name: "", onDismiss: { self.presentation.wrappedValue.dismiss() })
|
|
||||||
}
|
|
||||||
if accountType == .feedbin {
|
|
||||||
SettingsFeedbinAccountView(viewModel: SettingsFeedbinAccountView.ViewModel(), onDismiss: { self.presentation.wrappedValue.dismiss() })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.navigationBarTitle(Text("Add Account"), displayMode: .inline)
|
.navigationBarTitle(Text("Add Account"), displayMode: .inline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ struct SettingsDetailAccountView : View {
|
|||||||
|
|
||||||
var settingsFeedbinAccountView: SettingsFeedbinAccountView {
|
var settingsFeedbinAccountView: SettingsFeedbinAccountView {
|
||||||
let feedbinViewModel = SettingsFeedbinAccountView.ViewModel(account: viewModel.account)
|
let feedbinViewModel = SettingsFeedbinAccountView.ViewModel(account: viewModel.account)
|
||||||
return SettingsFeedbinAccountView(viewModel: feedbinViewModel, onDismiss: {})
|
return SettingsFeedbinAccountView(viewModel: feedbinViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewModel: ObservableObject {
|
class ViewModel: ObservableObject {
|
||||||
|
@ -17,49 +17,41 @@ struct SettingsFeedbinAccountView : View {
|
|||||||
@State var busy: Bool = false
|
@State var busy: Bool = false
|
||||||
@State var error: String = ""
|
@State var error: String = ""
|
||||||
|
|
||||||
// This is a hack around the fact that onDismiss isn't being called by the sheet modifier.
|
|
||||||
var onDismiss: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
Form {
|
||||||
Form {
|
Section(header:
|
||||||
Section(header:
|
HStack {
|
||||||
HStack {
|
Spacer()
|
||||||
Spacer()
|
SettingsAccountLabelView(accountImage: "accountFeedbin", accountLabel: "Feedbin").padding()
|
||||||
SettingsAccountLabelView(accountImage: "accountFeedbin", accountLabel: "Feedbin").padding()
|
Spacer()
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
TextField("Email", text: $viewModel.email).textContentType(.emailAddress)
|
|
||||||
SecureField("Password", text: $viewModel.password)
|
|
||||||
}
|
}
|
||||||
Section(footer:
|
) {
|
||||||
HStack {
|
TextField("Email", text: $viewModel.email).textContentType(.emailAddress)
|
||||||
Spacer()
|
SecureField("Password", text: $viewModel.password)
|
||||||
Text(verbatim: error).foregroundColor(.red)
|
}
|
||||||
Spacer()
|
Section(footer:
|
||||||
}
|
HStack {
|
||||||
) {
|
Spacer()
|
||||||
HStack {
|
Text(verbatim: error).foregroundColor(.red)
|
||||||
Spacer()
|
Spacer()
|
||||||
Button(action: { self.addAccount() }) {
|
}
|
||||||
if viewModel.isUpdate {
|
) {
|
||||||
Text("Update Account")
|
HStack {
|
||||||
} else {
|
Spacer()
|
||||||
Text("Add Account")
|
Button(action: { self.addAccount() }) {
|
||||||
}
|
if viewModel.isUpdate {
|
||||||
|
Text("Update Account")
|
||||||
|
} else {
|
||||||
|
Text("Add Account")
|
||||||
}
|
}
|
||||||
.disabled(!viewModel.isValid)
|
|
||||||
Spacer()
|
|
||||||
}
|
}
|
||||||
|
.disabled(!viewModel.isValid)
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.disabled(busy)
|
|
||||||
.navigationBarTitle(Text(""), displayMode: .inline)
|
|
||||||
.navigationBarItems(leading:
|
|
||||||
Button(action: { self.dismiss() }) { Text("Cancel") }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
// .disabled(busy) // Maybe someday we can do this, but right now it crashes on the iPad
|
||||||
|
.navigationBarTitle(Text(""), displayMode: .inline)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func addAccount() {
|
private func addAccount() {
|
||||||
@ -119,7 +111,6 @@ struct SettingsFeedbinAccountView : View {
|
|||||||
|
|
||||||
private func dismiss() {
|
private func dismiss() {
|
||||||
presentation.wrappedValue.dismiss()
|
presentation.wrappedValue.dismiss()
|
||||||
onDismiss()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewModel: ObservableObject {
|
class ViewModel: ObservableObject {
|
||||||
@ -164,7 +155,7 @@ struct SettingsFeedbinAccountView : View {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
struct SettingsFeedbinAccountView_Previews : PreviewProvider {
|
struct SettingsFeedbinAccountView_Previews : PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SettingsFeedbinAccountView(viewModel: SettingsFeedbinAccountView.ViewModel(), onDismiss: {})
|
SettingsFeedbinAccountView(viewModel: SettingsFeedbinAccountView.ViewModel())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,36 +13,30 @@ struct SettingsLocalAccountView : View {
|
|||||||
@Environment(\.presentationMode) var presentation
|
@Environment(\.presentationMode) var presentation
|
||||||
@State var name: String
|
@State var name: String
|
||||||
|
|
||||||
// This is a hack around the fact that onDismiss isn't being called by the sheet modifier.
|
|
||||||
var onDismiss: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
Form {
|
||||||
Form {
|
Section(header:
|
||||||
Section(header:
|
HStack {
|
||||||
HStack {
|
Spacer()
|
||||||
Spacer()
|
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: Account.defaultLocalAccountName).padding()
|
||||||
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: Account.defaultLocalAccountName).padding()
|
Spacer()
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
HStack {
|
|
||||||
TextField("Name", text: $name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Section {
|
) {
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
TextField("Name", text: $name)
|
||||||
Button(action: { self.addAccount() }) {
|
}
|
||||||
Text("Add Account")
|
}
|
||||||
}
|
Section {
|
||||||
Spacer()
|
HStack {
|
||||||
}
|
Spacer()
|
||||||
|
Button(action: { self.addAccount() }) {
|
||||||
|
Text("Add Account")
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationBarTitle(Text(""), displayMode: .inline)
|
|
||||||
.navigationBarItems(leading: Button(action: { self.dismiss() }) { Text("Cancel") } )
|
|
||||||
}
|
}
|
||||||
|
.navigationBarTitle(Text(""), displayMode: .inline)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func addAccount() {
|
private func addAccount() {
|
||||||
@ -53,7 +47,6 @@ struct SettingsLocalAccountView : View {
|
|||||||
|
|
||||||
private func dismiss() {
|
private func dismiss() {
|
||||||
presentation.wrappedValue.dismiss()
|
presentation.wrappedValue.dismiss()
|
||||||
onDismiss()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -61,7 +54,7 @@ struct SettingsLocalAccountView : View {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
struct SettingsLocalAccountView_Previews : PreviewProvider {
|
struct SettingsLocalAccountView_Previews : PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SettingsLocalAccountView(name: "", onDismiss: {})
|
SettingsLocalAccountView(name: "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user