-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from marty-suzuki/use-prex
Use prex
- Loading branch information
Showing
19 changed files
with
729 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "Carthage/Checkouts/Prex"] | ||
path = Carthage/Checkouts/Prex | ||
url = https://github.com/marty-suzuki/Prex.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// ARPresenter.swift | ||
// ArtShredder | ||
// | ||
// Created by marty-suzuki on 2018/10/19. | ||
// Copyright © 2018年 marty-suzuki. All rights reserved. | ||
// | ||
|
||
import Prex | ||
import UIKit | ||
|
||
final class ARPresenter: Presenter<AR.Action, AR.State> { | ||
|
||
var shredderNode: ARShredderNode? { | ||
return state.shredderNode | ||
} | ||
|
||
convenience init<T: View>(view: T) where T.State == AR.State { | ||
self.init(view: view, state: AR.State(), mutation: AR.Mutation()) | ||
} | ||
|
||
func setShredderNode(_ node: ARShredderNode) { | ||
dispatch(.setIsImageSelectHidden(false)) | ||
dispatch(.setIsAlphaViewHidden(true)) | ||
dispatch(.setShredderNode(node)) | ||
node.animationFinished = { [weak self] in | ||
self?.dispatch(.setIsImageSelectHidden(false)) | ||
} | ||
} | ||
|
||
func setImage(_ image: UIImage?) { | ||
if let image = image { | ||
dispatch(.setIsImageSelectHidden(true)) | ||
dispatch(.setImage(image)) | ||
} | ||
} | ||
|
||
func startAnimation() { | ||
dispatch(.startAnimation) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// ARPrexComponent.swift | ||
// ArtShredder | ||
// | ||
// Created by marty-suzuki on 2018/10/19. | ||
// Copyright © 2018年 marty-suzuki. All rights reserved. | ||
// | ||
|
||
import Prex | ||
import UIKit | ||
|
||
enum AR { | ||
enum Action: Prex.Action { | ||
case setShredderNode(ARShredderNode?) | ||
case setImage(UIImage) | ||
case startAnimation | ||
case setIsImageSelectHidden(Bool) | ||
case setIsAlphaViewHidden(Bool) | ||
} | ||
|
||
struct State: Prex.State { | ||
fileprivate(set) weak var shredderNode: ARShredderNode? | ||
fileprivate(set) var isImageSelectHidden = true | ||
fileprivate(set) var isAlphaViewHidden = false | ||
} | ||
|
||
struct Mutation: Prex.Mutation { | ||
func mutate(action: Action, state: inout State) { | ||
switch action { | ||
case let .setShredderNode(node): | ||
state.shredderNode = node | ||
|
||
case let .setImage(image): | ||
state.shredderNode?.setImage(image) | ||
|
||
case .startAnimation: | ||
state.shredderNode?.startAnimation() | ||
|
||
case let .setIsImageSelectHidden(isHidden): | ||
state.isImageSelectHidden = isHidden | ||
|
||
case let .setIsAlphaViewHidden(isHidden): | ||
state.isAlphaViewHidden = isHidden | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.