-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from WebEngage/push_revamp
Rich text support added
- Loading branch information
Showing
20 changed files
with
1,186 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// NSMutableAttributedString+Additions.h | ||
// WebEngage | ||
// | ||
// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface NSMutableAttributedString (Additions) | ||
|
||
- (void)updateDefaultTextColor; | ||
|
||
- (void)setFontFaceWithFont:(UIFont *)font; | ||
|
||
- (void)trimWhiteSpace; | ||
|
||
@end |
82 changes: 82 additions & 0 deletions
82
WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// NSMutableAttributedString+Additions.m | ||
// WebEngage | ||
// | ||
// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "NSMutableAttributedString+Additions.h" | ||
#import "UIColor+DarkMode.h" | ||
|
||
@implementation NSMutableAttributedString (Additions) | ||
|
||
- (void)updateDefaultTextColor { | ||
if (@available(iOS 13.0, *)) { | ||
[self beginEditing]; | ||
[self enumerateAttribute:NSForegroundColorAttributeName | ||
inRange:NSMakeRange(0, self.length) | ||
options:0 | ||
usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { | ||
|
||
UIColor *color = (UIColor *)value; | ||
UIColor *labelColor = [UIColor WEXLabelColor]; | ||
NSString *colorHex = [self hexStringFromColor:color]; | ||
|
||
if ([colorHex isEqualToString:@"000000"]) { | ||
[self removeAttribute:NSForegroundColorAttributeName range:range]; | ||
[self addAttribute:NSForegroundColorAttributeName value:labelColor range:range]; | ||
} | ||
}]; | ||
[self endEditing]; | ||
} | ||
} | ||
|
||
- (NSString *)hexStringFromColor:(UIColor *)color { | ||
const CGFloat *components = CGColorGetComponents(color.CGColor); | ||
|
||
CGFloat r = components[0]; | ||
CGFloat g = components[1]; | ||
CGFloat b = components[2]; | ||
|
||
return [NSString stringWithFormat:@"%02lX%02lX%02lX", | ||
lroundf(r * 255), | ||
lroundf(g * 255), | ||
lroundf(b * 255)]; | ||
} | ||
|
||
- (void)setFontFaceWithFont:(UIFont *)font { | ||
[self beginEditing]; | ||
[self enumerateAttribute:NSFontAttributeName | ||
inRange:NSMakeRange(0, self.length) | ||
options:0 | ||
usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { | ||
|
||
UIFont *oldFont = (UIFont *)value; | ||
UIFontDescriptor *newFontDescriptor = [[oldFont.fontDescriptor fontDescriptorWithFamily:font.familyName] fontDescriptorWithSymbolicTraits:oldFont.fontDescriptor.symbolicTraits]; | ||
UIFont *newFont = [UIFont fontWithDescriptor:newFontDescriptor size:font.pointSize]; | ||
|
||
if (newFont) { | ||
[self removeAttribute:NSFontAttributeName range:range]; | ||
[self addAttribute:NSFontAttributeName value:newFont range:range]; | ||
} | ||
}]; | ||
[self endEditing]; | ||
} | ||
|
||
- (void)trimWhiteSpace { | ||
NSCharacterSet *legalChars = [[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet]; | ||
NSRange startRange = [self.string rangeOfCharacterFromSet: legalChars]; | ||
NSRange endRange = [self.string rangeOfCharacterFromSet: legalChars options:NSBackwardsSearch]; | ||
if (startRange.location == NSNotFound || endRange.location == NSNotFound) { | ||
// there are no legal characters in self --- it is ALL whitespace, and so we 'trim' everything leaving an empty string | ||
[self setAttributedString:[NSAttributedString new]]; | ||
} | ||
else { | ||
NSUInteger startLocation = NSMaxRange(startRange), endLocation = endRange.location; | ||
NSRange range = NSMakeRange(startLocation - 1, endLocation - startLocation + 2); | ||
[self setAttributedString:[self attributedSubstringFromRange:range]]; | ||
} | ||
} | ||
|
||
@end |
22 changes: 22 additions & 0 deletions
22
WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// UIColor+DarkMode.h | ||
// WebEngage | ||
// | ||
// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIColor (DarkMode) | ||
|
||
+ (UIColor *)WEXWhiteColor; | ||
|
||
+ (UIColor *)WEXGreyColor; | ||
|
||
+ (UIColor *)WEXLabelColor; | ||
|
||
+ (UIColor *)WEXLightTextColor; | ||
|
||
+ (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor; | ||
|
||
@end |
63 changes: 63 additions & 0 deletions
63
WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// UIColor+DarkMode.m | ||
// WebEngage | ||
// | ||
// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "UIColor+DarkMode.h" | ||
|
||
@implementation UIColor (DarkMode) | ||
|
||
+ (UIColor *)WEXWhiteColor { | ||
if (@available(iOS 13.0, *)) { | ||
return UIColor.systemBackgroundColor; | ||
} else { | ||
return UIColor.whiteColor; | ||
} | ||
} | ||
|
||
+ (UIColor *)WEXGreyColor { | ||
if (@available(iOS 13.0, *)) { | ||
return UIColor.systemGrayColor; | ||
} else { | ||
return UIColor.lightGrayColor; | ||
} | ||
} | ||
|
||
+ (UIColor *)WEXLabelColor { | ||
if (@available(iOS 13.0, *)) { | ||
return UIColor.labelColor; | ||
} else { | ||
return UIColor.blackColor; | ||
} | ||
} | ||
|
||
+ (UIColor *)WEXLightTextColor { | ||
if (@available(iOS 13.0, *)) { | ||
return UIColor.systemGray4Color; | ||
} else { | ||
return UIColor.lightTextColor; | ||
} | ||
} | ||
|
||
+ (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor { | ||
if (hexString == (id)[NSNull null] || hexString.length == 0) { | ||
return defaultColor; | ||
} | ||
|
||
unsigned rgbValue = 0; | ||
NSScanner *scanner = [NSScanner scannerWithString:hexString]; | ||
|
||
if ([hexString hasPrefix:@"#"]) { | ||
[scanner setScanLocation:1]; // bypass '#' character | ||
} else { | ||
[scanner setScanLocation:0]; | ||
} | ||
|
||
[scanner scanHexInt:&rgbValue]; | ||
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; | ||
} | ||
|
||
@end |
24 changes: 24 additions & 0 deletions
24
WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// WEXBannerPushNotificationViewController.h | ||
// WebEngage | ||
// | ||
// Copyright (c) 2022 Webklipper Technologies Pvt Ltd. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 | ||
#import <UserNotifications/UserNotifications.h> | ||
#import <UserNotificationsUI/UserNotificationsUI.h> | ||
#import "WEXRichPushNotificationViewController+Private.h" | ||
#import "WEXRichPushLayout.h" | ||
#endif | ||
|
||
@interface WEXBannerPushNotificationViewController | ||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 | ||
: WEXRichPushLayout | ||
#else | ||
: NSObject | ||
#endif | ||
|
||
@end |
Oops, something went wrong.