Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mono0926 committed Apr 23, 2017
1 parent d003a5f commit cdd1fd2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
4 changes: 4 additions & 0 deletions NativePopup.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
FECA87D91EAC87B700D07CB1 /* NativePopup.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FE85338B1EAC7C92004BB756 /* NativePopup.framework */; };
FECA87DA1EAC87B700D07CB1 /* NativePopup.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FE85338B1EAC7C92004BB756 /* NativePopup.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
FECA87DF1EAC94B300D07CB1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FECA87DE1EAC94B300D07CB1 /* Assets.xcassets */; };
FECA87E11EACC77800D07CB1 /* NativePopup.extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FECA87E01EACC77800D07CB1 /* NativePopup.extension.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -56,6 +57,7 @@
FECA87C51EAC7CCF00D07CB1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FECA87D71EAC7D9E00D07CB1 /* NativePopup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NativePopup.swift; sourceTree = "<group>"; };
FECA87DE1EAC94B300D07CB1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
FECA87E01EACC77800D07CB1 /* NativePopup.extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NativePopup.extension.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -101,6 +103,7 @@
FE85338E1EAC7C92004BB756 /* NativePopup.h */,
FE85338F1EAC7C92004BB756 /* Info.plist */,
FECA87D71EAC7D9E00D07CB1 /* NativePopup.swift */,
FECA87E01EACC77800D07CB1 /* NativePopup.extension.swift */,
FECA87DE1EAC94B300D07CB1 /* Assets.xcassets */,
);
path = NativePopup;
Expand Down Expand Up @@ -236,6 +239,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FECA87E11EACC77800D07CB1 /* NativePopup.extension.swift in Sources */,
FECA87D81EAC7D9E00D07CB1 /* NativePopup.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
41 changes: 41 additions & 0 deletions NativePopup/NativePopup.extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// NativePopup.extension.swift
// NativePopup
//
// Created by mono on 2017/04/23.
// Copyright © 2017 mono. All rights reserved.
//

import Foundation

extension NativePopup {
public enum Image {
case
good,
bad,
custom(image: UIImage)

var image: UIImage {
switch self {
case .good: return type(of: self).createImage(named: "good")
case .bad: return type(of: self).createImage(named: "bad")
case .custom(let image): return image
}
}

private static func createImage(named: String) -> UIImage {
return UIImage.init(named: named, in: Bundle(for: NativePopup.self), compatibleWith: nil)!
}
}

public struct Info {
public let image: Image
public let title: String
public let message: String?
public init(image: Image, title: String, message: String?) {
self.image = image
self.title = title
self.message = message
}
}
}
31 changes: 0 additions & 31 deletions NativePopup/NativePopup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,11 @@
import Foundation
import UIKit


public class NativePopup: UIView {

private static let keyWindow = UIApplication.shared.keyWindow!
private weak static var currentView: NativePopup?

public enum Image {
case
good,
bad,
custom(image: UIImage)

fileprivate var image: UIImage {
switch self {
case .good: return type(of: self).createImage(named: "good")
case .bad: return type(of: self).createImage(named: "bad")
case .custom(let image): return image
}
}

private static func createImage(named: String) -> UIImage {
return UIImage.init(named: named, in: Bundle(for: NativePopup.self), compatibleWith: nil)!
}
}

public struct Info {
public let image: Image
public let title: String
public let message: String?
public init(image: Image, title: String, message: String?) {
self.image = image
self.title = title
self.message = message
}
}

public static func show(info: Info) {
let view = NativePopup(info: info)
view.show()
Expand Down

0 comments on commit cdd1fd2

Please sign in to comment.