This repository has been archived by the owner on May 6, 2024. It is now read-only.
/
OEXRegistrationViewController.m
544 lines (455 loc) · 23.7 KB
/
OEXRegistrationViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
//
// OEXRegistrationViewController.m
// edXVideoLocker
//
// Created by Jotiram Bhagat on 13/02/15.
// Copyright (c) 2015 edX. All rights reserved.
//
#import "OEXRegistrationViewController.h"
#import <Masonry/Masonry.h>
#import "edX-Swift.h"
#import "Logger+OEXObjC.h"
#import "NSArray+OEXFunctional.h"
#import "NSError+OEXKnownErrors.h"
#import "NSJSONSerialization+OEXSafeAccess.h"
#import "OEXAuthentication.h"
#import "OEXExternalAuthProvider.h"
#import "OEXExternalRegistrationOptionsView.h"
#import "OEXFacebookAuthProvider.h"
#import "OEXFacebookConfig.h"
#import "OEXGoogleAuthProvider.h"
#import "OEXGoogleConfig.h"
#import "OEXHTTPStatusCodes.h"
#import "OEXRegistrationDescription.h"
#import "OEXRegistrationFieldError.h"
#import "OEXRegistrationFormField.h"
#import "OEXRegistrationStyles.h"
#import "OEXRegisteringUserDetails.h"
#import "OEXUserLicenseAgreementViewController.h"
#import "OEXUsingExternalAuthHeadingView.h"
#import "OEXRegistrationAgreement.h"
NSString* const OEXExternalRegistrationWithExistingAccountNotification = @"OEXExternalRegistrationWithExistingAccountNotification";
@interface OEXRegistrationViewController () <OEXExternalRegistrationOptionsViewDelegate, AgreementTextViewDelegate>
/// Contents are id <OEXRegistrationFieldController>
@property (strong, nonatomic) NSArray* fieldControllers;
@property (strong, nonatomic) IBOutlet UIScrollView* scrollView;
// Used in auth from an external provider
@property (strong, nonatomic) UIView* currentHeadingView;
@property (strong, nonatomic) id <OEXExternalAuthProvider> externalProvider;
@property (copy, nonatomic) NSString* externalAccessToken;
@property (strong, nonatomic) UIButton* registerButton;
@property (strong, nonatomic) AgreementTextView* agreementTextView;
@property (strong, nonatomic) UIButton* toggleOptionalFieldsButton;
@property (strong, nonatomic) UIImageView* optionalFieldsSeparator;
@property (strong, nonatomic) UIActivityIndicatorView* progressIndicator;
@property (assign, nonatomic) BOOL isShowingOptionalFields;
@property (strong, nonatomic) OEXRegistrationStyles* styles;
@property (strong, nonatomic) OEXTextStyle *toggleButtonStyle;
@end
@implementation OEXRegistrationViewController
- (id)initWithEnvironment:(RouterEnvironment *)environment {
self = [super initWithNibName:nil bundle:nil];
if(self != nil) {
self.environment = environment;
self.styles = [[OEXRegistrationStyles alloc] init];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.agreementTextView = [[AgreementTextView alloc] init];
self.loadController = [[LoadStateViewController alloc] init];
[self.loadController setupInControllerWithController:self contentView:self.scrollView];
self.navigationController.navigationBarHidden = NO;
[self setTitle:[Strings registerText]];
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_cancel"] style:UIBarButtonItemStylePlain target:self action:@selector(navigateBack:)];
closeButton.accessibilityLabel = [Strings close];
closeButton.accessibilityIdentifier = @"RegistrationViewController:close-button";
self.navigationItem.leftBarButtonItem = closeButton;
//By default we only shows required fields
self.isShowingOptionalFields = NO;
self.toggleButtonStyle = [[OEXTextStyle alloc] initWithWeight:OEXTextWeightNormal size:OEXTextSizeBase color:[[OEXStyles sharedStyles] neutralDark]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(formFieldValueDidChange:) name:NOTIFICATION_REGISTRATION_FORM_FIELD_VALUE_DID_CHANGE object:nil];
[self getFormFields];
[self setAccessibilityIdentifiers];
}
//set accessibility identifiers for the developer automation use
- (void)setAccessibilityIdentifiers {
self.registerButton.accessibilityIdentifier = @"RegistrationViewController:register-button";
self.agreementTextView.accessibilityIdentifier = @"RegistrationViewController:agreement-text-view";
self.toggleOptionalFieldsButton.accessibilityIdentifier = @"RegistrationViewController:toggle-optional-field-button";
self.optionalFieldsSeparator.accessibilityIdentifier = @"RegistrationViewController:toggle-optional-field-separator-image-view";
self.progressIndicator.accessibilityIdentifier = @"RegistrationViewController:progress-indicator";
self.currentHeadingView.accessibilityIdentifier = @"RegistrationViewController:current-heading-view";
}
-(void)formFieldValueDidChange: (NSNotification *)notification {
[self refreshFormFields];
}
- (void)getFormFields {
__weak typeof(self) weakSelf = self;
[self getRegistrationFormDescriptionWithSuccess:^(OEXRegistrationDescription * _Nonnull response) {
weakSelf.registrationDescription = response;
[weakSelf makeFieldControllers];
[weakSelf initializeViews];
[weakSelf refreshFormFields];
}];
}
//Currently using asset file only to get from description
- (void)makeFieldControllers {
NSArray* fields = self.registrationDescription.registrationFormFields;
self.fieldControllers = [fields oex_map:^id < OEXRegistrationFieldController > (OEXRegistrationFormField* formField)
{
if(formField.fieldType != OEXRegistrationFieldTypeAgreement) {
id <OEXRegistrationFieldController> fieldController = [RegistrationFieldControllerFactory registrationControllerOf:formField];
return fieldController;
}
return nil;
}];
}
// This method will set default ui.
- (void)initializeViews {
////Create and initalize 'btnCreateAccount' button
self.registerButton = [[UIButton alloc] init];
[self.registerButton oex_addAction:^(id _Nonnull control) {
[self createAccount:nil];
} forEvents:UIControlEventTouchUpInside];
[self.registerButton applyButtonStyleWithStyle:[self.environment.styles filledPrimaryButtonStyle] withTitle:[Strings registrationCreateMyAccount]];
self.registerButton.accessibilityIdentifier = @"register";
////Create progrssIndicator as subview to btnCreateAccount
self.progressIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[self.registerButton addSubview:self.progressIndicator];
[self.progressIndicator hidesWhenStopped];
self.optionalFieldsSeparator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"separator3"]];
[self setUpAgreementTextView];
//This button will show and hide optional fields
self.toggleOptionalFieldsButton = [[UIButton alloc] init];
[self.toggleOptionalFieldsButton setBackgroundColor:[UIColor whiteColor]];
[self.toggleOptionalFieldsButton setAttributedTitle: [self.toggleButtonStyle attributedStringWithText:[Strings registrationShowOptionalFields]] forState:UIControlStateNormal];
[self.toggleOptionalFieldsButton addTarget:self action:@selector(toggleOptionalFields:) forControlEvents:UIControlEventTouchUpInside];
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] init];
[tapGesture addTarget:self action:@selector(scrollViewTapped:)];
[self.scrollView addGestureRecognizer:tapGesture];
NSMutableArray* providers = [[NSMutableArray alloc] init];
if(self.environment.config.googleConfig.enabled) {
[providers addObject:[[OEXGoogleAuthProvider alloc] init]];
}
if(self.environment.config.facebookConfig.enabled) {
[providers addObject:[[OEXFacebookAuthProvider alloc] init]];
}
if(providers.count > 0) {
OEXExternalRegistrationOptionsView* headingView = [[OEXExternalRegistrationOptionsView alloc] initWithFrame:CGRectZero providers:providers];
headingView.delegate = self;
[self useHeadingView:headingView];
}
}
-(void) setUpAgreementTextView {
[self.agreementTextView setupFor:AgreementTypeSignUp];
self.agreementTextView.agreementDelegate = self;
CGSize size = [self.agreementTextView sizeThatFits:CGSizeMake(self.scrollView.frame.size.width - 2 * self.styles.formMargin, CGFLOAT_MAX)];
self.agreementTextView.frame = CGRectMake(0, 0, size.width, size.height + [[OEXStyles sharedStyles] standardHorizontalMargin]);;
}
// MARK: AgreementTextViewDelegate
- (void)agreementTextView:(AgreementTextView *)textView didSelect:(NSURL *)url {
OEXUserLicenseAgreementViewController* viewController = [[OEXUserLicenseAgreementViewController alloc] initWithContentURL:url];
[self presentViewController:viewController animated:YES completion:nil];
}
- (void)useHeadingView:(UIView*)headingView {
[self.currentHeadingView removeFromSuperview];
self.currentHeadingView = headingView;
[self.scrollView addSubview:self.currentHeadingView];
[self.view setNeedsUpdateConstraints];
[self.view setNeedsLayout];
}
- (IBAction)navigateBack:(id)sender {
[self.view endEditing:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Scrolling on keyboard hide and show
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardFrameChanged:)
name:UIKeyboardWillChangeFrameNotification object:nil];
//Analytics Screen record
[self.environment.analytics trackScreenWithName:OEXAnalyticsScreenRegister];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
// This will remove observer for keyboard
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (BOOL)shouldFilterField:(OEXRegistrationFormField*)field {
return self.externalProvider != nil && [field.name isEqualToString:@"password"];
}
- (void)refreshFormFields {
for(id <OEXRegistrationFieldController>fieldController in self.fieldControllers) {
// Add view to scroll view if field is not optional and it is not agreement field.
UIView* view = fieldController.view;
if(fieldController.field.isRequired && ![self shouldFilterField:fieldController.field]) {
[self.scrollView addSubview:view];
[view setNeedsLayout];
[view layoutIfNeeded];
}
else {
[view removeFromSuperview];
}
}
// Actually show the optional fields if necessary
if(self.isShowingOptionalFields) {
for(id <OEXRegistrationFieldController>fieldController in self.fieldControllers) {
if(![fieldController field].isRequired && ![self shouldFilterField:fieldController.field]) {
UIView* view = fieldController.view;
[self.scrollView addSubview:view];
[view setNeedsLayout];
[view layoutIfNeeded];
}
}
}
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
[self viewDidLayoutSubviews];
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
}
- (void)updateViewConstraints {
CGFloat margin = self.styles.formMargin;
[self.currentHeadingView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.scrollView);
make.centerX.equalTo(self.scrollView);
make.width.equalTo(self.scrollView).offset(-2 * margin);
}];
[super updateViewConstraints];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// Add space if the heading view won't do it for us
NSInteger topSpacing = self.currentHeadingView == nil ? 10 : 0;
NSInteger horizontalSpacing = self.styles.formMargin;
NSInteger offset = 0;
CGFloat width = self.scrollView.frame.size.width;
NSInteger contentWidth = width - 2 * horizontalSpacing;
// Force the heading view to layout, so we get its height
[self.currentHeadingView setNeedsLayout];
[self.currentHeadingView layoutIfNeeded];
// Then do it again since we may have updated the preferred size of some text
[self.currentHeadingView setNeedsLayout];
//Setting offset as topspacing
CGSize size = [self.currentHeadingView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
offset = topSpacing + size.height;
BOOL isOptionalFieldPresent = NO;
for(id <OEXRegistrationFieldController>fieldController in self.fieldControllers) {
UIView* view = fieldController.view;
// Add view to scroll view if field is not optional and it is not agreement field.
if([fieldController field].isRequired && view.superview != nil) {
[view layoutIfNeeded];
[view setFrame:CGRectMake(0, offset, width, view.frame.size.height)];
offset = offset + view.frame.size.height;
}
if(![fieldController field].isRequired) {
isOptionalFieldPresent = YES;
}
}
if (isOptionalFieldPresent) {
//Add the optional field toggle
CGFloat buttonWidth = 150;
CGFloat buttonHeight = 30;
[self.scrollView addSubview:self.optionalFieldsSeparator];
[self.toggleOptionalFieldsButton setFrame:CGRectMake(self.view.frame.size.width / 2 - buttonWidth / 2, offset, buttonWidth, buttonHeight)];
[self.scrollView addSubview:self.toggleOptionalFieldsButton];
self.optionalFieldsSeparator.frame = CGRectMake(horizontalSpacing, self.toggleOptionalFieldsButton.center.y, contentWidth, 1);
self.optionalFieldsSeparator.center = self.toggleOptionalFieldsButton.center;
offset = offset + buttonHeight + 10;
}
// Actually show the optional fields if necessary
for(id <OEXRegistrationFieldController>fieldController in self.fieldControllers) {
UIView* view = fieldController.view;
if(![fieldController field].isRequired && view.superview != nil) {
[view layoutIfNeeded];
[view setFrame:CGRectMake(0, offset, width, view.frame.size.height)];
[self.scrollView addSubview:view];
offset = offset + view.frame.size.height;
}
}
[self.registerButton setFrame:CGRectMake(horizontalSpacing, offset, contentWidth, 40)];
const int progressIndicatorCenterX = [self isRTL] ? 40 : self.registerButton.frame.size.width - 40;
self.progressIndicator.center = CGPointMake(progressIndicatorCenterX, self.registerButton.frame.size.height / 2);
[self.scrollView addSubview:self.registerButton];
offset = offset + 40;
[self.scrollView addSubview:self.agreementTextView];
[self.agreementTextView setFrame:CGRectMake(horizontalSpacing, offset + 10, self.agreementTextView.frame.size.width, self.agreementTextView.frame.size.height)];
offset = offset + self.agreementTextView.frame.size.height + [[OEXStyles sharedStyles] standardHorizontalMargin] * 2;
[self.scrollView setContentSize:CGSizeMake(width, offset)];
}
//This method will hide and unhide optional fields
//using isRequired flag for corresponding field.
- (void)toggleOptionalFields:(id)sender {
self.isShowingOptionalFields = !self.isShowingOptionalFields;
NSString *attributedTitle = self.isShowingOptionalFields ? [Strings registrationHideOptionalFields] : [Strings registrationShowOptionalFields];
[self.toggleOptionalFieldsButton setAttributedTitle: [self.toggleButtonStyle attributedStringWithText: attributedTitle] forState:UIControlStateNormal];
[self refreshFormFields];
}
#pragma mark ExternalRegistrationOptionsDelegate
- (void)optionsView:(OEXExternalRegistrationOptionsView *)view choseProvider:(id<OEXExternalAuthProvider>)provider {
[provider authorizeServiceFromController:self requestingUserDetails:YES withCompletion:^(NSString *accessToken, OEXRegisteringUserDetails *userDetails, NSError *error) {
if(error == nil) {
[view beginIndicatingActivity];
self.view.userInteractionEnabled = NO;
[self attemptExternalLoginWithProvider:provider token:accessToken completion:^(NSData* data, NSHTTPURLResponse* response, NSError *error) {
[view endIndicatingActivity];
self.view.userInteractionEnabled = YES;
if(response.statusCode == OEXHTTPStatusCode200OK) {
[self.delegate registrationViewControllerDidRegister:self completion: ^{
// Need to show on login screen that we already had an account
[[NSNotificationCenter defaultCenter] postNotificationName:OEXExternalRegistrationWithExistingAccountNotification object:provider.displayName];
}];
}
else {
[self configureViewForSocial:provider accessToken:accessToken userDetails:userDetails];
}
}];
}
else if([error oex_isNoInternetConnectionError]){
[view endIndicatingActivity];
[self showNoNetworkError];
}
else {
[view endIndicatingActivity];
// Do nothing. Typically this happens because the user hits cancel and so they know it didn't work already
}
}];
}
- (void) configureViewForSocial:(id<OEXExternalAuthProvider>)provider accessToken:(NSString *) accessToken userDetails:(OEXRegisteringUserDetails *) userDetails {
// No account already, so continue registration process
__block OEXRegistrationViewController *blockSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
UIView* headingView = [[OEXUsingExternalAuthHeadingView alloc] initWithFrame:CGRectZero serviceName:provider.displayName];
[blockSelf useHeadingView:headingView];
[blockSelf receivedFields:userDetails fromProvider:provider withAccessToken:accessToken];
});
}
- (void)receivedFields:(OEXRegisteringUserDetails*)profile fromProvider:(id <OEXExternalAuthProvider>)provider withAccessToken:(NSString*)accessToken {
self.externalAccessToken = accessToken;
self.externalProvider = provider;
// Long term, we should update the registration.json description to provide this mapping.
// We will need to do this if we ever transition to fetching that from the server
for(id <OEXRegistrationFieldController> controller in self.fieldControllers) {
if([[controller field].name isEqualToString:@"email"]) {
[controller setValue:profile.email];
}
if([[controller field].name isEqualToString:@"name"]) {
[controller setValue:profile.name];
}
if([[controller field].name isEqualToString:@"year_of_birth"]) {
[controller setValue:profile.birthYear];
}
}
[self refreshFormFields];
}
- (void)attemptExternalLoginWithProvider:(id <OEXExternalAuthProvider>)provider token:(NSString*)token completion:(void(^)(NSData* data, NSHTTPURLResponse* response, NSError* error))completion {
[OEXAuthentication requestTokenWithProvider:provider externalToken:token completion:completion];
}
#pragma mark IBAction
- (IBAction)createAccount:(id)sender {
// Clear error for all views
[self.fieldControllers makeObjectsPerformSelector:@selector(handleError:) withObject:nil];
// Dictionary for registration parameters
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
BOOL hasError = NO;
for(id <OEXRegistrationFieldController> controller in self.fieldControllers) {
if([controller isValidInput]) {
if([controller hasValue]) {
[parameters setSafeObject:[controller currentValue] forKey:[controller field].name];
}
}
else if(![self shouldFilterField:controller.field]){
hasError = YES;
}
}
if(hasError) {
[self showProgress:NO];
[self refreshFormFields];
[self showInputErrorAlert];
return;
}
//Setting parameter 'honor_code'='true'
[parameters setObject:@"true" forKey:@"honor_code"];
//As user is agree to the license setting 'terms_of_service'='true'
[parameters setObject:@"true" forKey:@"terms_of_service"];
if(self.externalProvider != nil) {
[parameters setSafeObject:self.externalAccessToken forKey: @"access_token"];
[parameters setSafeObject:self.externalProvider.backendName forKey:@"provider"];
[parameters setSafeObject:self.environment.config.oauthClientID forKey:@"client_id"];
}
[self registerWithParameters:parameters];
}
- (void) showInputErrorAlert {
__weak typeof(self) weakSelf = self;
[[UIAlertController alloc] showAlertWithTitle:[Strings registrationErrorAlertTitle] message:[Strings registrationErrorAlertMessage] cancelButtonTitle:[Strings ok] onViewController:self tapBlock:^(UIAlertController * _Nonnull controller, UIAlertAction * _Nonnull action, NSInteger index) {
for(id <OEXRegistrationFieldController> controller in weakSelf.fieldControllers) {
if(![controller isValidInput]) {
[[controller accessibleInputField] becomeFirstResponder];
break;
}
}
}];
}
- (void) showNoNetworkError {
[[UIAlertController alloc] showAlertWithTitle:[Strings networkNotAvailableTitle] message:[Strings networkNotAvailableMessage] onViewController:self];
}
- (void)scrollViewTapped:(id)sender {
[self.view endEditing:YES];
}
- (void)agreementButtonTapped:(id)sender {
NSURL* url = [[NSBundle mainBundle] URLForResource:@"Terms-and-Services" withExtension:@"htm"];
OEXUserLicenseAgreementViewController* viewController = [[OEXUserLicenseAgreementViewController alloc] initWithContentURL:url];
[self presentViewController:viewController animated:YES completion:nil];
}
- (void)showProgress:(BOOL)status {
if(status) {
[self.progressIndicator startAnimating];
[self.registerButton applyButtonStyleWithStyle:[self.environment.styles filledPrimaryButtonStyle] withTitle:[Strings registrationCreatingAccount]];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
}
else {
[self.progressIndicator stopAnimating];
[self.registerButton applyButtonStyleWithStyle:[self.environment.styles filledPrimaryButtonStyle] withTitle:[Strings registrationCreateMyAccount]];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
}
- (BOOL) shouldAutorotate {
return false;
}
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#pragma mark - Scolling on Keyboard Hide/Show
// Called when the UIKeyboardDidChangeFrameNotification is sent.
- (void)keyboardFrameChanged:(NSNotification*)notification {
CGRect globalFrame = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect localFrame = [self.view convertRect:globalFrame fromView:nil];
CGRect intersection = CGRectIntersection(localFrame, self.view.bounds);
CGFloat keyboardHeight = intersection.size.height;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardHeight, 0.0);
self.scrollView.contentInset = contentInsets;
self.scrollView.scrollIndicatorInsets = contentInsets;
}
- (BOOL) isRTL {
return [UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft;
}
@end
@implementation OEXRegistrationViewController (Testing)
- (OEXRegistrationDescription*)t_registrationFormDescription {
return self.registrationDescription;
}
- (NSUInteger)t_visibleFieldCount {
NSIndexSet* visibleIndexes = [self.fieldControllers indexesOfObjectsPassingTest:^BOOL (id < OEXRegistrationFieldController > controller, NSUInteger idx, BOOL* stop) {
return controller.view.superview != nil;
}];
return visibleIndexes.count;
}
- (void)t_toggleOptionalFields {
[self toggleOptionalFields:nil];
}
- (void)t_registerWithParameters:(NSDictionary*)parameters {
[self registerWithParameters:parameters];
}
@end