Work around SwiftUI on bugs on iPadOS so that we can add accounts on the iPad

This commit is contained in:
Maurice Parker 2019-09-11 20:50:03 -05:00
parent efcbdd642a
commit 31b506b85a
5 changed files with 64 additions and 99 deletions

View File

@ -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()

View File

@ -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)
} }
} }

View File

@ -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 {

View File

@ -17,11 +17,7 @@ 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 {
@ -54,12 +50,8 @@ struct SettingsFeedbinAccountView : View {
} }
} }
} }
.disabled(busy) // .disabled(busy) // Maybe someday we can do this, but right now it crashes on the iPad
.navigationBarTitle(Text(""), displayMode: .inline) .navigationBarTitle(Text(""), displayMode: .inline)
.navigationBarItems(leading:
Button(action: { self.dismiss() }) { Text("Cancel") }
)
}
} }
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

View File

@ -13,11 +13,7 @@ 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 {
@ -41,8 +37,6 @@ struct SettingsLocalAccountView : View {
} }
} }
.navigationBarTitle(Text(""), displayMode: .inline) .navigationBarTitle(Text(""), displayMode: .inline)
.navigationBarItems(leading: Button(action: { self.dismiss() }) { Text("Cancel") } )
}
} }
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