From 689e13d03b8692b77b5480cf0014fa72168d6d2a Mon Sep 17 00:00:00 2001 From: Joe Gasiorek Date: Wed, 3 Jul 2019 09:14:27 -0700 Subject: [PATCH] Fix navbar on edit screen (#1058) --- lockbox-ios/Presenter/ItemDetailPresenter.swift | 12 +++++++++++- lockbox-ios/Store/AccountStore.swift | 2 +- lockbox-ios/View/ItemDetailCellConfiguration.swift | 1 - lockbox-ios/View/ItemDetailView.swift | 14 ++++++++++++-- .../ItemDetailCellConfigurationSpec.swift | 2 +- lockbox-iosTests/ItemDetailPresenterSpec.swift | 10 ++++++++-- lockbox-iosTests/ItemListViewSpec.swift | 6 +++--- 7 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lockbox-ios/Presenter/ItemDetailPresenter.swift b/lockbox-ios/Presenter/ItemDetailPresenter.swift index 094941e12..946c120f7 100644 --- a/lockbox-ios/Presenter/ItemDetailPresenter.swift +++ b/lockbox-ios/Presenter/ItemDetailPresenter.swift @@ -19,6 +19,7 @@ protocol ItemDetailViewProtocol: class, StatusAlertView, AlertControllerView { var titleText: AnyObserver { get } var rightButtonText: AnyObserver { get } var leftButtonText: AnyObserver { get } + var leftButtonIcon: AnyObserver { get } var deleteHidden: AnyObserver { get } } @@ -45,7 +46,6 @@ class ItemDetailPresenter { }.asObserver() }() - lazy private var discardChangesObserver: AnyObserver = { return Binder(self) { target, _ in target.dispatcher.dispatch(action: ItemDetailDisplayAction.viewMode) @@ -211,6 +211,16 @@ class ItemDetailPresenter { .subscribe(self.view!.leftButtonText) .disposed(by: self.disposeBag) + self.itemDetailStore.isEditing + .withLatestFrom(self.sizeClassStore.shouldDisplaySidebar) { (editing: Bool, sidebar: Bool) -> UIImage? in + if !editing && !sidebar { + return UIImage(named: "back") + } + return nil + } + .subscribe(self.view!.leftButtonIcon) + .disposed(by: self.disposeBag) + self.sizeClassStore.shouldDisplaySidebar .subscribe(onNext: { (enableSidebar) in self.view?.enableSwipeNavigation(enabled: !enableSidebar) diff --git a/lockbox-ios/Store/AccountStore.swift b/lockbox-ios/Store/AccountStore.swift index d3717c9a3..97705d554 100644 --- a/lockbox-ios/Store/AccountStore.swift +++ b/lockbox-ios/Store/AccountStore.swift @@ -51,7 +51,7 @@ class AccountStore: BaseAccountStore { } private var generatedLoginURL: Observable { - return Observable.create( { observer -> Disposable in + return Observable.create({ observer -> Disposable in self.fxa?.beginOAuthFlow(scopes: Constant.fxa.scopes, wantsKeys: true) { url, err in if let err = err { observer.onError(err) diff --git a/lockbox-ios/View/ItemDetailCellConfiguration.swift b/lockbox-ios/View/ItemDetailCellConfiguration.swift index 475c6860a..a575bdbab 100644 --- a/lockbox-ios/View/ItemDetailCellConfiguration.swift +++ b/lockbox-ios/View/ItemDetailCellConfiguration.swift @@ -4,7 +4,6 @@ import Foundation import UIKit -import UIKit import RxDataSources import RxSwift import RxCocoa diff --git a/lockbox-ios/View/ItemDetailView.swift b/lockbox-ios/View/ItemDetailView.swift index 641846d41..024cd7b41 100644 --- a/lockbox-ios/View/ItemDetailView.swift +++ b/lockbox-ios/View/ItemDetailView.swift @@ -79,8 +79,13 @@ extension ItemDetailView: ItemDetailViewProtocol { } var rightButtonText: AnyObserver { - // swiftlint:disable:next force_cast - return (self.navigationItem.rightBarButtonItem!.customView as! UIButton).rx.title().asObserver() + return AnyObserver { evt in + // swiftlint:disable:next force_cast + let button = (self.navigationItem.rightBarButtonItem!.customView as! UIButton) + button.setTitle(evt.element ?? "", for: UIControl.State.normal) + button.sizeToFit() + + } } var leftButtonText: AnyObserver { @@ -88,6 +93,11 @@ extension ItemDetailView: ItemDetailViewProtocol { return (self.navigationItem.leftBarButtonItem!.customView as! UIButton).rx.title().asObserver() } + var leftButtonIcon: AnyObserver { + // swiftlint:disable:next force_cast + return (self.navigationItem.leftBarButtonItem!.customView as! UIButton).rx.image().asObserver() + } + var deleteHidden: AnyObserver { return self.deleteButton.rx.isHidden.asObserver() } diff --git a/lockbox-iosTests/ItemDetailCellConfigurationSpec.swift b/lockbox-iosTests/ItemDetailCellConfigurationSpec.swift index 6193c50b4..d5a009f6c 100644 --- a/lockbox-iosTests/ItemDetailCellConfigurationSpec.swift +++ b/lockbox-iosTests/ItemDetailCellConfigurationSpec.swift @@ -70,4 +70,4 @@ class ItemDetailCellConfigurationSpec: QuickSpec { } } } -} \ No newline at end of file +} diff --git a/lockbox-iosTests/ItemDetailPresenterSpec.swift b/lockbox-iosTests/ItemDetailPresenterSpec.swift index 6bd542349..f880f1f4b 100644 --- a/lockbox-iosTests/ItemDetailPresenterSpec.swift +++ b/lockbox-iosTests/ItemDetailPresenterSpec.swift @@ -19,6 +19,7 @@ class ItemDetailPresenterSpec: QuickSpec { var rightButtonTextObserverStub: TestableObserver! var leftButtonTextObserverStub: TestableObserver! var deleteHiddenObserverStub: TestableObserver! + var leftButtonIconObserverStub: TestableObserver! let editStub = PublishSubject() let cellTappedStub = PublishSubject() let deleteTappedStub = PublishSubject() @@ -78,6 +79,10 @@ class ItemDetailPresenterSpec: QuickSpec { return self.deleteHiddenObserverStub.asObserver() } + var leftButtonIcon: AnyObserver { + return self.leftButtonIconObserverStub.asObserver() + } + func displayTemporaryAlert(_ message: String, timeout: TimeInterval, icon: UIImage?) { self.tempAlertMessage = message self.tempAlertTimeout = timeout @@ -175,6 +180,7 @@ class ItemDetailPresenterSpec: QuickSpec { self.view.rightButtonTextObserverStub = self.scheduler.createObserver(String?.self) self.view.leftButtonTextObserverStub = self.scheduler.createObserver(String?.self) self.view.deleteHiddenObserverStub = self.scheduler.createObserver(Bool.self) + self.view.leftButtonIconObserverStub = self.scheduler.createObserver(UIImage?.self) self.dispatcher = FakeDispatcher() self.dataStore = FakeDataStore() @@ -759,12 +765,12 @@ class ItemDetailPresenterSpec: QuickSpec { beforeEach { self.sizeClassStore.shouldDisplaySidebarStub.onNext(true) } - + it("enables swipe navigation") { expect(self.view.enableSwipeValue).to(beFalse()) } } - + describe("when not displaying sidebar") { beforeEach { self.sizeClassStore.shouldDisplaySidebarStub.onNext(false) diff --git a/lockbox-iosTests/ItemListViewSpec.swift b/lockbox-iosTests/ItemListViewSpec.swift index 811851f7c..823cac9cc 100644 --- a/lockbox-iosTests/ItemListViewSpec.swift +++ b/lockbox-iosTests/ItemListViewSpec.swift @@ -487,9 +487,9 @@ class ItemListViewSpec: QuickSpec { expect(LoginListCellConfiguration.SyncListPlaceholder.identity).to(equal("syncplaceholder")) let fakeObserver = self.scheduler.createObserver(Void.self).asObserver() expect(LoginListCellConfiguration.EmptyListPlaceholder(learnMoreObserver: fakeObserver).identity).to(equal("emptyplaceholder")) - expect(LoginListCellConfiguration.NoResults(learnMoreObserver: fakeObserver).identity).to(equal("noresultsplaceholder")) - expect(LoginListCellConfiguration.SelectAPasswordHelpText.identity).to(equal("selectapasswordhelptext")) - expect(LoginListCellConfiguration.NoNetwork(retryObserver: fakeObserver).identity).to(equal("nonetwork")) + expect(LoginListCellConfiguration.NoResults(learnMoreObserver: fakeObserver).identity).to(equal("noresultsplaceholder")) + expect(LoginListCellConfiguration.SelectAPasswordHelpText.identity).to(equal("selectapasswordhelptext")) + expect(LoginListCellConfiguration.NoNetwork(retryObserver: fakeObserver).identity).to(equal("nonetwork")) } }