Example #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();


            // setup the fake header
            HeaderView = new UIView( );
            View.AddSubview(HeaderView);
            HeaderView.BackgroundColor = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.BackgroundColor);

            // set the title image for the bar if there's no safe area defined. (A safe area is like, say, the notch for iPhone X)
            nfloat safeAreaTopInset = 0;

            // Make sure they're on iOS 11 before checking for insets. This is only needed for iPhone X anyways, which shipped with iOS 11.
            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                safeAreaTopInset = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Top;
            }

            if (safeAreaTopInset == 0)
            {
                string imagePath = NSBundle.MainBundle.BundlePath + "/" + PrivatePrimaryNavBarConfig.LogoFile_iOS;
                LogoView = new UIImageView(new UIImage(imagePath));
                LogoView.Layer.AnchorPoint = CGPoint.Empty;
                LogoView.SizeToFit( );
                HeaderView.AddSubview(LogoView);
            }

            ScrollView       = new UIScrollViewWrapper();
            ScrollView.Frame = new CGRect(View.Frame.Left, HeaderView.Frame.Bottom, View.Frame.Width, View.Frame.Height - HeaderView.Frame.Height);
            View.AddSubview(ScrollView);
            ScrollView.Parent = this;

            // logged in sanity check.
            //if( RockMobileUser.Instance.LoggedIn == true ) throw new Exception("A user cannot be logged in when registering. How did you do this?" );

            BlockerView = new UIBlockerView(View, View.Frame.ToRectF( ));

            //setup styles
            View.BackgroundColor = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.BackgroundColor);

            UserNameText = new StyledTextField();
            ScrollView.AddSubview(UserNameText.Background);
            UserNameText.Field.AutocapitalizationType = UITextAutocapitalizationType.None;
            UserNameText.Field.AutocorrectionType     = UITextAutocorrectionType.No;
            ControlStyling.StyleTextField(UserNameText.Field, RegisterStrings.UsernamePlaceholder, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ControlStyling.StyleBGLayer(UserNameText.Background);

            PasswordText = new StyledTextField();
            ScrollView.AddSubview(PasswordText.Background);
            PasswordText.Field.AutocapitalizationType = UITextAutocapitalizationType.None;
            PasswordText.Field.AutocorrectionType     = UITextAutocorrectionType.No;
            PasswordText.Field.SecureTextEntry        = true;
            ControlStyling.StyleTextField(PasswordText.Field, RegisterStrings.PasswordPlaceholder, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ControlStyling.StyleBGLayer(PasswordText.Background);

            ConfirmPasswordText = new StyledTextField();
            ScrollView.AddSubview(ConfirmPasswordText.Background);
            ConfirmPasswordText.Field.SecureTextEntry = true;
            ControlStyling.StyleTextField(ConfirmPasswordText.Field, RegisterStrings.ConfirmPasswordPlaceholder, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ControlStyling.StyleBGLayer(ConfirmPasswordText.Background);

            NickNameText = new StyledTextField();
            ScrollView.AddSubview(NickNameText.Background);
            NickNameText.Field.AutocapitalizationType = UITextAutocapitalizationType.Words;
            NickNameText.Field.AutocorrectionType     = UITextAutocorrectionType.No;
            ControlStyling.StyleTextField(NickNameText.Field, RegisterStrings.NickNamePlaceholder, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ControlStyling.StyleBGLayer(NickNameText.Background);

            LastNameText = new StyledTextField();
            ScrollView.AddSubview(LastNameText.Background);
            LastNameText.Field.AutocapitalizationType = UITextAutocapitalizationType.Words;
            LastNameText.Field.AutocorrectionType     = UITextAutocorrectionType.No;
            ControlStyling.StyleTextField(LastNameText.Field, RegisterStrings.LastNamePlaceholder, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ControlStyling.StyleBGLayer(LastNameText.Background);

            EmailText = new StyledTextField();
            ScrollView.AddSubview(EmailText.Background);
            EmailText.Field.AutocapitalizationType = UITextAutocapitalizationType.None;
            EmailText.Field.AutocorrectionType     = UITextAutocorrectionType.No;
            ControlStyling.StyleTextField(EmailText.Field, RegisterStrings.EmailPlaceholder, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ControlStyling.StyleBGLayer(EmailText.Background);

            CellPhoneText = new StyledTextField();
            ScrollView.AddSubview(CellPhoneText.Background);
            CellPhoneText.Field.AutocapitalizationType = UITextAutocapitalizationType.None;
            CellPhoneText.Field.AutocorrectionType     = UITextAutocorrectionType.No;
            ControlStyling.StyleTextField(CellPhoneText.Field, RegisterStrings.CellPhonePlaceholder, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ControlStyling.StyleBGLayer(CellPhoneText.Background);

            DoneButton = UIButton.FromType(UIButtonType.System);
            ScrollView.AddSubview(DoneButton);
            ControlStyling.StyleButton(DoneButton, RegisterStrings.RegisterButton, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            DoneButton.SizeToFit( );


            CancelButton = UIButton.FromType(UIButtonType.System);
            ScrollView.AddSubview(CancelButton);
            CancelButton.SetTitleColor(Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.TextField_PlaceholderTextColor), UIControlState.Normal);
            CancelButton.SetTitle(GeneralStrings.Cancel, UIControlState.Normal);
            CancelButton.SizeToFit( );


            // Allow the return on username and password to start
            // the login process
            NickNameText.Field.ShouldReturn += TextFieldShouldReturn;
            LastNameText.Field.ShouldReturn += TextFieldShouldReturn;

            EmailText.Field.ShouldReturn += TextFieldShouldReturn;

            // If submit is pressed with dirty changes, prompt the user to save them.
            DoneButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                RegisterUser( );

                HideKeyboard( );
            };

            // On logout, make sure the user really wants to log out.
            CancelButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                // if there were changes, create an action sheet for them to confirm.
                UIAlertController actionSheet = UIAlertController.Create(RegisterStrings.ConfirmCancelReg,
                                                                         null,
                                                                         UIAlertControllerStyle.ActionSheet);

                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                {
                    actionSheet.PopoverPresentationController.SourceView = CancelButton;
                    actionSheet.PopoverPresentationController.SourceRect = CancelButton.Bounds;
                }

                UIAlertAction yesAction = UIAlertAction.Create(GeneralStrings.Yes, UIAlertActionStyle.Destructive, delegate
                {
                    Springboard.ResignModelViewController(this, null);
                });
                actionSheet.AddAction(yesAction);


                // let them cancel, too
                UIAlertAction cancelAction = UIAlertAction.Create(GeneralStrings.Cancel, UIAlertActionStyle.Cancel, delegate { });
                actionSheet.AddAction(cancelAction);

                PresentViewController(actionSheet, true, null);
            };

            ResultView = new UIResultView(ScrollView, View.Frame.ToRectF( ), OnResultViewDone);
        }