Skip to content

Commit

Permalink
fix+feat: Some improvements + added isRequired
Browse files Browse the repository at this point in the history
- Added isRequired as conf on Notification
- Fixed some code styling
- Implemented SPIndicator and not SPAlert
  • Loading branch information
g-m-99 committed Dec 6, 2023
1 parent 62dfc74 commit b02db68
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 105 deletions.
12 changes: 0 additions & 12 deletions AlertViewTest.h

This file was deleted.

2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require Pod::Executable.execute_command('node', ['-p',

platform :ios, min_ios_version_supported
prepare_react_native_project!

use_frameworks! :linkage => :static
# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
Expand Down
44 changes: 24 additions & 20 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ PODS:
- RCT-Folly (= 2021.07.22.00)
- React-Core
- SDWebImage (~> 5.0)
- SPIndicator
- React-NativeModulesApple (0.72.5):
- React-callinvoker
- React-Core
Expand Down Expand Up @@ -395,6 +396,7 @@ PODS:
- SDWebImage/Core (= 5.18.3)
- SDWebImage/Core (5.18.3)
- SocketRocket (0.6.1)
- SPIndicator (1.6.4)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -444,6 +446,7 @@ SPEC REPOS:
- fmt
- SDWebImage
- SocketRocket
- SPIndicator

EXTERNAL SOURCES:
boost:
Expand Down Expand Up @@ -537,38 +540,39 @@ SPEC CHECKSUMS:
RCTTypeSafety: 4636e4a36c7c2df332bda6d59b19b41c443d4287
React: e0cc5197a804031a6c53fb38483c3485fcb9d6f3
React-callinvoker: 1a635856fe0c3d8b13fccd4ed7e76283b99b0868
React-Codegen: 2c2e23ede5a87859465582502ff61c7f63bc1ed8
React-Core: 5bb7f0f43a6fae733201a0396521bec7c1b062c0
React-CoreModules: f8b9e91fac7bd5d18729ce961a4978c70b5031cc
React-Codegen: 9cf2110ff377a905cd84f291b31fee39caed81b4
React-Core: c44c3146bfb7d122cbd2ad572d2403457244bed5
React-CoreModules: c39f9ef5cf812b2b266c63364a8969b29d30ba2a
React-cxxreact: 2fd17904f2d5ab7318e5432cf24de225cbf1768f
React-debug: ee33d7ba43766d9b10b32561527b57ccfbcb6bd1
React-debug: 93d183299eb4bd7b0bf8cb6e376f608e2a95b64f
React-jsc: f4a2687433840ec8c1be9d2f557fe71a7b5e66b5
React-jsi: bd20f0acd279dee534d8b731b31131f443b00868
React-jsiexecutor: f32f98d8ddbdfd97dea286af90381a731d68c505
React-jsinspector: aef73cbd43b70675f572214d10fa438c89bf11ba
React-logger: 2e4aee3e11b3ec4fa6cfd8004610bbb3b8d6cca4
react-native-bundle-updater: 8e9a3ba0a2a20979fac8352297f1e7e777194e90
React-NativeModulesApple: c6529c637f2e886aab44c48d66cabef2d4fd1138
react-native-bundle-updater: c6a6abe1c438e4ce16e6c8c43d30892fde92113a
React-NativeModulesApple: 535e26db03f74ecc500748ce79fa349b2ee2ee21
React-perflogger: cd8886513f68e1c135a1e79d20575c6489641597
React-RCTActionSheet: 726d2615ca62a77ce3e2c13d87f65379cdc73498
React-RCTAnimation: 8f2716b881c37c64858e4ecee0f58bfa57ff9afd
React-RCTAppDelegate: fa1c94d4c789a37c64bf1ba9f7bc0038beb6c2be
React-RCTBlob: 3e6120f6abbc7b8dc173da0db633d67cec7f66b7
React-RCTImage: 747e3d7b656a67470f9c234baedb8d41bbc4e745
React-RCTLinking: 148332b5b0396b280b05534f7d168e560a3bbd5f
React-RCTNetwork: 1d818121a8e678f064de663a6db7aaefc099e53c
React-RCTSettings: 4b95d26ebc88bfd3b6535b2d7904914ff88dbfc2
React-RCTAnimation: 0dcffbaab5acd05334d1d3b157f9275291e3a15b
React-RCTAppDelegate: 45099a63e41201a97ec9c2da0b818ec099b96658
React-RCTBlob: 066b6f215e44a05f53f6c8da8f14d5a06d00eb54
React-RCTImage: a80cc7170c7cd07b7b109353c605930b24d14bcf
React-RCTLinking: fb1add50b83dc4f3d39526d4ff5127f171cdad86
React-RCTNetwork: 6acdb13f8df6cff487f87ac799a3839ce1d45dac
React-RCTSettings: 0b8b7c2ebb78c540f7b0c0bbe46ab5481023f8a8
React-RCTText: ce4499e4f2d8f85dc4b93ff0559313a016c4f3e2
React-RCTVibration: 45372e61b35e96d16893540958d156675afbeb63
React-rncore: a79d1cb3d6c01b358a8aa0b31ccc04ab5f0dbebc
React-RCTVibration: abb9c73984f4f0052cf50efe0ae6d6f877a74843
React-rncore: 3775c85216adc845837e5420c823a689aeaae630
React-runtimeexecutor: 7e31e2bc6d0ecc83d4ba05eadc98401007abc10c
React-runtimescheduler: 05bede38cb51ae152f31707022e881ee9ae970ab
React-utils: 7a9918a1ffdd39aba67835d42386f592ea3f8e76
ReactCommon: a77b3916d0d39113b5f0de714a0acd47c9d17c3a
React-runtimescheduler: cf556acfc14dd4322d3337c70dd44c2742850ca5
React-utils: 40cdd9acee23230df5b78bf78a64ce8a2084c2d0
ReactCommon: c16d3a77f8fc5d3e0df30c2ac4eac82fbc9aeb8c
SDWebImage: 96e0c18ef14010b7485210e92fac888587ebb958
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
SPIndicator: 93e0a4fb23de51294ac48e874c0f081a5e293e4f
Yoga: 86fed2e4d425ee4c6eab3813ba1791101ee153c6

PODFILE CHECKSUM: 36f3ad0a064dd81d1315b07ef45c36b5b83cdc6a
PODFILE CHECKSUM: 7431905f8d399ca127564f129bfa93819111c9b2

COCOAPODS: 1.12.1
COCOAPODS: 1.14.2
126 changes: 75 additions & 51 deletions ios/BundleUpdater.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "BundleUpdater.h"
#import "AlertViewTest.h"
#import "BundlerUpdaterNitificationVC.h"
#import "BundleUpdaterViewController.h"
#import "CommonCrypto/CommonDigest.h"

Expand All @@ -10,20 +10,23 @@


@interface BundleUpdater()
// in this case variables would be visible for anyone which has an instance of the class
// @property (nonatomic, strong) NSString *apiUrl;
// @property (nonatomic, strong) NSString *bundle_id_from_api;
// @property (nonatomic, strong) BundleUpdaterViewController *updaterVC;
// in this case props will be visible to any subclass (them are still private)
// useful when need of getter and setter by default
@property (nonatomic, strong) NSString *apiUrl;
@property (nonatomic, strong) NSString *bundle_id_from_api;
@property (nonatomic, strong) BundleUpdaterViewController *updaterVC;
@end

@implementation BundleUpdater{
// in this case are private variables only visible inside the class
NSString *_apiUrl;
NSString *_bundle_id_from_api;
BundleUpdaterViewController *_updaterVC;
// in this case are private instance variables only visible inside this class and not on subclasses
// NSString *_apiUrl;
// NSString *_bundle_id_from_api;
// BundleUpdaterViewController *_updaterVC;
}
RCT_EXPORT_MODULE()

// MARK: - INIT

+ (instancetype)sharedInstance{
static BundleUpdater *sharedInstance = nil;
static dispatch_once_t once_token;
Expand All @@ -33,15 +36,34 @@ + (instancetype)sharedInstance{
return sharedInstance;
}

- (instancetype)init{
self = [super init];
// init variables
_apiUrl = @"http://192.168.1.92:3003";
_bundle_id_from_api = @"";
_updaterVC = [[BundleUpdaterViewController alloc] init];
return self;
// MARK: - SETTERS

- (NSString *)apiUrl{
//lazy initialization
if(!_apiUrl){
_apiUrl = @"http://192.168.1.92:3003";
}
return _apiUrl;
}

- (NSString *)bundle_id_from_api{
// lazy init
if(!_bundle_id_from_api){
_bundle_id_from_api = @"";
}
return _bundle_id_from_api;
}

- (BundleUpdaterViewController *)updaterVC {
// lazy init
if(!_updaterVC){
_updaterVC = [[BundleUpdaterViewController alloc] init];
}
return _updaterVC;
}

// MARK: - METHODS

/*!
* @brief get the hash of the file
*
Expand Down Expand Up @@ -192,41 +214,45 @@ - (NSDictionary *)getMetaData {
*
* @param updateData - dictionary with the sheet config
*/
- (void)showUpdateVC:(NSDictionary *)updateData {
- (void)showUpdateVC:(NSDictionary *)updateData withNecessaryUpdate:(BOOL)isNecessaryUpdate{
// Set the data properties of the bottom sheet view controller
_updaterVC.image = updateData[@"image"];
_updaterVC.titleText = updateData[@"title"];
_updaterVC.message = updateData[@"message"];
_updaterVC.buttonLabel = updateData[@"button_label"];
_updaterVC.buttonLink = updateData[@"button_label"];
_updaterVC.buttonBackgroundColor = updateData[@"button_color"];
_updaterVC.buttonIcon = [UIImage imageNamed:@"button_icon"];
_updaterVC.footerLogo = [UIImage imageNamed:@"sdk_logo"];
self.updaterVC.image = updateData[@"image"];
self.updaterVC.titleText = updateData[@"title"];
self.updaterVC.message = updateData[@"message"];
self.updaterVC.buttonLabel = updateData[@"button_label"];
self.updaterVC.buttonLink = updateData[@"button_label"];
self.updaterVC.buttonBackgroundColor = updateData[@"button_color"];
self.updaterVC.buttonIcon = [UIImage imageNamed:@"button_icon"];
self.updaterVC.footerLogo = [UIImage imageNamed:@"sdk_logo"];
if(isNecessaryUpdate){
self.updaterVC.isNecessaryUpdate = true;
}
NSString *type = updateData[@"type"];
if([type isEqualToString:@"Notification"]){
//TODO - pass config to the notification
AlertViewTest *alertVC = [AlertViewTest new];
if([alertVC isKindOfClass:[UIViewController class]]){
UIViewController *_alertVC = (UIViewController *)alertVC;
_alertVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
BundlerUpdaterNitificationVC *notificationVC = [BundlerUpdaterNitificationVC new];
notificationVC.isNecessaryUpdate = isNecessaryUpdate;
if([notificationVC isKindOfClass:[UIViewController class]]){
UIViewController *_notificationVC = (UIViewController *)notificationVC;
_notificationVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
// present the new viewContoller
dispatch_async(dispatch_get_main_queue(), ^{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIViewController *rootViewController = window.rootViewController;
[rootViewController presentViewController:_alertVC animated:NO completion:nil];
[rootViewController presentViewController:_notificationVC animated:NO completion:nil];
});
return;
}else{
NSLog(@"[SDK] It's NOT an UIViewController, display normal bottomsheet");
}
}else if([type isEqualToString:@"Modal"]){
_updaterVC.isModal = true;
self.updaterVC.isModal = true;
}
UIViewController *rootViewController =
[[[UIApplication sharedApplication] keyWindow] rootViewController];
_updaterVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
_updaterVC.transitioningDelegate = self;
[rootViewController presentViewController:_updaterVC
self.updaterVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
self.updaterVC.transitioningDelegate = self;
[rootViewController presentViewController:self.updaterVC
animated:YES
completion:nil];
}
Expand All @@ -236,7 +262,7 @@ - (void)showUpdateVC:(NSDictionary *)updateData {
*/
-(void)hideBottomSheet {
dispatch_async(dispatch_get_main_queue(), ^{
[self->_updaterVC dismissViewControllerAnimated:YES completion:nil];
[self.updaterVC dismissViewControllerAnimated:YES completion:nil];
});
}

Expand Down Expand Up @@ -264,7 +290,7 @@ - (void)initialization:(NSString *)apiKey


NSString *urlString =
[NSString stringWithFormat:@"%@/project/%@/initialize", _apiUrl, apiKey];
[NSString stringWithFormat:@"%@/project/%@/initialize", self.apiUrl, apiKey];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
Expand Down Expand Up @@ -341,9 +367,9 @@ - (void)initialization:(NSString *)apiKey
} else {
// NSHTTPURLResponse *httpResponse =
// (NSHTTPURLResponse *)response;
NSLog(@"[SDK] initialization response: %@",
[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding]);
// NSLog(@"[SDK] initialization response: %@",
// [[NSString alloc] initWithData:data
// encoding:NSUTF8StringEncoding]);
// if(httpResponse.statusCode == 404){
//
// }
Expand All @@ -357,22 +383,20 @@ - (void)initialization:(NSString *)apiKey
NSLog(@"[SDK] JSON parsing error: %@", jsonError);
return;
}
NSLog(@"%@", responseDict.description);
NSLog(@"%@", [responseDict valueForKey:@"update_required"]);
// NSLog(@"%@", responseDict.description);
// NSLog(@"%@", [responseDict valueForKey:@"update_required"]);
id updateRequiredValue = [responseDict valueForKey:@"update_required"];
if (updateRequiredValue != nil) {
NSLog(@"Update required %@", updateRequiredValue ? @"YES": @"NO");
if([updateRequiredValue isKindOfClass:[NSNumber class]]){
// update not required
}else{
//update required
if ([responseDict valueForKey:@"update_required"]) {
bool isNecessaryUpdate = [[responseDict valueForKey:@"isNecessaryUpdate"] boolValue];
if(isNecessaryUpdate){
self->_updaterVC.isNecessaryUpdate = true;
}
self->_bundle_id_from_api = [responseDict valueForKey:@"bundleId"];
bool isNecessaryUpdate = [[responseDict valueForKey:@"is_necessary"] boolValue];
self.bundle_id_from_api = [responseDict valueForKey:@"bundleId"];
dispatch_async(dispatch_get_main_queue(), ^{
[self showUpdateVC:updateRequiredValue];
[self showUpdateVC:updateRequiredValue withNecessaryUpdate:isNecessaryUpdate];
});
}
}
Expand Down Expand Up @@ -445,13 +469,13 @@ - (NSURL *)initializeBundle:(RCTBridge *)bridge withKey:(NSString *)key{
dispatch_async(
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//Save the actual bundle id on the phone
[[NSUserDefaults standardUserDefaults] setObject:self->_bundle_id_from_api forKey:@"bundleId"];
[[NSUserDefaults standardUserDefaults] setObject:self.bundle_id_from_api forKey:@"bundleId"];
// get the saved api key
NSString *_key = [[NSUserDefaults standardUserDefaults] stringForKey:@"bundleKey"];
NSString *keyToUse = apiKey ? apiKey : _key;
// Fetch script from server
NSString *url = [NSString
stringWithFormat:@"%@/project/%@/bundle", self->_apiUrl, keyToUse];
stringWithFormat:@"%@/project/%@/bundle", self.apiUrl, keyToUse];

NSLog(@"[SDK] Fetching script from %@", url);

Expand All @@ -474,7 +498,7 @@ - (NSURL *)initializeBundle:(RCTBridge *)bridge withKey:(NSString *)key{
return;
}
NSHTTPURLResponse *res = (NSHTTPURLResponse *)response;
NSLog(@"%ld",(long)res.statusCode);
// NSLog(@"%ld",(long)res.statusCode);
if(res.statusCode == 200){
NSError *jsonError;
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
Expand Down Expand Up @@ -525,7 +549,7 @@ - (NSURL *)initializeBundle:(RCTBridge *)bridge withKey:(NSString *)key{
// update done or not - dismiss bottomsheet
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.2 animations:^{
self->_updaterVC.backgroundView.alpha = 0;
self.updaterVC.backgroundView.alpha = 0;
}];
[NSTimer scheduledTimerWithTimeInterval:0.2
target:self
Expand Down
6 changes: 2 additions & 4 deletions ios/AlertViewTest.h → ios/BundlerUpdaterNitificationVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

NS_ASSUME_NONNULL_BEGIN

@interface AlertViewTest : NSObject
@interface BundlerUpdaterNitificationVC : UIViewController

@property (nonatomic, strong) NSString *test;

- (void)useAlertView;
@property (nonatomic) BOOL isNecessaryUpdate;

@end

Expand Down
Loading

0 comments on commit b02db68

Please sign in to comment.