Skip to content

Commit

Permalink
Merge pull request #1 from marty-suzuki/use-prex
Browse files Browse the repository at this point in the history
Use prex
  • Loading branch information
marty-suzuki committed Oct 26, 2018
2 parents 6897fd2 + d2ce307 commit dcf1b07
Show file tree
Hide file tree
Showing 19 changed files with 729 additions and 310 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
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
43 changes: 43 additions & 0 deletions ArtShredder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
3715DEA22178FF0400885E84 /* Prex.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3715DEA12178FF0400885E84 /* Prex.framework */; };
3715DEA42178FF8F00885E84 /* ARPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3715DEA32178FF8F00885E84 /* ARPresenter.swift */; };
3715DEA62179096300885E84 /* ARViewDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3715DEA52179096300885E84 /* ARViewDelegateProxy.swift */; };
3715DEA821790B9500885E84 /* ARView.PrexComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3715DEA721790B9500885E84 /* ARView.PrexComponents.swift */; };
375D300F216D15D700D5B953 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 375D300E216D15D700D5B953 /* AppDelegate.swift */; };
375D3011216D15D700D5B953 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 375D3010216D15D700D5B953 /* ViewController.swift */; };
375D3014216D15D700D5B953 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 375D3012216D15D700D5B953 /* Main.storyboard */; };
Expand All @@ -29,6 +33,10 @@
/* Begin PBXFileReference section */
1EF19B87DCFEB853B83C3FB3 /* Pods-Shuretta.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Shuretta.release.xcconfig"; path = "Target Support Files/Pods-Shuretta/Pods-Shuretta.release.xcconfig"; sourceTree = "<group>"; };
35DD7BD236D6A68D7E549A88 /* Pods_ArtShredder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ArtShredder.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3715DEA12178FF0400885E84 /* Prex.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Prex.framework; path = Carthage/Build/iOS/Prex.framework; sourceTree = "<group>"; };
3715DEA32178FF8F00885E84 /* ARPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ARPresenter.swift; sourceTree = "<group>"; };
3715DEA52179096300885E84 /* ARViewDelegateProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ARViewDelegateProxy.swift; sourceTree = "<group>"; };
3715DEA721790B9500885E84 /* ARView.PrexComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ARView.PrexComponents.swift; sourceTree = "<group>"; };
375D300B216D15D700D5B953 /* ArtShredder.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ArtShredder.app; sourceTree = BUILT_PRODUCTS_DIR; };
375D300E216D15D700D5B953 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
375D3010216D15D700D5B953 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -60,6 +68,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3715DEA22178FF0400885E84 /* Prex.framework in Frameworks */,
719AE58EEDEC814482CE58CF /* Pods_ArtShredder.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -81,6 +90,7 @@
1BF0846AD1F6339F217DE70C /* Frameworks */ = {
isa = PBXGroup;
children = (
3715DEA12178FF0400885E84 /* Prex.framework */,
EAA1FBADD1E3C9EA2FA09CC6 /* Pods_Shuretta.framework */,
35DD7BD236D6A68D7E549A88 /* Pods_ArtShredder.framework */,
);
Expand Down Expand Up @@ -130,6 +140,9 @@
children = (
37E47A4D2175E5F700C7E693 /* ARViewController.swift */,
37E47A5721767F5F00C7E693 /* ARViewController.xib */,
3715DEA32178FF8F00885E84 /* ARPresenter.swift */,
3715DEA721790B9500885E84 /* ARView.PrexComponents.swift */,
3715DEA52179096300885E84 /* ARViewDelegateProxy.swift */,
37E47A5521765E4400C7E693 /* ARShredderLayer.swift */,
37E47A5E2176EE7000C7E693 /* ARShredderNode.swift */,
);
Expand All @@ -156,6 +169,7 @@
375D3007216D15D700D5B953 /* Sources */,
375D3008216D15D700D5B953 /* Frameworks */,
375D3009216D15D700D5B953 /* Resources */,
3715DEA02178FEC200885E84 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -217,6 +231,24 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
3715DEA02178FEC200885E84 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"$(SRCROOT)/Carthage/Build/iOS/Prex.framework",
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/usr/local/bin/carthage copy-frameworks\n";
};
F33D5ABB3B5FEF8EE47FEDB6 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -249,13 +281,16 @@
37E47A5621765E4400C7E693 /* ARShredderLayer.swift in Sources */,
3771D611216FCBF7003909BE /* SettingViewController.swift in Sources */,
375D3011216D15D700D5B953 /* ViewController.swift in Sources */,
3715DEA821790B9500885E84 /* ARView.PrexComponents.swift in Sources */,
3771D60D216FC711003909BE /* Secret.swift in Sources */,
37E47A4E2175E5F700C7E693 /* ARViewController.swift in Sources */,
3771D609216FC61E003909BE /* AdMobConfig.swift in Sources */,
3715DEA62179096300885E84 /* ARViewDelegateProxy.swift in Sources */,
37E47A5D2176EB1000C7E693 /* Additional.swift in Sources */,
37E47A5F2176EE7000C7E693 /* ARShredderNode.swift in Sources */,
37E47A5B2176EADB00C7E693 /* UIImage.extension.swift in Sources */,
375D300F216D15D700D5B953 /* AppDelegate.swift in Sources */,
3715DEA42178FF8F00885E84 /* ARPresenter.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -424,6 +459,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 8WYW9G5NXR;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = "$(SRCROOT)/ArtShredder/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -444,6 +483,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 8WYW9G5NXR;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = "$(SRCROOT)/ArtShredder/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
41 changes: 41 additions & 0 deletions ArtShredder/AR/ARPresenter.swift
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)
}
}
28 changes: 22 additions & 6 deletions ArtShredder/AR/ARShredderLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,30 @@ final class AspectFillImageLayer: CALayer {

if size.height > size.width {
let relativeHeight = (layerSize.width / size.width) * size.height
let delta = abs(relativeHeight - layerSize.height) / 2
imageLayer.frame.origin.y = -delta
imageLayer.frame.size.height = relativeHeight

if relativeHeight < layerSize.height {
let relativeWidth = (layerSize.height / size.height) * size.width
let delta = abs(relativeWidth - layerSize.width) / 2
imageLayer.frame.origin.x = -delta
imageLayer.frame.size.width = relativeWidth
} else {
let delta = abs(relativeHeight - layerSize.height) / 2
imageLayer.frame.origin.y = -delta
imageLayer.frame.size.height = relativeHeight
}
} else {
let relativeWidth = (layerSize.height / size.height) * size.width
let delta = abs(relativeWidth - layerSize.width) / 2
imageLayer.frame.origin.x = -delta
imageLayer.frame.size.width = relativeWidth

if relativeWidth < layerSize.width {
let relativeHeight = (layerSize.width / size.width) * size.height
let delta = abs(relativeHeight - layerSize.height) / 2
imageLayer.frame.origin.y = -delta
imageLayer.frame.size.height = relativeHeight
} else {
let delta = abs(relativeWidth - layerSize.width) / 2
imageLayer.frame.origin.x = -delta
imageLayer.frame.size.width = relativeWidth
}
}

imageLayer.contents = image.cgImage
Expand Down
47 changes: 47 additions & 0 deletions ArtShredder/AR/ARView.PrexComponents.swift
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
}
}
}
}
Loading

0 comments on commit dcf1b07

Please sign in to comment.