Beispiel #1
0
        public LoginPage()
        {
            ViewModel.LoginFailed   += HandleLoginFailed;
            ViewModel.LoginApproved += HandleLoginApproved;

            BackgroundColor = Color.FromHex("#3498db");
            Padding         = GetPagePadding();

            _logo = new Image {
                Source = "xamarin_logo"
            };

            _logoSlogan = new StyledLabel
            {
                Opacity = 0,
                Text    = "Login to your account with facial recognition.",
            };
            _usernameEntry = new StyledEntry
            {
                Placeholder   = "Username",
                ReturnType    = ReturnType.Next,
                ReturnCommand = new Command(() => _passwordEntry.Focus())
            };
            _usernameEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.UsernameEntryText));

            _passwordEntry = new StyledEntry
            {
                Placeholder = "Password",
                IsPassword  = true,
                ReturnType  = ReturnType.Done
            };
            _passwordEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.PasswordEntryText));
            _passwordEntry.SetBinding(Xamarin.Forms.Entry.ReturnCommandProperty, nameof(ViewModel.LoginButtonTappedCommand));

            _loginButton = new StyledButton(Borders.Thin)
            {
                Text = "Login"
            };
            _loginButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));
            _loginButton.SetBinding(Button.CommandProperty, nameof(ViewModel.LoginButtonTappedCommand));

            _newUserSignUpButton = new StyledButton(Borders.None)
            {
                Text = "Sign-up"
            };
            _newUserSignUpButton.Clicked += HandleNewUserSignUpButtonClicked;
            _newUserSignUpButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));

            var activityIndicator = new ActivityIndicator {
                Color = Color.White
            };

            activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionActive));
            activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsInternetConnectionActive));

            On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);

            Func <RelativeLayout, double> getNewUserButtonWidth      = (p) => _newUserSignUpButton.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getLogoSloganWidth         = (p) => _logoSlogan.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getActivityIndicatorHeight = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Height;
            Func <RelativeLayout, double> getActivityIndicatorWidth  = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Width;

            _relativeLayout = new RelativeLayout();
            _relativeLayout.Children.Add(
                _logo,
                xConstraint: Constraint.Constant(100),
                yConstraint: Constraint.Constant(250),
                widthConstraint: Constraint.RelativeToParent(p => p.Width - 200)
                );

            _relativeLayout.Children.Add(
                _logoSlogan,
                xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getLogoSloganWidth(p) / 2)),
                yConstraint: Constraint.Constant(125)
                );

            _relativeLayout.Children.Add(
                _usernameEntry,
                xConstraint: Constraint.Constant(40),
                yConstraint: Constraint.RelativeToView(_logoSlogan, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                );
            _relativeLayout.Children.Add(
                _passwordEntry,
                xConstraint: Constraint.Constant(40),
                yConstraint: Constraint.RelativeToView(_usernameEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                );

            _relativeLayout.Children.Add(
                _loginButton,
                xConstraint: Constraint.Constant(40),
                yConstraint: Constraint.RelativeToView(_passwordEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                );
            _relativeLayout.Children.Add(
                _newUserSignUpButton,
                xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getNewUserButtonWidth(p) / 2)),
                yConstraint: Constraint.RelativeToView(_loginButton, (p, v) => v.Y + _loginButton.Height + 15)
                );

            _relativeLayout.Children.Add(activityIndicator,
                                         xConstraint: Constraint.RelativeToParent(parent => parent.Width / 2 - getActivityIndicatorWidth(parent) / 2),
                                         yConstraint: Constraint.RelativeToParent(parent => parent.Height / 2 - getActivityIndicatorHeight(parent) / 2));

            Content = new Xamarin.Forms.ScrollView {
                Content = _relativeLayout
            };
        }
Beispiel #2
0
        public LoginPage()
        {
            BackgroundColor = Color.FromHex("#3498db");
            Padding         = GetPagePadding();

            _logo = new Image {
                Source = "xamarin_logo"
            };

            _logoSlogan = new StyledLabel
            {
                Opacity = 0,
                Text    = "Delighting Developers."
            };
            _usernameEntry = new StyledEntry {
                Placeholder = "Username"
            };
            _usernameEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.UsernameEntryText));
            CustomReturnEffect.SetReturnType(_usernameEntry, ReturnType.Next);
            CustomReturnEffect.SetReturnCommand(_usernameEntry, new Command(() => _passwordEntry.Focus()));

            _passwordEntry = new StyledEntry
            {
                Placeholder = "Password",
                IsPassword  = true,
            };
            _passwordEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.PasswordEntryText));
            _passwordEntry.SetBinding(CustomReturnEffect.ReturnCommandProperty, nameof(ViewModel.LoginButtonTappedCommand));
            CustomReturnEffect.SetReturnType(_passwordEntry, ReturnType.Done);

            _loginButton = new StyledButton(Borders.Thin)
            {
                Text = "Login"
            };
            _loginButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));
            _loginButton.SetBinding(Button.CommandProperty, nameof(ViewModel.LoginButtonTappedCommand));

            _newUserSignUpButton = new StyledButton(Borders.None)
            {
                Text = "Sign-up"
            };
            _newUserSignUpButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));

            var activityIndicator = new ActivityIndicator {
                Color = Color.White
            };

            activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionActive));
            activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsInternetConnectionActive));

            Func <RelativeLayout, double> getNewUserButtonWidth      = (p) => _newUserSignUpButton.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getLogoSloganWidth         = (p) => _logoSlogan.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getActivityIndicatorHeight = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Height;
            Func <RelativeLayout, double> getActivityIndicatorWidth  = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Width;

            _relativeLayout = new RelativeLayout();
            _relativeLayout.Children.Add(
                _logo,
                xConstraint: Constraint.Constant(100),
                yConstraint: Constraint.Constant(250),
                widthConstraint: Constraint.RelativeToParent(p => p.Width - 200)
                );

            _relativeLayout.Children.Add(
                _logoSlogan,
                xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getLogoSloganWidth(p) / 2)),
                yConstraint: Constraint.Constant(125)
                );

            _relativeLayout.Children.Add(
                _usernameEntry,
                xConstraint: Constraint.Constant(40),
                yConstraint: Constraint.RelativeToView(_logoSlogan, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                );
            _relativeLayout.Children.Add(
                _passwordEntry,
                xConstraint: Constraint.Constant(40),
                yConstraint: Constraint.RelativeToView(_usernameEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                );

            _relativeLayout.Children.Add(
                _loginButton,
                xConstraint: Constraint.Constant(40),
                yConstraint: Constraint.RelativeToView(_passwordEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                );
            _relativeLayout.Children.Add(
                _newUserSignUpButton,
                xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getNewUserButtonWidth(p) / 2)),
                yConstraint: Constraint.RelativeToView(_loginButton, (p, v) => v.Y + _loginButton.Height + 15)
                );

            _relativeLayout.Children.Add(activityIndicator,
                                         xConstraint: Constraint.RelativeToParent(parent => parent.Width / 2 - getActivityIndicatorWidth(parent) / 2),
                                         yConstraint: Constraint.RelativeToParent(parent => parent.Height / 2 - getActivityIndicatorHeight(parent) / 2));

            Content = new ScrollView {
                Content = _relativeLayout
            };
        }