More addcardvc fixes/changes
* Address cell placeholders are now what used to be captions instead of examples. No more permanent captions to conserve horizontal space (and match Contacts.app address entry) * Have remember me footer view size itself correctly and update UI test to capture it properly.
|
@ -63,6 +63,10 @@
|
|||
@property(nonatomic)STPCard *checkoutAccountCard;
|
||||
@property(nonatomic)BOOL lookupSucceeded;
|
||||
@property(nonatomic)STPRememberMeTermsView *rememberMeTermsView;
|
||||
@property(nonatomic)BOOL showingRememberMePhoneAndTerms;
|
||||
#if DEBUG
|
||||
@property(nonatomic)BOOL forceEnableRememberMeForTesting;
|
||||
#endif
|
||||
@end
|
||||
|
||||
static NSString *const STPPaymentCardCellReuseIdentifier = @"STPPaymentCardCellReuseIdentifier";
|
||||
|
@ -208,6 +212,7 @@ static NSInteger STPPaymentCardRememberMeSection = 3;
|
|||
self.rememberMeCell.theme = self.theme;
|
||||
self.rememberMePhoneCell.theme = self.theme;
|
||||
self.rememberMeTermsView.theme = self.theme;
|
||||
[self reloadRememberMeSectionForFooterSizeChangeIfNecessary];
|
||||
[self setNeedsStatusBarAppearanceUpdate];
|
||||
}
|
||||
|
||||
|
@ -220,6 +225,20 @@ static NSInteger STPPaymentCardRememberMeSection = 3;
|
|||
- (void)viewDidLayoutSubviews {
|
||||
[super viewDidLayoutSubviews];
|
||||
self.tableView.frame = self.view.bounds;
|
||||
[self reloadRememberMeSectionForFooterSizeChangeIfNecessary];
|
||||
}
|
||||
|
||||
- (void)reloadRememberMeSectionForFooterSizeChangeIfNecessary {
|
||||
|
||||
if (self.showingRememberMePhoneAndTerms
|
||||
&& self.rememberMeTermsView.superview != nil) {
|
||||
|
||||
// This should force the table to recalc all of its heights
|
||||
// And therefore render the footer appropriately if its height changed
|
||||
[self.tableView beginUpdates];
|
||||
[self.tableView endUpdates];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setLoading:(BOOL)loading {
|
||||
|
@ -323,7 +342,7 @@ static NSInteger STPPaymentCardRememberMeSection = 3;
|
|||
} else {
|
||||
NSString *phone = self.rememberMePhoneCell.contents;
|
||||
NSString *email = self.emailCell.contents;
|
||||
BOOL rememberMeSelected = [STPEmailAddressValidator stringIsValidEmailAddress:email] && [STPPhoneNumberValidator stringIsValidPhoneNumber:phone] && self.rememberMeCell.on;
|
||||
BOOL rememberMeSelected = [STPEmailAddressValidator stringIsValidEmailAddress:email] && [STPPhoneNumberValidator stringIsValidPhoneNumber:phone] && self.showingRememberMePhoneAndTerms;
|
||||
[[STPAnalyticsClient sharedClient] logRememberMeConversion:rememberMeSelected];
|
||||
if (rememberMeSelected) {
|
||||
[self.checkoutAPIClient createAccountWithCardParams:cardParams email:email phone:phone];
|
||||
|
@ -498,7 +517,9 @@ static NSInteger STPPaymentCardRememberMeSection = 3;
|
|||
// this is the email cell; do nothing.
|
||||
}
|
||||
|
||||
- (void)switchTableViewCell:(STPSwitchTableViewCell *)cell didToggleSwitch:(BOOL)on {
|
||||
- (void)switchTableViewCell:(__unused STPSwitchTableViewCell *)cell didToggleSwitch:(BOOL)on {
|
||||
self.showingRememberMePhoneAndTerms = on;
|
||||
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1
|
||||
inSection:STPPaymentCardRememberMeSection];
|
||||
[self.tableView beginUpdates];
|
||||
|
@ -508,7 +529,7 @@ static NSInteger STPPaymentCardRememberMeSection = 3;
|
|||
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
|
||||
}
|
||||
[self.tableView endUpdates];
|
||||
|
||||
|
||||
[UIView animateWithDuration:0.1 animations:^{
|
||||
self.rememberMeTermsView.textView.alpha = on ? 1.0f : 0.0f;
|
||||
}];
|
||||
|
@ -524,8 +545,27 @@ static NSInteger STPPaymentCardRememberMeSection = 3;
|
|||
|
||||
#pragma mark - UITableView
|
||||
|
||||
#if DEBUG
|
||||
- (void)setForceEnableRememberMeForTesting:(BOOL)forceEnableRememberMeForTesting {
|
||||
// force view load
|
||||
__unused UIView *view = self.view;
|
||||
|
||||
[self.tableView setNeedsLayout];
|
||||
[self.tableView layoutIfNeeded];
|
||||
_forceEnableRememberMeForTesting = forceEnableRememberMeForTesting;
|
||||
[self reloadRememberMeCellAnimated:NO];
|
||||
self.rememberMeCell.on = forceEnableRememberMeForTesting;
|
||||
[self switchTableViewCell:self.rememberMeCell didToggleSwitch:forceEnableRememberMeForTesting];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)reloadRememberMeCellAnimated:(BOOL)animated {
|
||||
BOOL disabled = (!self.checkoutAPIClient.readyForLookups || self.checkoutAccount || self.configuration.smsAutofillDisabled || self.lookupSucceeded || self.managedAccountCurrency) && (self.rememberMePhoneCell.contentView.alpha < FLT_EPSILON || self.rememberMePhoneCell.superview == nil);
|
||||
#if DEBUG
|
||||
if (self.forceEnableRememberMeForTesting) {
|
||||
disabled = NO;
|
||||
}
|
||||
#endif
|
||||
[UIView animateWithDuration:(0.2f * animated) animations:^{
|
||||
self.rememberMeCell.contentView.alpha = disabled ? 0 : 1;
|
||||
} completion:^(__unused BOOL finished) {
|
||||
|
@ -549,7 +589,7 @@ static NSInteger STPPaymentCardRememberMeSection = 3;
|
|||
} else if (section == STPPaymentCardBillingAddressSection) {
|
||||
return self.addressViewModel.addressCells.count;
|
||||
} else if (section == STPPaymentCardRememberMeSection) {
|
||||
return self.rememberMeCell.on ? 2 : 1;
|
||||
return self.showingRememberMePhoneAndTerms ? 2 : 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -588,8 +628,9 @@ static NSInteger STPPaymentCardRememberMeSection = 3;
|
|||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
|
||||
if (section == STPPaymentCardRememberMeSection) {
|
||||
return 140.0f;
|
||||
if (section == STPPaymentCardRememberMeSection
|
||||
&& self.showingRememberMePhoneAndTerms) {
|
||||
return [self.rememberMeTermsView heightForWidth:CGRectGetWidth(self.tableView.frame)];
|
||||
} else if ([self tableView:tableView numberOfRowsInSection:section] == 0) {
|
||||
return 0.01f;
|
||||
}
|
||||
|
@ -632,10 +673,12 @@ static NSInteger STPPaymentCardRememberMeSection = 3;
|
|||
}
|
||||
|
||||
- (UIView *)tableView:(__unused UITableView *)tableView viewForFooterInSection:(NSInteger)section {
|
||||
if (section != STPPaymentCardRememberMeSection) {
|
||||
if (section == STPPaymentCardRememberMeSection) {
|
||||
return self.rememberMeTermsView;
|
||||
}
|
||||
else {
|
||||
return [UIView new];
|
||||
}
|
||||
return self.rememberMeTermsView;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
@interface STPAddressFieldTableViewCell() <STPFormTextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource>
|
||||
|
||||
@property(nonatomic, weak) UILabel *captionLabel;
|
||||
@property(nonatomic, weak) STPFormTextField *textField;
|
||||
@property(nonatomic) UIToolbar *inputAccessoryToolbar;
|
||||
@property(nonatomic) UIPickerView *countryPickerView;
|
||||
|
@ -38,10 +37,6 @@
|
|||
_theme = [STPTheme new];
|
||||
_contents = contents;
|
||||
|
||||
UILabel *captionLabel = [UILabel new];
|
||||
_captionLabel = captionLabel;
|
||||
[self.contentView addSubview:captionLabel];
|
||||
|
||||
STPFormTextField *textField = [[STPFormTextField alloc] init];
|
||||
textField.formDelegate = self;
|
||||
textField.autoFormattingBehavior = STPFormTextFieldAutoFormattingBehaviorNone;
|
||||
|
@ -105,7 +100,6 @@
|
|||
}
|
||||
|
||||
- (void)updateTextFieldsAndCaptions {
|
||||
self.captionLabel.text = [self captionForAddressField:self.type];
|
||||
self.textField.placeholder = [self placeholderForAddressField:self.type];
|
||||
switch (self.type) {
|
||||
case STPAddressFieldTypeName:
|
||||
|
@ -169,7 +163,7 @@
|
|||
break;
|
||||
|
||||
}
|
||||
self.textField.accessibilityLabel = self.captionLabel.text;
|
||||
self.textField.accessibilityLabel = self.textField.placeholder;
|
||||
}
|
||||
|
||||
+ (NSString *)stateFieldCaptionForCountryCode:(NSString *)countryCode {
|
||||
|
@ -183,11 +177,11 @@
|
|||
return STPLocalizedString(@"County", @"Caption for County field on address form (only countries that use county, like United Kingdom)");
|
||||
}
|
||||
else {
|
||||
return STPLocalizedString(@"State / Region", @"Caption for generalized state/province/region field on address form (not tied to a specific country's format)");
|
||||
return STPLocalizedString(@"State / Province/ Region", @"Caption for generalized state/province/region field on address form (not tied to a specific country's format)");
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)captionForAddressField:(STPAddressFieldType)addressFieldType {
|
||||
- (NSString *)placeholderForAddressField:(STPAddressFieldType)addressFieldType {
|
||||
switch (addressFieldType) {
|
||||
case STPAddressFieldTypeName:
|
||||
return STPLocalizedString(@"Name", @"Caption for Name field on address form");
|
||||
|
@ -212,33 +206,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (NSString *)placeholderForAddressField:(STPAddressFieldType)addressFieldType {
|
||||
if (![self countryCodeIsUnitedStates]) {
|
||||
// not currently localizing placeholders for non-US regions
|
||||
return nil;
|
||||
}
|
||||
switch (addressFieldType) {
|
||||
case STPAddressFieldTypeName:
|
||||
return STPLocalizedString(@"John Appleseed", @"Placeholder for Name field on address form");
|
||||
case STPAddressFieldTypeLine1:
|
||||
return STPLocalizedString(@"123 Address St", @"Placeholder for Address field on address form");
|
||||
case STPAddressFieldTypeLine2:
|
||||
return STPLocalizedString(@"#23", @"Placeholder for Apartment/Address line 2 on address form");
|
||||
case STPAddressFieldTypeCity:
|
||||
return @"San Francisco"; // Intentionally not translated
|
||||
case STPAddressFieldTypeState:
|
||||
return @"CA"; // Intentionally not translated
|
||||
case STPAddressFieldTypeZip:
|
||||
return @"12345"; // Intentionally not translated
|
||||
case STPAddressFieldTypeCountry:
|
||||
return nil;
|
||||
case STPAddressFieldTypeEmail:
|
||||
return STPLocalizedString(@"you@example.com", @"Placeholder for Email field on address form");
|
||||
case STPAddressFieldTypePhone:
|
||||
return STPLocalizedString(@"(555) 123-1234", @"Placeholder for Phone field on address form");
|
||||
}
|
||||
}
|
||||
|
||||
- (void)delegateCountryCodeDidChange:(NSString *)countryCode {
|
||||
self.ourCountryCode = countryCode;
|
||||
_postalCodeType = [STPPostalCodeValidator postalCodeTypeForCountryCode:self.ourCountryCode];
|
||||
|
@ -249,8 +216,6 @@
|
|||
- (void)updateAppearance {
|
||||
self.contentView.backgroundColor = self.theme.secondaryBackgroundColor;
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.captionLabel.font = self.theme.font;
|
||||
self.captionLabel.textColor = self.theme.secondaryForegroundColor;
|
||||
self.textField.placeholderColor = self.theme.tertiaryForegroundColor;
|
||||
self.textField.defaultColor = self.theme.primaryForegroundColor;
|
||||
self.textField.errorColor = self.theme.errorColor;
|
||||
|
@ -262,33 +227,9 @@
|
|||
return [self.ourCountryCode isEqualToString:@"US"];
|
||||
}
|
||||
|
||||
- (NSString *)longestPossibleCaption {
|
||||
NSString *longestCaption = @"";
|
||||
NSArray *addressFieldTypes = @[@(STPAddressFieldTypeName),
|
||||
@(STPAddressFieldTypeLine1),
|
||||
@(STPAddressFieldTypeLine2),
|
||||
@(STPAddressFieldTypeCity),
|
||||
@(STPAddressFieldTypeState),
|
||||
@(STPAddressFieldTypeZip),
|
||||
@(STPAddressFieldTypeCountry),
|
||||
@(STPAddressFieldTypeEmail),
|
||||
@(STPAddressFieldTypePhone),
|
||||
];
|
||||
for (NSNumber *addressFieldType in addressFieldTypes) {
|
||||
NSString *caption = [self captionForAddressField:[addressFieldType integerValue]];
|
||||
if ([caption length] > [longestCaption length]) {
|
||||
longestCaption = caption;
|
||||
}
|
||||
}
|
||||
return longestCaption;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
NSDictionary *attributes = @{ NSFontAttributeName: self.theme.font };
|
||||
CGFloat captionWidth = [[self longestPossibleCaption] sizeWithAttributes:attributes].width + 5;
|
||||
self.captionLabel.frame = CGRectMake(15, 0, captionWidth, self.bounds.size.height);
|
||||
CGFloat textFieldX = CGRectGetMaxX(self.captionLabel.frame) + 10;
|
||||
CGFloat textFieldX = 15;
|
||||
self.textField.frame = CGRectMake(textFieldX, 1, self.bounds.size.width - textFieldX, self.bounds.size.height - 1);
|
||||
self.inputAccessoryToolbar.frame = CGRectMake(0, 0, self.bounds.size.width, 44);
|
||||
}
|
||||
|
@ -333,11 +274,11 @@
|
|||
}
|
||||
|
||||
- (void)setCaption:(NSString *)caption {
|
||||
self.captionLabel.text = caption;
|
||||
self.textField.placeholder = caption;
|
||||
}
|
||||
|
||||
- (NSString *)caption {
|
||||
return self.captionLabel.text;
|
||||
return self.textField.placeholder;
|
||||
}
|
||||
|
||||
- (void)setContents:(NSString *)contents {
|
||||
|
|
|
@ -19,6 +19,8 @@ typedef void(^STPRememberMeTermsPushVCBlock)(UIViewController *vc);
|
|||
@property(nonatomic)UIEdgeInsets insets;
|
||||
@property (nonatomic, copy)STPRememberMeTermsPushVCBlock pushViewControllerBlock;
|
||||
|
||||
- (CGFloat)heightForWidth:(CGFloat)maxWidth;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -118,11 +118,23 @@ static NSString *const FooterLinkTagMoreInfo = @"infolink";
|
|||
};
|
||||
}
|
||||
|
||||
- (CGFloat)heightForWidth:(CGFloat)maxWidth {
|
||||
CGFloat availableWidth = maxWidth - (self.insets.left + self.insets.right);
|
||||
return ([self.textView sizeThatFits:CGSizeMake(availableWidth, CGFLOAT_MAX)].height
|
||||
+ self.insets.top
|
||||
+ self.insets.bottom);
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
self.textView.frame = UIEdgeInsetsInsetRect(self.bounds, self.insets);
|
||||
}
|
||||
|
||||
- (void)setInsets:(UIEdgeInsets)insets {
|
||||
_insets = insets;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
|
||||
if (self.pushViewControllerBlock) {
|
||||
STPWebViewController *webViewController = [[STPWebViewController alloc] initWithURL:URL
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
@interface STPSwitchTableViewCell : UITableViewCell
|
||||
|
||||
@property(nonatomic, readonly)BOOL on;
|
||||
@property(nonatomic)BOOL on;
|
||||
@property(nonatomic)STPTheme *theme;
|
||||
|
||||
- (void)configureWithLabel:(NSString *)label
|
||||
|
|
|
@ -83,4 +83,8 @@
|
|||
return self.switchView.on;
|
||||
}
|
||||
|
||||
|
||||
- (void)setOn:(BOOL)on {
|
||||
self.switchView.on = on;
|
||||
}
|
||||
@end
|
||||
|
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 117 KiB |
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 107 KiB |
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 130 KiB |
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 124 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 119 KiB |
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 134 KiB |
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 125 KiB |
|
@ -8,11 +8,17 @@
|
|||
|
||||
#import <FBSnapshotTestCase/FBSnapshotTestCase.h>
|
||||
#import <Stripe/Stripe.h>
|
||||
#import "STPSwitchTableViewCell.h"
|
||||
|
||||
@interface STPAddCardViewControllerLocalizationTests : FBSnapshotTestCase
|
||||
|
||||
@end
|
||||
|
||||
@interface STPAddCardViewController (TestsPrivate)
|
||||
@property(nonatomic) UITableView *tableView;
|
||||
@property(nonatomic)BOOL forceEnableRememberMeForTesting;
|
||||
@end
|
||||
|
||||
@implementation STPAddCardViewControllerLocalizationTests
|
||||
|
||||
//- (void)setUp {
|
||||
|
@ -38,7 +44,10 @@
|
|||
UINavigationController *navController = [UINavigationController new];
|
||||
navController.view.frame = CGRectMake(0, 0, 320, 750);
|
||||
[navController pushViewController:addCardVC animated:NO];
|
||||
|
||||
addCardVC.forceEnableRememberMeForTesting = YES;
|
||||
[navController.view layoutIfNeeded];
|
||||
navController.view.frame = CGRectMake(0, 0, 320, addCardVC.tableView.contentSize.height);
|
||||
|
||||
FBSnapshotVerifyView(navController.view, nil)
|
||||
|
||||
[STPLocalizationUtils overrideLanguageTo:nil];
|
||||
|
|