Skip to content

Commit

Permalink
v3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
frankus committed Jun 22, 2016
2 parents 199bd72 + cb79bc1 commit 9840620
Show file tree
Hide file tree
Showing 31 changed files with 84 additions and 419 deletions.
5 changes: 3 additions & 2 deletions ApptentiveConnect/source/Apptentive.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

#import <UIKit/UIKit.h>

#define kApptentiveVersionString @"3.1.0"
#define kApptentiveVersionString @"3.1.1"
#define kApptentivePlatformString @"iOS"

NS_ASSUME_NONNULL_BEGIN

@protocol ApptentiveDelegate, ApptentiveStyle;
@protocol ApptentiveDelegate
, ApptentiveStyle;

/** Notification sent when Message Center unread messages count changes. */
extern NSString *const ApptentiveMessageCenterUnreadCountChangedNotification;
Expand Down
2 changes: 1 addition & 1 deletion ApptentiveConnect/source/ApptentiveStyleSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The secondary text color to use in the Apptentive UI. Defaults to #8E8E93.
/// The color to use for the background of collection views and grouped table views.
@property (strong, nonatomic) UIColor *collectionBackgroundColor;

/// The color used for text field placeholder text. The recommended color is the value for `primaryColor` with an alpha value of around 0.22.
/// The color used for text field placeholder text. The recommended color is the value for `primaryColor` with an alpha value of around 0.22.
@property (strong, nonatomic) UIColor *placeholderColor;

/// A global multiplier applied to all font sizes other than those with explicit overrides.
Expand Down
11 changes: 7 additions & 4 deletions ApptentiveConnect/source/ApptentiveStyleSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ - (instancetype)init {

_fontDescriptorOverrides = [NSMutableDictionary dictionary];
_colorOverrides = [NSMutableDictionary dictionary];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
}
return self;
}
Expand All @@ -361,12 +359,12 @@ - (UIColor *)appearanceColorForClass:(Class)klass property:(SEL)propertySelector
return defaultColor;
}

- (void)didBecomeActive:(NSNotification *)notification {
- (void)inheritDefaultColors {
_primaryColor = self.primaryColor ?: [self appearanceColorForClass:[UILabel class] property:@selector(textColor) default:[UIColor blackColor]];
_separatorColor = self.separatorColor ?: [self appearanceColorForClass:[UITableView class] property:@selector(separatorColor) default:[UIColor colorWithRed:199.0 / 255.0 green:200.0 / 255.0 blue:204.0 / 255.0 alpha:1.0]];
_backgroundColor = self.backgroundColor ?: [self appearanceColorForClass:[UITableViewCell class] property:@selector(backgroundColor) default:[UIColor whiteColor]];
_collectionBackgroundColor = self.collectionBackgroundColor ?: [self appearanceColorForClass:[UITableView class] property:@selector(backgroundColor) default:[UIColor groupTableViewBackgroundColor]];
_placeholderColor = self.placeholderColor ?: [UIColor colorWithRed:0 green:0 blue:25.0/255.0 alpha:56.0/255.0];
_placeholderColor = self.placeholderColor ?: [UIColor colorWithRed:0 green:0 blue:25.0 / 255.0 alpha:56.0 / 255.0];
}

- (void)setFontDescriptor:(UIFontDescriptor *)fontDescriptor forStyle:(NSString *)textStyle {
Expand Down Expand Up @@ -452,6 +450,11 @@ - (UIColor *)interpolateAtPoint:(CGFloat)interpolation between:(UIColor *)color1
}

- (UIColor *)colorForStyle:(NSString *)style {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self inheritDefaultColors];
});

UIColor *result = self.colorOverrides[style];

if (result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ - (IBAction)showWho:(id)sender {
self.profileView.skipButton.hidden = NO;
self.profileView.titleLabel.text = self.interaction.profileEditTitle;

NSDictionary *placeholderAttributes = @{ NSForegroundColorAttributeName: [[Apptentive sharedConnection].styleSheet colorForStyle:ApptentiveColorTextInputPlaceholder] };
NSDictionary *placeholderAttributes = @{NSForegroundColorAttributeName: [[Apptentive sharedConnection].styleSheet colorForStyle:ApptentiveColorTextInputPlaceholder]};
self.profileView.nameField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.interaction.profileEditNamePlaceholder attributes:placeholderAttributes];
self.profileView.emailField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.interaction.profileEditEmailPlaceholder attributes:placeholderAttributes];

