Skip to content

Commit

Permalink
Upgrade SweetAlert to Swift 4.2 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Doko-Demo-Doa committed Oct 13, 2018
1 parent e16e153 commit 5612a9d
Show file tree
Hide file tree
Showing 6 changed files with 707 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ so it will look like:
android:theme="@style/AppTheme">
```

# On iOS:

Since the vendor library is written in Swift, apart from doing usual `react-native link react-native-sweet-alert`, you will also have to create a Bridging Header for Swift file, which is also pretty easy:

- Open the project with XCode.



__And then you can use the library like so:__

```
Expand Down
18 changes: 18 additions & 0 deletions ios/RNSweetAlert-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// RNSweetAlert-Bridging-Header.h
// RNSweetAlert
//
// Created by Quan Pham on 10/13/18.
// Copyright © 2018 Facebook. All rights reserved.
//

#ifndef RNSweetAlert_Bridging_Header_h
#define RNSweetAlert_Bridging_Header_h

#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTViewManager.h>
#import <React/RCTConvert.h>
#import <React/RCTUtils.h>

#endif /* RNSweetAlert_Bridging_Header_h */
28 changes: 27 additions & 1 deletion ios/RNSweetAlert.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/* 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 */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -26,6 +29,10 @@
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>"; };
EDCA74642171D35B005A52E8 /* SweetAlertBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SweetAlertBridge.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -50,12 +57,24 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
EDCA745F21719A1D005A52E8 /* Vendor */,
ED5834842171D63F002A623F /* RNSweetAlert-Bridging-Header.h */,
EDCA74642171D35B005A52E8 /* SweetAlertBridge.m */,
EDCA746021719A39005A52E8 /* SweetAlertManager.swift */,
B3E7B5881CC2AC0600A0062D /* RNSweetAlert.h */,
B3E7B5891CC2AC0600A0062D /* RNSweetAlert.m */,
134814211AA4EA7D00B7C361 /* Products */,
);
sourceTree = "<group>";
};
EDCA745F21719A1D005A52E8 /* Vendor */ = {
isa = PBXGroup;
children = (
EDCA746221719A4A005A52E8 /* SweetAlert.swift */,
);
path = Vendor;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -113,6 +132,9 @@
buildActionMask = 2147483647;
files = (
B3E7B58A1CC2AC0600A0062D /* RNSweetAlert.m in Sources */,
EDCA746121719A39005A52E8 /* SweetAlertManager.swift in Sources */,
EDCA74652171D35B005A52E8 /* SweetAlertBridge.m in Sources */,
EDCA746321719A4A005A52E8 /* SweetAlert.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -204,7 +226,7 @@
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../../React/**",
"$(SRCROOT)/../../react-native/React/**",
Expand All @@ -213,6 +235,8 @@
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = RNSweetAlert;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "RNSweetAlert-Bridging-Header.h";
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -229,6 +253,8 @@
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = RNSweetAlert;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "RNSweetAlert-Bridging-Header.h";
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
17 changes: 17 additions & 0 deletions ios/SweetAlertBridge.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#import <Foundation/Foundation.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(SweetAlertManager, NSObject);

- (dispatch_queue_t)methodQueue {
return dispatch_get_main_queue();
}

RCT_EXTERN_METHOD(showAlert: (NSString *)title callback:(RCTResponseSenderBlock));

RCT_EXTERN_METHOD(showAlertWithSubtitle: (NSString *)title subTitle:(NSString *) subTitle);

RCT_EXTERN_METHOD(hideSweetAlert);

@end
26 changes: 26 additions & 0 deletions ios/SweetAlertManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
}
}
Loading

0 comments on commit 5612a9d

Please sign in to comment.