Skip to content

Commit bdd6019

Browse files
committed
Create new Harmony library
1 parent cc61582 commit bdd6019

File tree

449 files changed

+2260
-48153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

449 files changed

+2260
-48153
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ playground.xcworkspace
4545
# you should judge for yourself, the pros and cons are mentioned at:
4646
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
4747
#
48-
# Pods/
48+
Pods/
4949

5050
# Carthage
5151
#

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Harmony.xcodeproj/project.pbxproj

+2-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
D2D1A64C229C8CE600FE6D97 /* UserDefaults+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D1A64B229C8CE600FE6D97 /* UserDefaults+Extension.swift */; };
3535
D2D9FB5B203DE7E20069AE74 /* Future+InitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D9FB5A203DE7E20069AE74 /* Future+InitTests.swift */; };
3636
D2D9FB5D203DEC8A0069AE74 /* Future+SetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D9FB5C203DEC8A0069AE74 /* Future+SetTests.swift */; };
37-
D2D9FB63203DEC990069AE74 /* MJFuturePerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D9FB5F203DEC990069AE74 /* MJFuturePerformanceTests.swift */; };
3837
D2D9FB64203DEC990069AE74 /* GCDPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D9FB60203DEC990069AE74 /* GCDPerformanceTests.swift */; };
3938
D2D9FB65203DEC990069AE74 /* PromisesPerformanceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D9FB61203DEC990069AE74 /* PromisesPerformanceTest.swift */; };
4039
D2D9FB66203DEC990069AE74 /* FuturePerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D9FB62203DEC990069AE74 /* FuturePerformanceTests.swift */; };
@@ -94,7 +93,6 @@
9493
D2D1A64B229C8CE600FE6D97 /* UserDefaults+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+Extension.swift"; sourceTree = "<group>"; };
9594
D2D9FB5A203DE7E20069AE74 /* Future+InitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Future+InitTests.swift"; sourceTree = "<group>"; };
9695
D2D9FB5C203DEC8A0069AE74 /* Future+SetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Future+SetTests.swift"; sourceTree = "<group>"; };
97-
D2D9FB5F203DEC990069AE74 /* MJFuturePerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MJFuturePerformanceTests.swift; sourceTree = "<group>"; };
9896
D2D9FB60203DEC990069AE74 /* GCDPerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GCDPerformanceTests.swift; sourceTree = "<group>"; };
9997
D2D9FB61203DEC990069AE74 /* PromisesPerformanceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromisesPerformanceTest.swift; sourceTree = "<group>"; };
10098
D2D9FB62203DEC990069AE74 /* FuturePerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FuturePerformanceTests.swift; sourceTree = "<group>"; };
@@ -385,7 +383,6 @@
385383
D2D9FB5E203DEC990069AE74 /* Performance */ = {
386384
isa = PBXGroup;
387385
children = (
388-
D2D9FB5F203DEC990069AE74 /* MJFuturePerformanceTests.swift */,
389386
D2D9FB60203DEC990069AE74 /* GCDPerformanceTests.swift */,
390387
D2D9FB61203DEC990069AE74 /* PromisesPerformanceTest.swift */,
391388
D2D9FB62203DEC990069AE74 /* FuturePerformanceTests.swift */,
@@ -505,22 +502,18 @@
505502
);
506503
inputPaths = (
507504
"${PODS_ROOT}/Target Support Files/Pods-Harmony_Example/Pods-Harmony_Example-frameworks.sh",
508-
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
509505
"${BUILT_PRODUCTS_DIR}/Harmony/Harmony.framework",
506+
"${BUILT_PRODUCTS_DIR}/HarmonyAlamofire/HarmonyAlamofire.framework",
510507
"${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework",
511-
"${BUILT_PRODUCTS_DIR}/MJCocoaCore/MJCocoaCore.framework",
512-
"${BUILT_PRODUCTS_DIR}/MJObjection/MJObjection.framework",
513508
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
514509
"${BUILT_PRODUCTS_DIR}/PromisesSwift/Promises.framework",
515510
"${BUILT_PRODUCTS_DIR}/SQLite.swift/SQLite.framework",
516511
);
517512
name = "[CP] Embed Pods Frameworks";
518513
outputPaths = (
519-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
520514
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Harmony.framework",
515+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HarmonyAlamofire.framework",
521516
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Kingfisher.framework",
522-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJCocoaCore.framework",
523-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJObjection.framework",
524517
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
525518
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Promises.framework",
526519
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLite.framework",
@@ -599,7 +592,6 @@
599592
isa = PBXSourcesBuildPhase;
600593
buildActionMask = 2147483647;
601594
files = (
602-
D2D9FB63203DEC990069AE74 /* MJFuturePerformanceTests.swift in Sources */,
603595
D2D9FB6A203DF2A30069AE74 /* Future+ThenTests.swift in Sources */,
604596
D2D9FB68203DEE9A0069AE74 /* Future+DeallocTests.swift in Sources */,
605597
D2D9FB66203DEC990069AE74 /* FuturePerformanceTests.swift in Sources */,

Example/Harmony.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Example/Harmony/AppDelegate.swift

+179-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
import UIKit
10-
import MJCocoaCore
1110
import Harmony
1211

1312
let applicationComponent: ApplicationComponent = ApplicationDefaultModule()
@@ -58,3 +57,182 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5857
}
5958
}
6059

60+
public class ContainerViewController: UIViewController {
61+
62+
private static let animationDuration : Double = 0.40
63+
private static let animationOptions = UIView.AnimationOptions(rawValue:(7<<16))
64+
65+
public enum Animation {
66+
case none
67+
case crossDisolve
68+
case newModalBottom
69+
case oldModalBottom
70+
}
71+
72+
/// The contained view controller
73+
public private(set) var viewController : UIViewController
74+
75+
/// Main initializer
76+
///
77+
/// - Parameter viewController: The view controller to contain
78+
public required init(_ viewController: UIViewController) {
79+
self.viewController = viewController
80+
super.init(nibName: nil, bundle: nil)
81+
}
82+
83+
public required init?(coder aDecoder: NSCoder) {
84+
self.viewController = UIViewController(nibName: nil, bundle: nil)
85+
super.init(coder: aDecoder)
86+
}
87+
88+
/// Sets a new view controller
89+
///
90+
/// - Parameters:
91+
/// - viewController: The new view controller
92+
/// - animation: The replacement animation
93+
public func set(_ viewController: UIViewController, animation: Animation = .none) {
94+
if isViewLoaded {
95+
// Getting instances on the view controllers
96+
let oldVC = self.viewController
97+
let newVC = viewController
98+
99+
// Configuring the new view controller's view
100+
let subview = viewController.view!
101+
subview.autoresizingMask = [.flexibleWidth, .flexibleHeight]
102+
subview.frame = self.view.bounds
103+
104+
// Storing the new view controller
105+
self.viewController = viewController
106+
107+
oldVC.willMove(toParent: nil)
108+
self.addChild(newVC)
109+
110+
switch (animation) {
111+
case .none:
112+
oldVC.view.removeFromSuperview()
113+
self.view.insertSubview(newVC.view, at: 0)
114+
oldVC.removeFromParent()
115+
newVC.didMove(toParent: self)
116+
case .crossDisolve:
117+
self.view.insertSubview(newVC.view, belowSubview: oldVC.view)
118+
UIView.animate(withDuration: ContainerViewController.animationDuration,
119+
delay: 0,
120+
options: ContainerViewController.animationOptions,
121+
animations: {
122+
oldVC.view.alpha = 0.0
123+
},
124+
completion: { (success) in
125+
oldVC.view.removeFromSuperview()
126+
oldVC.removeFromParent()
127+
newVC.didMove(toParent: self)
128+
})
129+
case .newModalBottom:
130+
newVC.view.alpha = 0.0
131+
newVC.view.frame = self.view.bounds.offsetBy(dx: 0, dy: UIScreen.main.bounds.size.height)
132+
self.view.insertSubview(newVC.view, aboveSubview: oldVC.view)
133+
UIView.animate(withDuration: ContainerViewController.animationDuration,
134+
delay: 0,
135+
options: ContainerViewController.animationOptions,
136+
animations: {
137+
newVC.view.alpha = 1.0
138+
newVC.view.frame = self.view.bounds
139+
},
140+
completion: { (success) in
141+
oldVC.view.removeFromSuperview()
142+
oldVC.removeFromParent()
143+
newVC.didMove(toParent: self)
144+
})
145+
case .oldModalBottom:
146+
let frame = self.view.bounds.offsetBy(dx: 0, dy: UIScreen.main.bounds.size.height)
147+
self.view.insertSubview(newVC.view, belowSubview: oldVC.view)
148+
UIView.animate(withDuration: ContainerViewController.animationDuration,
149+
delay: 0,
150+
options: ContainerViewController.animationOptions,
151+
animations: {
152+
oldVC.view.alpha = 0.0
153+
oldVC.view.frame = frame
154+
},
155+
completion: { (success) in
156+
oldVC.view.removeFromSuperview()
157+
oldVC.removeFromParent()
158+
newVC.didMove(toParent: self)
159+
})
160+
}
161+
} else {
162+
// View not loaded yet. Just storing the instance for later processing
163+
self.viewController = viewController
164+
}
165+
}
166+
167+
override public func viewDidLoad() {
168+
super.viewDidLoad()
169+
if !self.children.contains(viewController) {
170+
let subview = viewController.view!
171+
subview.autoresizingMask = [.flexibleWidth, .flexibleHeight]
172+
subview.frame = self.view.bounds
173+
174+
addChild(viewController)
175+
self.view.addSubview(subview)
176+
viewController.didMove(toParent: self)
177+
}
178+
}
179+
180+
override public func viewWillLayoutSubviews() {
181+
super.viewWillLayoutSubviews()
182+
self.view.subviews.first?.frame = self.view.bounds
183+
}
184+
185+
override public func willMove(toParent parent: UIViewController?) {
186+
super.willMove(toParent: parent)
187+
if parent != nil {
188+
addChild(viewController)
189+
} else {
190+
viewController.willMove(toParent: nil)
191+
}
192+
}
193+
194+
override public func didMove(toParent parent: UIViewController?) {
195+
super.didMove(toParent: parent)
196+
if parent != nil {
197+
viewController.didMove(toParent: self)
198+
} else {
199+
viewController.removeFromParent()
200+
}
201+
}
202+
203+
override public var preferredStatusBarStyle: UIStatusBarStyle {
204+
get {
205+
return viewController.preferredStatusBarStyle
206+
}
207+
}
208+
209+
override public var shouldAutorotate: Bool {
210+
get {
211+
return viewController.shouldAutorotate
212+
}
213+
}
214+
215+
override public var supportedInterfaceOrientations: UIInterfaceOrientationMask {
216+
get {
217+
return viewController.supportedInterfaceOrientations
218+
}
219+
}
220+
}
221+
222+
public extension UIViewController {
223+
/// Returns the first ContainerViewController found in the hierarchy.
224+
///
225+
/// - Returns: The first ContainerViewController found in the hierarchy.
226+
func containerViewController() -> ContainerViewController? {
227+
var vc : UIViewController? = self
228+
while vc != nil {
229+
if let viewController = vc {
230+
if viewController.isKind(of: ContainerViewController.self) {
231+
return viewController as? ContainerViewController
232+
}
233+
vc = viewController.parent
234+
}
235+
}
236+
return nil
237+
}
238+
}

Example/Harmony/Core/App/UnauthorizedStatusCodeRequestRetrier.swift

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import UIKit
1010

1111
import Alamofire
12-
import Harmony
1312

1413
class UnauthorizedStatusCodeRequestRetrier: RequestRetrier {
1514

Example/Harmony/Core/Features/Item/Data/Network/ItemNetworkDataSource.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import Foundation
77

8-
import Alamofire
98
import Harmony
9+
import Alamofire
1010

1111
extension ItemEntity {
1212
fileprivate static var fromNetworkMap : [String : String] {

Example/Harmony/Core/Utils/Alamofire+Future.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// Copyright © 2017 Mobile Jazz. All rights reserved.
77
//
88

9-
10-
import Alamofire
119
import Harmony
10+
import HarmonyAlamofire
11+
import Alamofire
1212

1313
public extension DataRequest {
1414
/// Inserts the JSON data response into a Future

0 commit comments

Comments
 (0)