Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Fix navbar on edit screen (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyg authored and devinreams committed Jul 3, 2019
1 parent a0c7fa6 commit 689e13d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
12 changes: 11 additions & 1 deletion lockbox-ios/Presenter/ItemDetailPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protocol ItemDetailViewProtocol: class, StatusAlertView, AlertControllerView {
var titleText: AnyObserver<String?> { get }
var rightButtonText: AnyObserver<String?> { get }
var leftButtonText: AnyObserver<String?> { get }
var leftButtonIcon: AnyObserver<UIImage?> { get }
var deleteHidden: AnyObserver<Bool> { get }
}

Expand All @@ -45,7 +46,6 @@ class ItemDetailPresenter {
}.asObserver()
}()


lazy private var discardChangesObserver: AnyObserver<Void> = {
return Binder(self) { target, _ in
target.dispatcher.dispatch(action: ItemDetailDisplayAction.viewMode)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lockbox-ios/Store/AccountStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AccountStore: BaseAccountStore {
}

private var generatedLoginURL: Observable<URL> {
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)
Expand Down
1 change: 0 additions & 1 deletion lockbox-ios/View/ItemDetailCellConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import Foundation
import UIKit
import UIKit
import RxDataSources
import RxSwift
import RxCocoa
Expand Down
14 changes: 12 additions & 2 deletions lockbox-ios/View/ItemDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,25 @@ extension ItemDetailView: ItemDetailViewProtocol {
}

var rightButtonText: AnyObserver<String?> {
// swiftlint:disable:next force_cast
return (self.navigationItem.rightBarButtonItem!.customView as! UIButton).rx.title().asObserver()
return AnyObserver<String?> { 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<String?> {
// swiftlint:disable:next force_cast
return (self.navigationItem.leftBarButtonItem!.customView as! UIButton).rx.title().asObserver()
}

var leftButtonIcon: AnyObserver<UIImage?> {
// swiftlint:disable:next force_cast
return (self.navigationItem.leftBarButtonItem!.customView as! UIButton).rx.image().asObserver()
}

var deleteHidden: AnyObserver<Bool> {
return self.deleteButton.rx.isHidden.asObserver()
}
Expand Down
2 changes: 1 addition & 1 deletion lockbox-iosTests/ItemDetailCellConfigurationSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ class ItemDetailCellConfigurationSpec: QuickSpec {
}
}
}
}
}
10 changes: 8 additions & 2 deletions lockbox-iosTests/ItemDetailPresenterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ItemDetailPresenterSpec: QuickSpec {
var rightButtonTextObserverStub: TestableObserver<String?>!
var leftButtonTextObserverStub: TestableObserver<String?>!
var deleteHiddenObserverStub: TestableObserver<Bool>!
var leftButtonIconObserverStub: TestableObserver<UIImage?>!
let editStub = PublishSubject<Void>()
let cellTappedStub = PublishSubject<String?>()
let deleteTappedStub = PublishSubject<Void>()
Expand Down Expand Up @@ -78,6 +79,10 @@ class ItemDetailPresenterSpec: QuickSpec {
return self.deleteHiddenObserverStub.asObserver()
}

var leftButtonIcon: AnyObserver<UIImage?> {
return self.leftButtonIconObserverStub.asObserver()
}

func displayTemporaryAlert(_ message: String, timeout: TimeInterval, icon: UIImage?) {
self.tempAlertMessage = message
self.tempAlertTimeout = timeout
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lockbox-iosTests/ItemListViewSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}

Expand Down

0 comments on commit 689e13d

Please sign in to comment.