Skip to content

Commit

Permalink
Updating Braze SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
lowip committed Jun 11, 2021
1 parent 84b0e3f commit dcd1a23
Show file tree
Hide file tree
Showing 35 changed files with 602 additions and 777 deletions.
2 changes: 1 addition & 1 deletion Appboy-iOS-SDK.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Appboy-iOS-SDK"
s.version = "4.2.0"
s.version = "4.3.0"
s.summary = "This is the Braze iOS SDK for Mobile Marketing Automation"
s.homepage = "http://www.braze.com"
s.license = { :type => 'Commercial', :text => 'Please refer to https://github.com/Appboy/appboy-ios-sdk/blob/master/LICENSE'}
Expand Down
2 changes: 1 addition & 1 deletion AppboyKit/include/Appboy.h
Expand Up @@ -13,7 +13,7 @@
#import <UserNotifications/UserNotifications.h>

#ifndef APPBOY_SDK_VERSION
#define APPBOY_SDK_VERSION @"4.2.0"
#define APPBOY_SDK_VERSION @"4.3.0"
#endif

#if !TARGET_OS_TV
Expand Down
Binary file modified AppboyPushStory/Resources/ABKPageView.nib
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -28,12 +28,6 @@ @interface ABKContentCardsTableViewController () <ABKBaseContentCardCellDelegate
*/
@property (nonatomic) NSMutableSet<NSString *> *unviewedOnScreenCards;

/*!
* Stores the cell heights to provide for a smooth scrolling experience when cells need
* to resize themselves as you scroll through the ViewController
*/
@property (nonatomic) NSMutableDictionary<NSString *, NSNumber *> *cellHeights;

/*!
* There is some initialization such as associating which cell class to use in the table view that
* is the responsibility of the storyboard if one is provided. If no story board is used then
Expand Down Expand Up @@ -77,7 +71,6 @@ - (void)setUp {
_cacheTimeout = ABKContentCardsCacheTimeout;
_cardImpressions = [NSMutableSet set];
_unviewedOnScreenCards = [NSMutableSet set];
_cellHeights = [NSMutableDictionary dictionary];
_enableDarkTheme = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(contentCardsUpdated:)
Expand Down Expand Up @@ -298,20 +291,13 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
// the scrollView jump if a cell needs to resize itself
- (CGFloat)tableView:(UITableView *)tableView
estimatedHeightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
ABKContentCard *card = self.cards[indexPath.row];
NSNumber *height = self.cellHeights[card.idString];
if (height) {
return [height floatValue];
}
return ABKContentCardsCellEstimatedHeight;
}

- (void)tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
ABKContentCard *card = self.cards[indexPath.row];
self.cellHeights[card.idString] = @(cell.frame.size.height);

BOOL cellVisible = [[tableView indexPathsForVisibleRows] containsObject:indexPath];
if (cellVisible) {
[self logCardImpressionIfNeeded:card];
Expand Down Expand Up @@ -469,10 +455,14 @@ - (NSString *)localizedAppboyContentCardsString:(NSString *)key {

#pragma mark - ABKBaseContentCardCellDelegate

- (void)refreshTableViewCellHeights {
- (void)cellRequestSizeUpdate:(UITableViewCell *)cell {
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
if (indexPath == nil) {
return;
}

[UIView performWithoutAnimation:^{
[self.tableView beginUpdates];
[self.tableView endUpdates];
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}];
}

Expand Down
Expand Up @@ -8,12 +8,4 @@

- (void)applyCard:(ABKBannerContentCard *)bannerCard;

- (void)updateImageConstraintsWithRatio:(CGFloat)newRatio;

/*!
* @discussion specific view property initialization that is in place of Storyboard or XIB initialization.
* Called by the ABKBaseContentCardCell setUpUI method and is exposed here to allow overriding.
*/
- (void)setUpBannerImageView;

@end
Expand Up @@ -2,50 +2,45 @@
#import "ABKBannerCard.h"
#import "Appboy.h"
#import "ABKImageDelegate.h"

static const CGFloat ImageMinResizingMultiplier = 0.1f;
#import "ABKUIUtils.h"

@implementation ABKBannerContentCardCell

#pragma mark - Properties

- (UIImageView *)bannerImageView {
if (_bannerImageView != nil) {
return _bannerImageView;
}

UIImageView *bannerImageView = [[[self imageViewClass] alloc] init];
bannerImageView.contentMode = UIViewContentModeScaleAspectFit;
bannerImageView.translatesAutoresizingMaskIntoConstraints = NO;
_bannerImageView = bannerImageView;
return bannerImageView;
}

#pragma mark - SetUp

- (void)setUpUI {
[super setUpUI];
[self setUpBannerImageView];
}

#pragma mark BannerImageView

- (void)setUpBannerImageView {
if (!self.bannerImageView) {
self.bannerImageView = [[[self imageViewClass] alloc] init];
self.bannerImageView.contentMode = UIViewContentModeScaleAspectFit;
self.bannerImageView.translatesAutoresizingMaskIntoConstraints = NO;

[self.rootView addSubview:self.bannerImageView];

NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[bannerImageView]-0-|"
options:0
metrics:nil
views:@{@"bannerImageView" : self.bannerImageView}];
[NSLayoutConstraint activateConstraints:horizontalConstraints];
NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[bannerImageView]-0-|"
options:0
metrics:nil
views:@{@"bannerImageView" : self.bannerImageView}];
[NSLayoutConstraint activateConstraints:verticalConstraints];

