Skip to content

Commit

Permalink
dismiss the container in cancel action
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisho committed Apr 22, 2018
1 parent 6cc62ee commit 5a0e7d2
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Papr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
DC658D95208CFDBA00FEBC31 /* PhotoCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DC658D91208CFDBA00FEBC31 /* PhotoCollectionViewCell.xib */; };
DC658D96208CFDBA00FEBC31 /* PhotoCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DC658D91208CFDBA00FEBC31 /* PhotoCollectionViewCell.xib */; };
DC658D97208CFDBA00FEBC31 /* PhotoCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DC658D91208CFDBA00FEBC31 /* PhotoCollectionViewCell.xib */; };
DC658D9A208CFE1700FEBC31 /* PhotoCollectionCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC658D99208CFE1700FEBC31 /* PhotoCollectionCellModel.swift */; };
DC658D9B208CFE1700FEBC31 /* PhotoCollectionCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC658D99208CFE1700FEBC31 /* PhotoCollectionCellModel.swift */; };
DC658D9C208CFE1700FEBC31 /* PhotoCollectionCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC658D99208CFE1700FEBC31 /* PhotoCollectionCellModel.swift */; };
DC66C92F2052BA0300831478 /* PhotoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC66C92E2052BA0300831478 /* PhotoViewModel.swift */; };
DC66C9302052BA0300831478 /* PhotoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC66C92E2052BA0300831478 /* PhotoViewModel.swift */; };
DC66C9312052BA0300831478 /* PhotoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC66C92E2052BA0300831478 /* PhotoViewModel.swift */; };
Expand Down Expand Up @@ -243,6 +246,7 @@
DC658D8B208CEF0300FEBC31 /* AddToCollectionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToCollectionViewModel.swift; sourceTree = "<group>"; };
DC658D90208CFDBA00FEBC31 /* PhotoCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoCollectionViewCell.swift; sourceTree = "<group>"; };
DC658D91208CFDBA00FEBC31 /* PhotoCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PhotoCollectionViewCell.xib; sourceTree = "<group>"; };
DC658D99208CFE1700FEBC31 /* PhotoCollectionCellModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoCollectionCellModel.swift; sourceTree = "<group>"; };
DC66C92E2052BA0300831478 /* PhotoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoViewModel.swift; sourceTree = "<group>"; };
DC6CC643204CBD5300050589 /* PhotoStatistics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoStatistics.swift; sourceTree = "<group>"; };
DC71C3011FBD9B7200C8E41A /* UnsplashAuthManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnsplashAuthManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -389,6 +393,7 @@
isa = PBXGroup;
children = (
DC658D90208CFDBA00FEBC31 /* PhotoCollectionViewCell.swift */,
DC658D99208CFE1700FEBC31 /* PhotoCollectionCellModel.swift */,
DC658D91208CFDBA00FEBC31 /* PhotoCollectionViewCell.xib */,
);
path = Cell;
Expand Down Expand Up @@ -984,6 +989,7 @@
DCBE008A202A1A980065BEF3 /* Date+Extentions.swift in Sources */,
DCAF6BBF204D465E002B7F00 /* Int+Extentions.swift in Sources */,
DCBB1B601FA8BA22004E95F0 /* LoginViewController.swift in Sources */,
DC658D9A208CFE1700FEBC31 /* PhotoCollectionCellModel.swift in Sources */,
DC66C92F2052BA0300831478 /* PhotoViewModel.swift in Sources */,
DCDDF32A2027DA5F00E1EB81 /* UIView+Extentions.swift in Sources */,
DC5AF7441FACEF2700ADA2BB /* Location.swift in Sources */,
Expand Down Expand Up @@ -1060,6 +1066,7 @@
DC71C3DC1FBF635C00C8E41A /* UnsplashAccessToken.swift in Sources */,
DCC8CA142002CC2700F6C540 /* HomeViewCell.swift in Sources */,
DC5AF7411FACE6A300ADA2BB /* Photo.swift in Sources */,
DC658D9B208CFE1700FEBC31 /* PhotoCollectionCellModel.swift in Sources */,
DCAF6BC0204D465E002B7F00 /* Int+Extentions.swift in Sources */,
DCBB1B371FA7B1BD004E95F0 /* PaprTests.swift in Sources */,
DC7F20941FADD3400017C14A /* SearchResults.swift in Sources */,
Expand Down Expand Up @@ -1141,6 +1148,7 @@
DCCCFCC7203A52410024D417 /* Resolution.swift in Sources */,
DCEE1F0D1FC97CDC0010BADE /* AlertViewController.swift in Sources */,
DCBE0090202A1EB30065BEF3 /* String+Extentions.swift in Sources */,
DC658D9C208CFE1700FEBC31 /* PhotoCollectionCellModel.swift in Sources */,
DC5AF7521FAD027F00ADA2BB /* PhotoCollection.swift in Sources */,
DCBB1B761FA8D597004E95F0 /* Unsplash.swift in Sources */,
DC5AF7291FAB989400ADA2BB /* UnsplashSettings.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Papr/Coodinator/SceneCoodinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SceneCoordinator: SceneCoordinatorType {
.rx
.delegate
.sentMessage(#selector(UINavigationControllerDelegate.navigationController(_:didShow:animated:)))
.map{_ in }
.map{ _ in }
.bind(to: subject)

navigationController.pushViewController(viewController, animated: true)
Expand Down
42 changes: 36 additions & 6 deletions Papr/Scenes/Add to collection/AddToCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

import UIKit
import RxSwift
import Action

class AddToCollectionViewController: UIViewController, BindableType {

Expand All @@ -19,17 +21,45 @@ class AddToCollectionViewController: UIViewController, BindableType {
@IBOutlet var cancelButton: UIButton!
@IBOutlet var transparentViewContainer: UIView!

// MARK: Private
private let disposeBag = DisposeBag()

override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
UIView.animate(withDuration: 0.5, animations: {
self.transparentViewContainer.backgroundColor = .black
self.transparentViewContainer.alpha = 0.2
})
}

showOverlayView()
configureCollectionView()
}

func bindViewModel() {
let inputs = viewModel.inputs
let outputs = viewModel.outputs

cancelButton.rx.controlEvent(.touchUpInside)
.subscribe(onNext: { [unowned self] in
UIView.animate(withDuration: 0.2, animations: {
self.transparentViewContainer.backgroundColor = .clear
})

DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
inputs.cancelAction.execute(())
}
})
.disposed(by: disposeBag)

}

private func configureCollectionView() {
collectionView.registerCell(type: PhotoCollectionViewCell.self)
}

private func showOverlayView() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
UIView.animate(withDuration: 0.2, animations: {
self.transparentViewContainer.backgroundColor = .black
self.transparentViewContainer.alpha = 0.2

})
}
}
}
44 changes: 42 additions & 2 deletions Papr/Scenes/Add to collection/AddToCollectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,47 @@
//

import Foundation
import RxSwift
import Action

protocol AddToCollectionViewModelInput {
/// Call when cancel button is pressed
var cancelAction: CocoaAction { get }
}

protocol AddToCollectionViewModelOutput {
/// Emites the child viewModels
var collectionCellModelTypes: Observable<[PhotoCollectionCellModelType]>! { get }
}

protocol AddToCollectionViewModelType {
var inputs: AddToCollectionViewModelInput { get }
var outputs: AddToCollectionViewModelOutput { get }
}

class AddToCollectionViewModel: AddToCollectionViewModelInput,
AddToCollectionViewModelOutput,
AddToCollectionViewModelType {

// MARK: Inputs & Outputs
var inputs: AddToCollectionViewModelInput { return self }
var outputs: AddToCollectionViewModelOutput { return self }

// MARK: Inputs
lazy var cancelAction: CocoaAction = {
CocoaAction { [unowned self] _ in
self.sceneCoordinator.pop(animated: true)
}
}()

// MARK: Outputs
var collectionCellModelTypes: Observable<[PhotoCollectionCellModelType]>!

// MARK: Private
private let sceneCoordinator: SceneCoordinatorType

init(sceneCoordinator: SceneCoordinatorType = SceneCoordinator.shared) {
self.sceneCoordinator = sceneCoordinator
}

struct AddToCollectionViewModel {

}
40 changes: 40 additions & 0 deletions Papr/Scenes/Add to collection/Cell/PhotoCollectionCellModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// PhotoCollectionCellModel.swift
// Papr
//
// Created by Joan Disho on 22.04.18.
// Copyright © 2018 Joan Disho. All rights reserved.
//

import Foundation
import RxSwift

protocol PhotoCollectionCellModelInput {

}

protocol PhotoCollectionCellModelOutput {

}


protocol PhotoCollectionCellModelType {
var inputs: PhotoCollectionCellModelInput { get }
var outputs: PhotoCollectionCellModelOutput { get }
}

class PhotoCollectionCellModel: PhotoCollectionCellModelInput,
PhotoCollectionCellModelOutput,
PhotoCollectionCellModelType {


// MARK: Inputs & Outputs
var inputs: PhotoCollectionCellModelInput { return self }
var outputs: PhotoCollectionCellModelOutput { return self }

// MARK: Inputs


// MARK: Outputs

}

0 comments on commit 5a0e7d2

Please sign in to comment.