protected override async void OnAppearingAnimationEnd() { if (!IsAnimationEnabled) { return; } var translateLength = 400u; await Task.WhenAll( UsernameEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength), UsernameEntry.FadeTo(1), (new Func <Task>(async() => { await Task.Delay(200); await Task.WhenAll( PasswordEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength), PasswordEntry.FadeTo(1)); }))()); await Task.WhenAll( CloseImage.FadeTo(1), CloseImage.ScaleTo(1, easing: Easing.SpringOut), CloseImage.RotateTo(0), LoginButton.ScaleTo(1), LoginButton.FadeTo(1)); }
protected override async Task OnDisappearingAnimationBeginAsync() { var taskSource = new TaskCompletionSource <bool>(); var currentHeight = FrameContainer.Height; await Task.WhenAll( UsernameEntry.FadeTo(0), PasswordEntry.FadeTo(0), LoginButton.FadeTo(0)); FrameContainer.Animate("HideAnimation", d => { FrameContainer.HeightRequest = d; }, start: currentHeight, end: 170, finished: async(d, b) => { await Task.Delay(300); taskSource.TrySetResult(true); }); await taskSource.Task; }
/// Caso dê algum erro na autenticação, devemos voltar /// para o estado original das views, assim podemos /// fazer uma animação de retorno private async Task OnErrorLoadingAsync() { // Caso seu servidor responda muito rápido, pode ser que a // animação ainda esteja sendo executada, por isso // utilizamos o TaskCompletationSource para aguardar o término da animaçao de loading _ = await loadingAnimationTask.Task; // Voltamos a visibilidade do botao de login _ = await LoginButton.FadeTo(1, 100); // Deixaremos novamente o Frame no tamanho/posicão exatos do login var rectTo = new Rectangle(0, LoginButton.Y, LoginButton.Width, LoginButton.Height); // Criamos a transiçao do raio do frame + o tamanh/posição (Layout) + a cor defundo // E aguardamos a execução de todas _ = await Task.WhenAll( LoginFrame.CornerRadiusTo(LoginButton.CornerRadius), LoginFrame.LayoutTo(rectTo, 500, Easing.SpringOut), LoginFrame.BackgroundColorTo(Color.Transparent, 1000)); // Finalizamos deixando o Frame Invisível // Pode parecer redundante, pois deixamos o fundo transparente // Mas parece que o comportamento do `IsVisible` não cooperou pra mim no IOS // Pode ser um bug na versão atual do Xamarin.Forms, ainda vou investigar mais LoginFrame.IsVisible = false; }
private void MakeTransformation(LoginMode loginMode) { switch (loginMode) { case LoginMode.Initial: RegisterButton.TranslateTo(0, 0, AnimationSpeed); RegisterButton.FadeTo(1, AnimationSpeed); LoginButton.FadeTo(1, AnimationSpeed); HideControls(); _viewModel.LoginModel.Email = string.Empty; _viewModel.LoginModel.Password = string.Empty; break; case LoginMode.Login: RegisterButton.FadeTo(0, AnimationSpeed); ShowControls(); break; case LoginMode.Register: RegisterButton.TranslateTo(0, LoginButton.Y - RegisterButton.Y, AnimationSpeed); LoginButton.FadeTo(0, AnimationSpeed); ShowControls(); break; default: throw new ArgumentOutOfRangeException(nameof(loginMode)); } }
protected async override Task OnAppearingAnimationEnd() { var translateLength = 400u; await Task.WhenAll( Nombre.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength), Apellido.FadeTo(1)); await Task.WhenAll( UsernameEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength), UsernameEntry.FadeTo(1), Profesion.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength), Profesion.FadeTo(1), (new Func <Task>(async() => { await Task.Delay(200); await Task.WhenAll( PasswordEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength), PasswordEntry.FadeTo(1)); }))()); await Task.WhenAll( LoginButton.ScaleTo(1), LoginButton.FadeTo(1)); }
//Animation on page load protected override async void OnAppearing() { if (SettingsSaved == "") { double scale = this.Scale; LoginButton.Scale = (scale * 70 / 100); LoginEntryUsername.Scale = (scale * 70 / 100); LoginEntryPassword.Scale = (scale * 70 / 100); //Startup setup await CinnamonLogo.TranslateTo(0, 170, 500, Easing.Linear); //await CheckinText.TranslateTo(0, 100, 500, Easing.Linear); await LoginEntryUsername.TranslateTo(0, 100, 500, Easing.Linear); await LoginEntryPassword.TranslateTo(0, 100, 500, Easing.Linear); await LoginButton.TranslateTo(0, 100, 500, Easing.Linear); //Cinnamon Logo Animation await Sleep(500); await CinnamonLogo.TranslateTo(0, 0, 600, Easing.CubicOut); //Entry and Button Animation //CheckinText.FadeTo(1, 800, Easing.CubicOut); //CheckinText.TranslateTo(0, 0, 800, Easing.CubicOut); LoginEntryUsername.FadeTo(1, 800, Easing.CubicOut); LoginEntryUsername.TranslateTo(0, 0, 800, Easing.CubicOut); LoginEntryPassword.FadeTo(1, 800, Easing.CubicOut); LoginEntryPassword.TranslateTo(0, 0, 800, Easing.CubicOut); LoginButton.FadeTo(1, 800, Easing.CubicOut); LoginButton.TranslateTo(0, 0, 800, Easing.CubicOut); ForgotPasswordButton.FadeTo(1, 800, Easing.CubicOut); ForgotPasswordButton.TranslateTo(0, 0, 800, Easing.CubicOut); //NeedHelpButton.FadeTo(1, 800, Easing.CubicOut); //NeedHelpButton.TranslateTo(0, 0, 800, Easing.CubicOut); //ContactButton.FadeTo(1, 800, Easing.CubicOut); //ContactButton.TranslateTo(0, 0, 800, Easing.CubicOut); TradeMark.IsVisible = true; //ContactSeperator.IsVisible = true; Sleep(800); base.OnAppearing(); } //Update Availability Indicator //VersionChecker(); }
private async Task checkLoggedIn() { ClientInitializor.username = Xamarin.Essentials.Preferences.Get("username", "null"); ClientInitializor.password = Xamarin.Essentials.Preferences.Get("password", "null"); Device.BeginInvokeOnMainThread(() => { indicator.IsVisible = true; indicator.IsEnabled = true; indicator.IsRunning = true; }); if (ClientInitializor.username != "null") { await DataFetcher.AttemptLogIn(); if (DataFetcher.loggedIn) { LoggedIn = true; if (Device.RuntimePlatform == Device.iOS) { await Navigation.PopToRootAsync(); } Device.BeginInvokeOnMainThread(() => { Application.Current.MainPage = new NavigationPage(new GradesPage()); ((NavigationPage)Application.Current.MainPage).BarBackgroundColor = g1; }); //Application.Current.MainPage = new NavigationPage(new GradesPage()); //await Navigation.PushModalAsync(new GradesPage()); //((NavigationPage)Application.Current.MainPage).BarBackgroundColor = g1; } else { Device.BeginInvokeOnMainThread(() => { usnHolder.Hint = "Incorrect Username or Password"; usnHolder.FocusedColor = Color.Red; usnHolder.Focus(); pwd.Text = ""; usn.Text = ""; acceptTOS.IsChecked = false; LoginButton.IsEnabled = true; LoginButton.FadeTo(1, 300); LoginButton.IsVisible = true; indicator.IsVisible = false; indicator.IsEnabled = false; indicator.IsRunning = false; }); } } }
protected override void OnAppearing() { base.OnAppearing(); if (String.IsNullOrEmpty(LogoFileImageSource)) { throw new Exception("You must set the LogoFileImageSource property to specify the logo"); } logo.Source = LogoFileImageSource; List <Task> animationTaskList; if (!isInitialized) { Device.BeginInvokeOnMainThread(async() => { await Task.Delay(500); await logo?.TranslateTo(0, -layout.Height * 0.3 - 10, 250); await logo?.TranslateTo(0, -layout.Height * 0.3 + 5, 100); await logo?.TranslateTo(0, -layout.Height * 0.3, 50); await logo?.TranslateTo(0, -200 + 5, 100); await logo?.TranslateTo(0, -200, 50); var logoSloginAnimationTask = logoSlogan?.FadeTo(1, 5); var newUserSignUpButtonAnimationTask = newUserSignUpButton?.FadeTo(1, 250); var forgotPasswordButtonAnimationTask = forgotPasswordButton?.FadeTo(1, 250); var loginEntryAnimationTask = loginEntry?.FadeTo(1, 250); var passwordEntryAnimationTask = passwordEntry?.FadeTo(1, 250); var saveUsernameAnimationTask = saveUsername?.FadeTo(1, 250); var rememberMeAnimationTask = rememberMe?.FadeTo(1, 250); var loginButtonAnimationTask = loginButton?.FadeTo(1, 249); animationTaskList = new List <Task> { logoSloginAnimationTask, newUserSignUpButtonAnimationTask, forgotPasswordButtonAnimationTask, loginEntryAnimationTask, passwordEntryAnimationTask, saveUsernameAnimationTask, rememberMeAnimationTask, loginButtonAnimationTask }; await Task.WhenAll(animationTaskList); isInitialized = true; RunAfterAnimation(); }); } }
public async void Login(object sender, EventArgs e) { Firstlight.TranslationY = -20; Secondlight.TranslationY = -20; Clock.TranslationY = -20; View.TranslationY = -20; LoginButton.TranslationY = -20; Forget.TranslationY = -20; Firstlight.Opacity = 0; Secondlight.Opacity = 0; Clock.Opacity = 0; View.Opacity = 0; LoginButton.Opacity = 0; Forget.Opacity = 0; Firstlight.FadeTo(1, 100); await Firstlight.TranslateTo(0, 0, 300); Secondlight.FadeTo(1, 100); await Secondlight.TranslateTo(0, 0, 300); Clock.FadeTo(1, 100); await Clock.TranslateTo(0, 0, 300); View.FadeTo(1, 100); await View.TranslateTo(0, 0, 300); LoginButton.FadeTo(1, 100); await LoginButton.TranslateTo(0, 0, 300); Forget.FadeTo(1, 100); await Forget.TranslateTo(0, 0, 300); //try //{ // _googleManager.Logout(); // _googleManager.Login(OnLoginComplete); //} //catch (Exception x) //{ // await DisplayAlert("Authentication Failed", "Your Authentication Attempt Failed. Please try again..", "Ok"); //} }
async void OnLoginAttempt(object sender, EventArgs args) { LoginButton.IsEnabled = false; await LoginButton.FadeTo(0, 300); LoginButton.IsVisible = false; indicator.IsVisible = true; indicator.IsEnabled = true; indicator.IsRunning = true; ClientInitializor.username = usn.Text; ClientInitializor.password = pwd.Text; await Task.Run(() => DoLogin()); if (!DataFetcher.loggedIn) { usnHolder.Hint = "Incorrect Username or Password"; usnHolder.FocusedColor = Color.Red; usnHolder.Focus(); pwd.Text = ""; usn.Text = ""; acceptTOS.IsChecked = false; LoginButton.IsEnabled = true; await LoginButton.FadeTo(1, 300); LoginButton.IsVisible = true; indicator.IsVisible = false; indicator.IsEnabled = false; indicator.IsRunning = false; } else { LoggedIn = true; if (rememberCB.IsChecked.Value) { Xamarin.Essentials.Preferences.Set("username", ClientInitializor.username); Xamarin.Essentials.Preferences.Set("password", ClientInitializor.password); } if (Device.RuntimePlatform == Device.iOS) { await Navigation.PopToRootAsync(); } Application.Current.MainPage = new NavigationPage(new GradesPage()); //await Navigation.PushModalAsync(new GradesPage()); ((NavigationPage)Application.Current.MainPage).BarBackgroundColor = g1; } }
protected override async Task OnAppearingAnimationEndAsync() { if (!IsAnimationEnabled) { return; } var translateLength = 400u; await Task.WhenAll( CloseImage.FadeTo(1), CloseImage.ScaleTo(1, easing: Easing.SpringOut), CloseImage.RotateTo(0), LoginButton.ScaleTo(1), LoginButton.FadeTo(1)); }
protected override async Task OnAppearingAnimationEndAsync() { if (!IsAnimationEnabled) { return; } var translateLength = 400u; await Task.WhenAll( UsernameEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength), UsernameEntry.FadeTo(1), (new Func <Task>(async() => { await Task.Delay(150); await Task.WhenAll( PasswordEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength), PasswordEntry.FadeTo(1) ); }))(), (new Func <Task>(async() => { await Task.Delay(300); await Task.WhenAll( RememberCheckBox.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength), RememberCheckBox.FadeTo(1) ); }))() ); await Task.WhenAll( //CloseImage.FadeTo(1), //CloseImage.ScaleTo(1, easing: Easing.SpringOut), //CloseImage.RotateTo(0), LoginButton.ScaleTo(1), LoginButton.FadeTo(1), RegisterButton.ScaleTo(1), RegisterButton.FadeTo(1), OrEntry.ScaleTo(1), OrEntry.FadeTo(1) ); LoginButton.IsEnabled = false; }
private async Task AnimateLoginStart() { await Task.Run(() => { LoginEntry.FadeTo(0, 500, Easing.Linear); PasswordEntry.FadeTo(0, 500, Easing.Linear); LoginButton.FadeTo(0, 500, Easing.Linear); }); await LogoImage.TranslateTo(0, 50, 1000, Easing.Linear); while ((BindingContext as LoginPageViewModel).Busy) { await LogoImage.FadeTo(1, 600); await LogoImage.FadeTo(0, 600); } }
protected async override void OnAppearing() { base.OnAppearing(); if (String.IsNullOrEmpty(LogoFileImageSource)) { throw new Exception("You must set the LogoFileImageSource property to specify the logo"); } logo.Source = LogoFileImageSource; if (!isInitialized) { await Task.Delay(500); await logo.TranslateTo(0, -layout.Height * 0.3 - 10, 250); await logo.TranslateTo(0, -layout.Height * 0.3 + 5, 100); await logo.TranslateTo(0, -layout.Height * 0.3, 50); await logo.TranslateTo(0, -200 + 5, 100); await logo.TranslateTo(0, -200, 50); newUserSignUpButton.FadeTo(1, 250); forgotPasswordButton.FadeTo(1, 250); loginEntry.FadeTo(1, 250); passwordEntry.FadeTo(1, 250); saveUsername.FadeTo(1, 250); rememberMe.FadeTo(1, 250); await loginButton.FadeTo(1, 249); isInitialized = true; RunAfterAnimation(); } }
// Aqui fazemos a animaçao do botao se tornar o ActivityIndicator private async Task ShowLoadingAsync() { // Aqui definimos que a animação de loading vai começar // e deve ser aguardada antes de iniciar outra animaçao loadingAnimationTask?.TrySetCanceled(); loadingAnimationTask = new TaskCompletionSource <bool>(); try { // Tornamos visivel o frame do login que usa o mesmo tamanho/formato do botão // Utilizei aqui o Frame, ao inves de manipular diretamente o botão porque achei mais facil // de alterar sem precisar ocultar texto ou outrar propriedaes do botão LoginFrame.IsVisible = true; // Criamos uma animaçao onde o frame vai ficar com a cor de fundo igual a do botao // e o botão faz um Fade, ficando totalmente transparente, ficando assim // apenas visivel o frame que contém o ActivityIndicator dentro _ = await Task.WhenAll( LoginFrame.BackgroundColorTo(LoginButton.BackgroundColor, 50), LoginButton.FadeTo(0, 100)); // Calculamos a nova posição do frame, após reduzir a largura dele para 50 var anchorX = (LoginFrame.Width / 2) - (LOADING_WIDTH / 2); // Criamos então a posição/tamanho final do frame (layout) var rectTo = new Rectangle(anchorX, LoginFrame.Y, LOADING_WIDTH, LoginFrame.Height); // Fazemos a transição que vai manipular a posicão/tamanho do frame _ = await LoginFrame.LayoutTo(rectTo, easing : Easing.SpringOut); } finally { // Por fim definimos que a animação de loading foi finalizada loadingAnimationTask.SetResult(true); } }