Skip to content

Commit

Permalink
Added unified function API
Browse files Browse the repository at this point in the history
  • Loading branch information
Doko-Demo-Doa committed Oct 13, 2018
1 parent 5612a9d commit 92677a6
Show file tree
Hide file tree
Showing 5 changed files with 653 additions and 626 deletions.
11 changes: 0 additions & 11 deletions ios/RNSweetAlert.h

This file was deleted.

13 changes: 0 additions & 13 deletions ios/RNSweetAlert.m

This file was deleted.

12 changes: 4 additions & 8 deletions ios/RNSweetAlert.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
B3E7B58A1CC2AC0600A0062D /* RNSweetAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNSweetAlert.m */; };
EDCA746121719A39005A52E8 /* SweetAlertManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCA746021719A39005A52E8 /* SweetAlertManager.swift */; };
EDCA746321719A4A005A52E8 /* SweetAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCA746221719A4A005A52E8 /* SweetAlert.swift */; };
EDCA74652171D35B005A52E8 /* SweetAlertBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = EDCA74642171D35B005A52E8 /* SweetAlertBridge.m */; };
Expand All @@ -27,8 +26,6 @@

/* Begin PBXFileReference section */
134814201AA4EA6300B7C361 /* libRNSweetAlert.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNSweetAlert.a; sourceTree = BUILT_PRODUCTS_DIR; };
B3E7B5881CC2AC0600A0062D /* RNSweetAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSweetAlert.h; sourceTree = "<group>"; };
B3E7B5891CC2AC0600A0062D /* RNSweetAlert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSweetAlert.m; sourceTree = "<group>"; };
ED5834842171D63F002A623F /* RNSweetAlert-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNSweetAlert-Bridging-Header.h"; sourceTree = "<group>"; };
EDCA746021719A39005A52E8 /* SweetAlertManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SweetAlertManager.swift; sourceTree = "<group>"; };
EDCA746221719A4A005A52E8 /* SweetAlert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SweetAlert.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -61,8 +58,6 @@
ED5834842171D63F002A623F /* RNSweetAlert-Bridging-Header.h */,
EDCA74642171D35B005A52E8 /* SweetAlertBridge.m */,
EDCA746021719A39005A52E8 /* SweetAlertManager.swift */,
B3E7B5881CC2AC0600A0062D /* RNSweetAlert.h */,
B3E7B5891CC2AC0600A0062D /* RNSweetAlert.m */,
134814211AA4EA7D00B7C361 /* Products */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -131,7 +126,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B3E7B58A1CC2AC0600A0062D /* RNSweetAlert.m in Sources */,
EDCA746121719A39005A52E8 /* SweetAlertManager.swift in Sources */,
EDCA74652171D35B005A52E8 /* SweetAlertBridge.m in Sources */,
EDCA746321719A4A005A52E8 /* SweetAlert.swift in Sources */,
Expand Down Expand Up @@ -225,6 +219,7 @@
58B511F01A9E6C8500147676 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO;
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
Expand All @@ -235,14 +230,15 @@
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = RNSweetAlert;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "RNSweetAlert-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "$(SWIFT_MODULE_NAME)-Bridging-Header.h";
SWIFT_VERSION = 4.2;
};
name = Debug;
};
58B511F11A9E6C8500147676 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO;
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
Expand All @@ -253,7 +249,7 @@
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = RNSweetAlert;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "RNSweetAlert-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "$(SWIFT_MODULE_NAME)-Bridging-Header.h";
SWIFT_VERSION = 4.2;
};
name = Release;
Expand Down
97 changes: 76 additions & 21 deletions ios/SweetAlertManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,80 @@ import Foundation

@objc(SweetAlertManager)
class SweetAlertManager: RCTViewManager {

var alert = SweetAlert();

@objc
func showAlert(_ title: String, callback: RCTResponseSenderBlock) -> Void {
_ = alert.showAlert(title)
}

@objc
func showAlertWithSubtitle(_ title: String, subTitle: String?) -> Void {
_ = alert.showAlert(title, subTitle: subTitle, style: AlertStyle.none)
}

@objc
func hideSweetAlert() -> Void {
_ = alert.closeAlert(0)
}

override static func requiresMainQueueSetup() -> Bool {
return true
}
var alert = SweetAlert()

@objc
func showAlert(_ title: String, callback: RCTResponseSenderBlock) {
_ = alert.showAlert(title)
}

@objc
func showAlertWithOptions(options: NSDictionary, callback: @escaping RCTResponseSenderBlock) {
let title: String = options.object(forKey: "title") as! String
let subTitle: String = options.object(forKey: "subTitle") as! String
let confirmButtonTitle: String = options.object(forKey: "confirmButtonTitle") as! String
let confirmButtonColor: String = options.object(forKey: "confirmButtonColor") as! String

let otherButtonTitle: String = options.object(forKey: "buttonTitle") as! String
let otherButtonColor: String = options.object(forKey: "otherButtonColor") as! String

// error none success warning
let style: String = options.object(forKey: "style") as! String
var convertedStyle = AlertStyle.none

switch style {
case "error":
convertedStyle = AlertStyle.error
break
case "success":
convertedStyle = AlertStyle.error
break
case "warning":
convertedStyle = AlertStyle.warning
break
default:
convertedStyle = AlertStyle.none
}

_ = alert.showAlert(title, subTitle: subTitle, style: convertedStyle, buttonTitle: confirmButtonTitle, buttonColor: hexStringToUIColor(hex: confirmButtonColor), otherButtonTitle: otherButtonTitle, otherButtonColor: hexStringToUIColor(hex: otherButtonColor), action: { (isOtherButton: Bool) in
// True == isOtherButton.
callback([NSNull(), isOtherButton])
})
}

@objc
func showAlertWithSubtitle(_ title: String, subTitle: String?) {
_ = alert.showAlert(title, subTitle: subTitle, style: AlertStyle.none)
}

@objc
func hideSweetAlert() {
_ = alert.closeAlert(0)
}

func hexStringToUIColor (hex: String) -> UIColor {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()

if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}

if ((cString.count) != 6) {
return UIColor.gray
}

var rgbValue:UInt32 = 0
Scanner(string: cString).scanHexInt32(&rgbValue)

return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}

override class func requiresMainQueueSetup() -> Bool {
return true
}
}
Loading

0 comments on commit 92677a6

Please sign in to comment.