Expand Down Expand Up @@ -1171,7 +1171,7 @@ - (void)scrollToFooterView:(NSNotification *)notification {
CGFloat verticalOffset = CGRectGetMaxY(self.rectOfLastMessage) + footerSpace;
CGFloat toolbarHeight = self.navigationController.toolbarHidden ? 0 : CGRectGetHeight(self.navigationController.toolbar.bounds);

CGFloat iOS7FudgeFactor = isIOS7 && self.view.window == nil ? topContentInset : 0;
CGFloat iOS7FudgeFactor = isIOS7 && self.view.window == nil ? topContentInset : 0;
CGFloat heightOfVisibleView = fmin(CGRectGetMinY(localKeyboardRect), CGRectGetHeight(self.view.bounds) - toolbarHeight - iOS7FudgeFactor);
CGFloat verticalOffsetMaximum = fmax(-64, self.tableView.contentSize.height - heightOfVisibleView);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(N
layoutAttributes.backgroundColor = [(id<ApptentiveCollectionViewDataSource>)self.collectionView.dataSource backgroundColor];
}

layoutAttributes.frame = UIEdgeInsetsInsetRect(CGRectMake(origin.x, origin.y, size.width, size.height), self.sectionInset );
layoutAttributes.frame = UIEdgeInsetsInsetRect(CGRectMake(origin.x, origin.y, size.width, size.height), self.sectionInset);
layoutAttributes.zIndex = -1;

return layoutAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ @interface ApptentiveSurveyViewController ()
@property (strong, nonatomic) NSIndexPath *editingIndexPath;

@property (readonly, nonatomic) CGFloat lineHeightOfQuestionFont;
@property (assign, nonatomic) BOOL shouldRemoveToolbarInset;
@property (assign, nonatomic) CGFloat iOS9ToolbarInset;

@end

Expand Down Expand Up @@ -191,6 +191,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell

cell.textView.text = [self.viewModel textOfAnswerAtIndexPath:indexPath];
cell.placeholderLabel.attributedText = [self.viewModel placeholderTextOfAnswerAtIndexPath:indexPath];
cell.placeholderLabel.hidden = cell.textView.text.length > 0;
cell.textView.delegate = self;
cell.textView.tag = [self.viewModel textFieldTagForIndexPath:indexPath];
cell.textView.accessibilityLabel = cell.placeholderLabel.text;
Expand Down Expand Up @@ -455,38 +456,7 @@ - (void)textFieldDidEndEditing:(UITextField *)textField {
- (void)viewModelValidationChanged:(ApptentiveSurveyViewModel *)viewModel isValid:(BOOL)valid {
[self.collectionViewLayout invalidateLayout];

CGFloat bottomContentInset = self.collectionView.contentInset.bottom;
CGFloat bottomContentOffset = self.collectionView.contentSize.height - CGRectGetHeight(self.collectionView.bounds) + bottomContentInset;
CGFloat toolbarAdjustment = (valid ? -1 : 1) * CGRectGetHeight(self.navigationController.toolbar.bounds);

[UIView animateWithDuration:0.2 animations:^{
if ( bottomContentInset == 0 && self.collectionView.contentOffset.y >= bottomContentOffset - toolbarAdjustment) {
self.collectionView.contentOffset = CGPointMake(0, bottomContentOffset + toolbarAdjustment);
} else if (bottomContentInset != 0) {
UIEdgeInsets insets = self.collectionView.contentInset;
CGPoint contentOffset = self.collectionView.contentOffset;

if (valid && !self.navigationController.toolbarHidden) {
insets.bottom -= toolbarAdjustment;
}

self.collectionView.contentInset = insets;
self.collectionView.contentOffset = contentOffset;
}
}];

CGPoint contentOffset = self.collectionView.contentOffset;
[self.navigationController setToolbarHidden:valid animated:YES];

// Work around a bug in iOS 9, where if the toolbar is hidden with the keyboard covering it,
// the CV's contentInset property is not adjusted accordingly.
if (valid && bottomContentInset != 0) {
self.shouldRemoveToolbarInset = YES;
} else {
self.shouldRemoveToolbarInset = NO;
}

self.collectionView.contentOffset = contentOffset;
[self setToolbarHidden:valid];

for (UICollectionViewCell *cell in self.collectionView.visibleCells) {
if ([cell isKindOfClass:[ApptentiveSurveyOtherCell class]]) {
Expand All @@ -512,11 +482,12 @@ - (void)adjustForKeyboard:(NSNotification *)notification {
self.collectionView.contentInset = UIEdgeInsetsMake(self.collectionView.contentInset.top, self.collectionView.contentInset.left, CGRectGetHeight(self.collectionView.bounds) - keyboardRect.origin.y, self.collectionView.contentInset.right);

[self.collectionViewLayout invalidateLayout];
} else if (self.shouldRemoveToolbarInset) {
} else if (self.iOS9ToolbarInset != 0) {
// Remove any additional inset we added for hiding the toolbar when the keyboard was visible.
UIEdgeInsets contentInset = self.collectionView.contentInset;
contentInset.bottom -= 44;
contentInset.bottom += self.iOS9ToolbarInset;
self.collectionView.contentInset = contentInset;
self.shouldRemoveToolbarInset = NO;
self.iOS9ToolbarInset = 0;
}

CGFloat duration = ((NSNumber *)notification.userInfo[UIKeyboardAnimationDurationUserInfoKey]).doubleValue;
Expand All @@ -530,7 +501,48 @@ - (void)adjustForKeyboard:(NSNotification *)notification {
}];
}

#pragma mark - Private
#pragma mark - Private

// If the survey is scrolled all the way to the bottom, we want to scroll down as the toolbar animates in
// (and scroll up when it animates out, if necessary).
// There are a lot of pecularities related to OS version and keyboard visibility we have to deal with as well.
- (void)setToolbarHidden:(BOOL)hidden {
CGFloat bottomContentInset = self.collectionView.contentInset.bottom;
BOOL keyboardVisible = bottomContentInset > 0;
CGFloat bottomContentOffset = self.collectionView.contentSize.height - CGRectGetHeight(self.collectionView.bounds) + bottomContentInset;
CGFloat toolbarAdjustment = (hidden ? -1 : 1) * CGRectGetHeight(self.navigationController.toolbar.bounds);
BOOL scrolledAllTheWayDown = self.collectionView.contentOffset.y >= bottomContentOffset - toolbarAdjustment;

[UIView animateWithDuration:0.2 animations:^{
if (!keyboardVisible && scrolledAllTheWayDown) {
self.collectionView.contentOffset = CGPointMake(0, bottomContentOffset + toolbarAdjustment);
} else if (keyboardVisible && hidden) {
// If we're hiding the toolbar with the keyboard visible, we need to add in a bit more bottom inset to keep things from moving around.
UIEdgeInsets insets = self.collectionView.contentInset;
CGPoint contentOffset = self.collectionView.contentOffset;

insets.bottom -= toolbarAdjustment;

// On iOS9, we need to remember to remove that inset once the keyboard is dismissed.
self.iOS9ToolbarInset = toolbarAdjustment;

self.collectionView.contentInset = insets;
self.collectionView.contentOffset = contentOffset;
}
}];

// iOS 7 resets the contentOffset to CGPointZero when the toolbar animation takes place.
// So we have to save off the content offset and set it back after changing toolbar visibility.
// Once we drop iOS 7, all of the following but the call to -setToolbarHidden:animated: can be removed.
CGPoint contentOffset = self.collectionView.contentOffset;
[self.navigationController setToolbarHidden:hidden animated:YES];

if (hidden && !keyboardVisible && scrolledAllTheWayDown) {
contentOffset.y += toolbarAdjustment;
}

self.collectionView.contentOffset = contentOffset;
}

- (void)maybeAnimateOtherSizeChangeAtIndexPath:(NSIndexPath *)indexPath {
if ([self.viewModel typeOfAnswerAtIndexPath:indexPath] == ApptentiveSurveyAnswerTypeOther) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

@class ApptentiveSurvey, ApptentiveInteraction;

@protocol ATSurveyViewModelDelegate, ApptentiveStyle;
@protocol ATSurveyViewModelDelegate
, ApptentiveStyle;


@interface ApptentiveSurveyViewModel : NSObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ - (NSAttributedString *)placeholderTextOfAnswerAtIndexPath:(NSIndexPath *)indexP
placeholder = [self answerAtIndexPath:indexPath].placeholder ?: @"";
}

return [[NSAttributedString alloc] initWithString:placeholder attributes:@{ NSForegroundColorAttributeName: [self.styleSheet colorForStyle:ApptentiveColorTextInputPlaceholder] }];
return [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName: [self.styleSheet colorForStyle:ApptentiveColorTextInputPlaceholder]}];
}

- (NSString *)textOfChoiceAtIndexPath:(NSIndexPath *)indexPath {
Expand Down Expand Up @@ -302,7 +302,7 @@ - (BOOL)validate:(BOOL)isSubmit {
self.invalidQuestionIndexes = redToGreenQuestionIndexes;

NSMutableSet *redToGreenAnswerIndexPaths = [self.invalidAnswerIndexPaths mutableCopy];
[self.invalidAnswerIndexPaths enumerateObjectsUsingBlock:^(id _Nonnull obj, BOOL * _Nonnull stop) {
[self.invalidAnswerIndexPaths enumerateObjectsUsingBlock:^(id _Nonnull obj, BOOL *_Nonnull stop) {
if (![previousInvalidAnswerIndexPaths containsObject:obj]) {
[redToGreenAnswerIndexPaths removeObject:obj];
}
Expand Down Expand Up @@ -427,7 +427,7 @@ - (NSDictionary *)responseDictionaryForAnswerAtIndexPath:(NSIndexPath *)indexPat
response[@"value"] = [self trimmedTextAtIndexPath:indexPath] ?: @"";
}
}

return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "ApptentiveSurveyChoiceCell.h"


@interface ApptentiveSurveyOtherCell : ApptentiveSurveyChoiceCell

@property (strong, nonatomic) IBOutlet UITextField *textField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "ApptentiveSurveyOtherCell.h"


@implementation ApptentiveSurveyOtherCell

- (void)awakeFromNib {
Expand Down
5 changes: 0 additions & 5 deletions ApptentiveConnect/tests/ApptentiveStyleSheetTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ - (void)testUIAppearanceDefaults {
[UITableView appearance].separatorColor = [UIColor redColor];
[UITableView appearanceWhenContainedIn:[ApptentiveNavigationController class], nil].backgroundColor = [UIColor greenColor];

XCTAssertNotEqualObjects([self.styleSheet colorForStyle:ApptentiveColorSeparator], [UIColor redColor]);
XCTAssertNotEqualObjects([self.styleSheet colorForStyle:ApptentiveColorCollectionBackground], [UIColor greenColor]);

[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidBecomeActiveNotification object:nil];

XCTAssertEqualObjects([self.styleSheet colorForStyle:ApptentiveColorSeparator], [UIColor redColor]);
XCTAssertEqualObjects([self.styleSheet colorForStyle:ApptentiveColorCollectionBackground], [UIColor greenColor]);
}
Expand Down
18 changes: 7 additions & 11 deletions ApptentiveConnect/tests/ApptentiveSurveyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ - (void)setUp {
self.answeredQuestions = [NSMutableSet set];
self.deselectedIndexPaths = [NSMutableSet set];

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
[self.viewModel.styleSheet performSelector:@selector(didBecomeActive:) withObject:nil];
#pragma clang diagnostic pop

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(answeredQuestion:) name:ATSurveyDidAnswerQuestionNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didHide:) name:ATSurveyDidHideWindowNotification object:nil];
}
Expand Down Expand Up @@ -187,13 +182,14 @@ - (void)testAnswers {
[self.viewModel setText:@" Foo " forAnswerAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:7]];
[self.viewModel setText:@" Bar\n" forAnswerAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:9]];

NSDictionary *answer = @{ @"id": @"56d49499c719925f3300000b", @"value": @"Other Text" };
XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f3300000b"], @[ answer ]);
XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f33000011"], @[ @{ @"id": @"56d49499c719925f33000012" }]);
XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f33000019"], @[ @{ @"id": @"56d49499c719925f3300001a" }] );
NSDictionary *answer = @{ @"id": @"56d49499c719925f3300000b",
@"value": @"Other Text" };
XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f3300000b"], @[answer]);
XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f33000011"], @[@{ @"id": @"56d49499c719925f33000012" }]);
XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f33000019"], @[@{ @"id": @"56d49499c719925f3300001a" }]);

XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f3300001f"], @[ @{ @"value": @"Foo" } ]);
XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f33000021"], @[ @{ @"value": @"Bar" } ]);
XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f3300001f"], @[@{ @"value": @"Foo" }]);
XCTAssertEqualObjects(self.viewModel.answers[@"56d49499c719925f33000021"], @[@{ @"value": @"Bar" }]);
}

- (void)testMetrics {
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2016-06-21 frankus v3.1.1
-------------------------
Version 3.1.1 fixes an issue where surveys could crash if the Apptentive
singleton was instantiated after the app became active. It also improves the
scrolling behavior in surveys.

2016-06-08 frankus v3.1.0
-------------------------
Version 3.1.0 adds the ability to include a freeform "Other" choice for single-
Expand Down
4 changes: 0 additions & 4 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
014B260D1CD16F72009BE289 /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = 019958D31CD13A320044A185 /* Defaults.plist */; };
014B26111CD27D67009BE289 /* CustomDataCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014B26101CD27D67009BE289 /* CustomDataCell.swift */; };
014B26131CD2994B009BE289 /* ConnectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014B26121CD2994B009BE289 /* ConnectionViewController.swift */; };
018C24C71CD3F90B00AC8276 /* Mocks in Resources */ = {isa = PBXBuildFile; fileRef = 018C24C61CD3F90B00AC8276 /* Mocks */; };
019959021CD15DFA0044A185 /* EventsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019959011CD15DFA0044A185 /* EventsViewController.swift */; };
019959041CD15E180044A185 /* InteractionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019959031CD15E180044A185 /* InteractionsViewController.swift */; };
019959061CD15E2A0044A185 /* MessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019959051CD15E2A0044A185 /* MessagesViewController.swift */; };
Expand Down Expand Up @@ -77,7 +76,6 @@
014B26101CD27D67009BE289 /* CustomDataCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomDataCell.swift; sourceTree = "<group>"; };
014B26121CD2994B009BE289 /* ConnectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionViewController.swift; sourceTree = "<group>"; };
018C24C51CD3F82500AC8276 /* iOSDemoUITests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "iOSDemoUITests-Bridging-Header.h"; sourceTree = "<group>"; };
018C24C61CD3F90B00AC8276 /* Mocks */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Mocks; sourceTree = "<group>"; };
019958CE1CD1375A0044A185 /* Apptentive.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Apptentive.h; path = ../../ApptentiveConnect/source/Apptentive.h; sourceTree = "<group>"; };
019958CF1CD137640044A185 /* Apptentive_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Apptentive_Private.h; path = ../../ApptentiveConnect/source/Apptentive_Private.h; sourceTree = "<group>"; };
019958D01CD137CA0044A185 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -188,7 +186,6 @@
01FA581E1CD03B7800CF132B /* iOSDemoUITests */ = {
isa = PBXGroup;
children = (
018C24C61CD3F90B00AC8276 /* Mocks */,
01FA581F1CD03B7800CF132B /* iOSDemoUITests.swift */,
01FA58211CD03B7800CF132B /* Info.plist */,
018C24C51CD3F82500AC8276 /* iOSDemoUITests-Bridging-Header.h */,
Expand Down Expand Up @@ -321,7 +318,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
018C24C71CD3F90B00AC8276 /* Mocks in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
17 changes: 0 additions & 17 deletions Demo/iOSDemo/AppDelegate.h

This file was deleted.

Loading

0 comments on commit 9840620

Please sign in to comment.