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

Fix navbar on edit screen #1058

Merged
merged 8 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 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 Down Expand Up @@ -211,6 +212,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
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()
devinreams marked this conversation as resolved.
Show resolved Hide resolved
}

var deleteHidden: AnyObserver<Bool> {
return self.deleteButton.rx.isHidden.asObserver()
}
Expand Down
6 changes: 6 additions & 0 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