self.imageRatioConstraint = [NSLayoutConstraint
constraintWithItem:self.bannerImageView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.bannerImageView
attribute:NSLayoutAttributeHeight
multiplier:(355 / 79)
constant:0];
self.imageRatioConstraint.priority = ABKContentCardPriorityLayoutVeryHighButBelowRequired;
self.imageRatioConstraint.active = YES;
}
// Views
[self.rootView addSubview:self.bannerImageView];
[self.rootView bringSubviewToFront:self.unviewedLineView];

// AutoLayout
self.imageRatioConstraint = [self.bannerImageView.heightAnchor constraintEqualToAnchor:self.bannerImageView.widthAnchor];
self.imageRatioConstraint.priority = UILayoutPriorityDefaultHigh;

NSArray *constraints = @[
[self.bannerImageView.topAnchor constraintEqualToAnchor:self.rootView.topAnchor],
[self.bannerImageView.bottomAnchor constraintEqualToAnchor:self.rootView.bottomAnchor],
[self.bannerImageView.leadingAnchor constraintEqualToAnchor:self.rootView.leadingAnchor],
[self.bannerImageView.trailingAnchor constraintEqualToAnchor:self.rootView.trailingAnchor],
self.imageRatioConstraint
];
[NSLayoutConstraint activateConstraints:constraints];
}

#pragma mark - ApplyCard
Expand All @@ -56,8 +51,7 @@ - (void)applyCard:(ABKBannerContentCard *)card {
}

[super applyCard:card];

[self.rootView bringSubviewToFront:self.unviewedLineView];
[self updateImageConstraintIfNeededWithAspectRatio:card.imageAspectRatio];

if (![Appboy sharedInstance].imageDelegate) {
NSLog(@"[APPBOY][WARN] %@ %s",
Expand All @@ -74,41 +68,33 @@ - (void)applyCard:(ABKBannerContentCard *)card {
NSError * _Nullable error,
NSInteger cacheType,
NSURL * _Nullable imageURL) {
if (weakSelf == nil) {
return;
}
if (image && image.size.height > 0.0) {
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat newRatio = image.size.width / image.size.height;
if ([self shouldResizeImageWithNewRatio:newRatio]) {
// Update image size based on actual downloaded image
[weakSelf updateImageConstraintsWithRatio:newRatio];
[weakSelf.delegate refreshTableViewCellHeights];
card.imageAspectRatio = newRatio;
}
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.bannerImageView.image = [weakSelf getPlaceHolderImage];
});
}
dispatch_async(dispatch_get_main_queue(), ^{
typeof(self) __strong strongSelf = weakSelf;
if (strongSelf == nil) {
return;
}

UIImage *finalImage = image != nil ? image : [strongSelf getPlaceHolderImage];
strongSelf.bannerImageView.image = finalImage;

CGFloat aspectRatio = finalImage.size.width / finalImage.size.height;
card.imageAspectRatio = aspectRatio;
[strongSelf updateImageConstraintIfNeededWithAspectRatio:aspectRatio];
});
}];
}

- (void)updateImageConstraintsWithRatio:(CGFloat)newRatio {
if (self.imageRatioConstraint) {
self.imageRatioConstraint.active = NO;
- (void)updateImageConstraintIfNeededWithAspectRatio:(CGFloat)aspectRatio {
if (aspectRatio == 0 || ABK_CGFLT_EQ(self.imageRatioConstraint.multiplier, 1 / aspectRatio)) {
return;
}
self.imageRatioConstraint = [self.bannerImageView.widthAnchor constraintEqualToAnchor:self.bannerImageView.heightAnchor multiplier:newRatio];
self.imageRatioConstraint.active = YES;
[self setNeedsLayout];
}

#pragma mark - Private methods

- (BOOL)shouldResizeImageWithNewRatio:(CGFloat)newRatio {
return self.imageRatioConstraint &&
fabs(newRatio - self.imageRatioConstraint.multiplier) > ImageMinResizingMultiplier;
self.imageRatioConstraint.active = NO;
self.imageRatioConstraint = [self.bannerImageView.heightAnchor constraintEqualToAnchor:self.bannerImageView.widthAnchor
multiplier:1 / aspectRatio];
self.imageRatioConstraint.priority = UILayoutPriorityDefaultHigh;
self.imageRatioConstraint.active = YES;
[self.delegate cellRequestSizeUpdate:self];
}

@end
Expand Up @@ -3,7 +3,7 @@

@protocol ABKBaseContentCardCellDelegate <NSObject>

- (void)refreshTableViewCellHeights;
- (void)cellRequestSizeUpdate:(UITableViewCell *)cell;

@end

Expand Down Expand Up @@ -77,14 +77,6 @@
*/
- (void)setUpUI;

/*!
* @discussion specific view property initialization that is in place of Storyboard or XIB initialization.
* Called by the above setUpUI method and is exposed here to allow overriding.
*/
- (void)setUpRootView;
- (void)setUpPinImageView;
- (void)setUpUnviewedLineView;

/*!
* @discussion This is a utility method to make text styled.
*/
Expand All @@ -93,5 +85,4 @@
@end

static const UILayoutPriority ABKContentCardPriorityLayoutRequiredBelowAppleRequired = UILayoutPriorityRequired - 1;
static const UILayoutPriority ABKContentCardPriorityLayoutVeryHighButBelowRequired = UILayoutPriorityRequired - 2;

0 comments on commit dcd1a23

Please sign in to comment.