Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content title and button to Details view #60

Merged
merged 6 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Application/Source/Detail/View/DetailPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ extension DetailPresentingViewModel {
/// This action should be executed with a Bool indicating whether the presentation should be animated.
///
/// - Parameter factory: A factory to be used to generate the presented view model.
/// - Parameter setupViewModel: This closure will be called with the presenting view model when a present action
/// is executed. Consumers can use this to observe changes to the presenting view model if necessary.
/// - Parameter setupViewModel: This closure will be called with the presented view model when a present action
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this wording!

/// is executed. Consumers can use this to observe changes to the presented view model if necessary.
func makePresentDetail(
withFactory factory: DetailViewModelFactoryProtocol,
setupViewModel: ((DetailViewModel) -> Void)? = nil
Expand Down
15 changes: 15 additions & 0 deletions Application/Source/Detail/View/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,26 @@ class DetailView: UIView {
return label
}()

let contentsListTitle: UILabel = {
let label = UILabel()
label.textAlignment = .center
label.numberOfLines = 0
return label
}()

let contentsButton: UIButton = {
let button = UIButton()
button.setTitleColor(.blue, for: .normal)
return button
}()

private(set) lazy var stackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [
title,
button,
selectionResult,
contentsListTitle,
contentsButton
])
stackView.axis = .vertical
stackView.alignment = .center
Expand Down
7 changes: 7 additions & 0 deletions Application/Source/Detail/View/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ class DetailViewController: UIViewController, ViewController {
viewModel.selectionResult
.bind(to: detailView.selectionResult.rx.text)
.disposed(by: disposeBag)
viewModel.contentsListTitle
.bind(to: detailView.contentsListTitle.rx.text)
.disposed(by: disposeBag)
viewModel.contentsButtonTitle
.bind(to: detailView.contentsButton.rx.title())
.disposed(by: disposeBag)

detailView.button.rx.bind(to: viewModel.presentSelection, input: true)
detailView.contentsButton.rx.bind(to: viewModel.presentContents, input: ())

rx.isAppeared
.bind(to: viewModel.isActive)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ struct DetailViewControllerStyle: Style {

background.apply(to: view)
title.apply(to: view.title)
title.apply(to: view.contentsListTitle)
selectionResult.apply(to: view.selectionResult)
button.apply(to: view.button)
button.apply(to: view.contentsButton)

view.stackView.spacing = theme.layout.interitemSpacing
}
Expand Down
9 changes: 9 additions & 0 deletions Application/Source/Detail/View/DetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import RxSwift
import RxCocoa
import RxExtensions
import Presentations
import Action

class DetailViewModel: ViewModel, SelectionPresentingViewModel {

Expand All @@ -16,6 +17,14 @@ class DetailViewModel: ViewModel, SelectionPresentingViewModel {

let presentSelectionTitle = Property(L10n.Detail.Select.title)

let contentsListTitle = Property(L10n.Detail.ContentsList.title)
let contentsButtonTitle = Property(L10n.Detail.ContentsButton.title)

let presentContents = CocoaAction { _ in
print("Content button pressed")
return .empty()
}

private(set) lazy var presentSelection = makePresentSelection(
withFactory: selectionFactory,
defaultValue: { [weak self] in
Expand Down
2 changes: 1 addition & 1 deletion Application/Source/Home/View/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HomeViewModel: ViewModel, DetailPresentingViewModel {

let testTextInternalObserver = Observable<UInt>
// Add a delay to simulate a network operation.
.timer(RxTimeInterval(0.5), scheduler: backgroundScheduler)
.timer(RxTimeInterval(1.0), scheduler: backgroundScheduler)
.take(1)
.map { _ -> String? in
return L10n.Home.testText
Expand Down
4 changes: 2 additions & 2 deletions Application/Source/Home/View/HomeViewPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ extension HomePresentingViewModel {
/// This action should be executed with a Bool indicating whether the presentation should be animated.
///
/// - Parameter factory: A factory to be used to generate the presented view model.
/// - Parameter setupViewModel: This closure will be called with the presenting view model when a present action
/// is executed. Consumers can use this to observe changes to the presenting view model if necessary.
/// - Parameter setupViewModel: This closure will be called with the presented view model when a present action
/// is executed. Consumers can use this to observe changes to the presented view model if necessary.
func makePresentHome(
withFactory factory: HomeViewModelFactoryProtocol,
setupViewModel: ((HomeViewModel) -> Void)? = nil
Expand Down
4 changes: 2 additions & 2 deletions Application/Source/Selection/SelectionPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ extension SelectionPresentingViewModel {
///
/// - Parameter factory: A factory to be used to generate the presented view model.
/// - Parameter defaultValue: A closure that provides the default value of the selection input.
/// - Parameter setupViewModel: This closure will be called with the presenting view model when a present action
/// is executed. Consumers can use this to observe changes to the presenting view model if necessary.
/// - Parameter setupViewModel: This closure will be called with the presented view model when a present action
/// is executed. Consumers can use this to observe changes to the presented view model if necessary.
func makePresentSelection(
withFactory factory: SelectionViewModelFactoryProtocol,
defaultValue: (() -> String?)? = nil,
Expand Down
4 changes: 2 additions & 2 deletions Application/Source/Settings/View/SettingsPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ extension SettingsPresentingViewModel {
/// Makes an action that is suitable to be set as the presentSettings action.
///
/// - Parameter factory: A factory to be used to generate the presented view model.
/// - Parameter setupViewModel: This closure will be called with the presenting view model when a present action
/// is executed. Consumers can use this to observe changes to the presenting view model if necessary.
/// - Parameter setupViewModel: This closure will be called with the presented view model when a present action
/// is executed. Consumers can use this to observe changes to the presented view model if necessary.
func makePresentSettings(
withFactory factory: SettingsViewModelFactoryProtocol,
setupViewModel: ((SettingsViewModel) -> Void)? = nil
Expand Down
8 changes: 8 additions & 0 deletions Application/Source/SwiftGen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ internal enum L10n {
internal enum Detail {
/// Details
internal static let title = L10n.tr("Localizable", "detail.title")
internal enum ContentsButton {
/// Contents Info
internal static let title = L10n.tr("Localizable", "detail.contents_button.title")
}
internal enum ContentsList {
/// Contents
internal static let title = L10n.tr("Localizable", "detail.contents_list.title")
}
internal enum Select {
/// Select Text
internal static let title = L10n.tr("Localizable", "detail.select.title")
Expand Down
6 changes: 6 additions & 0 deletions Application/Supporting Files/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
/* The title of the tab bar item for the detail navigation flow. */
"detail_navigation.tab_bar_item.title" = "Detail";

/* Title for the contents list on the details view. */
"detail.contents_list.title" = "Contents";

/* Title for the contents button that presents the contents view. */
"detail.contents_button.title" = "Contents Info";

/* The title of the button that presents the detail view. */
"home.present_detail.title" = "Details";

Expand Down
2 changes: 1 addition & 1 deletion Application/Tests/HomeViewModelSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HomeViewModelSpec: QuickSpec {

viewModel.isActive.accept(true)

expect(viewModel.testText.value).toEventually(equal(L10n.Home.testText))
expect(viewModel.testText.value).toEventually(equal(L10n.Home.testText), timeout: 2.0)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Source/Themes/Themes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public extension Theme {

public var layout: Layout {
return Layout(
interitemSpacing: 10,
interitemSpacing: 20,
buttonContentEdgeInsets: UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 20),
buttonBorderWidth: 1,
buttonCornerRadius: 12,
Expand Down