Skip to content

Commit

Permalink
Merge pull request #1 from shawyunz/PolishAnimation
Browse files Browse the repository at this point in the history
Replace Triggers with delegate and event for smooth animation.
  • Loading branch information
tuyen-vuduc committed Dec 16, 2022
2 parents 7a8846e + cfe95d9 commit dad1333
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/TodoApp.Android/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions src/TodoApp/Features/Todos/Pages/TodosPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Shell.NavBarHasShadow="False"
Shell.NavBarIsVisible="False"
ios:Page.UseSafeArea="True"
BackgroundColor="{x:Static app:Colors.Bg}"
BackgroundColor="{x:Static app:Colors.Primary}"
BindingContext="{app:BindingContext {x:Type app:TodosPageViewModel}}">
<ContentPage.ToolbarItems>
<ToolbarItem
Expand All @@ -29,7 +29,7 @@
Glyph={x:Static app:Mdi.Bell}
}" />
</ContentPage.ToolbarItems>
<ContentPage.Triggers>
<!--<ContentPage.Triggers>
<DataTrigger
Binding="{Binding SidebarMenuVisible}"
Value="True"
Expand All @@ -38,16 +38,19 @@
Property="BackgroundColor"
Value="{x:Static app:Colors.Primary}" />
</DataTrigger>
</ContentPage.Triggers>
</ContentPage.Triggers>-->

<Grid
x:Name="grid">
<app:SideBarMenuView />
<app:SideBarMenuView
x:Name="SideBarView"
TranslationX="-300"/>

<app:TodosMainContentView
x:Name="TodoContentView"
BindingContext="{Binding BindingContext, Source={x:Reference root}}"
>
<app:TodosMainContentView.Triggers>
<!--<app:TodosMainContentView.Triggers>
<DataTrigger
Binding="{Binding SidebarMenuVisible}"
Value="True"
Expand Down Expand Up @@ -87,7 +90,7 @@
Property="TranslationX"
Value="0" />
</DataTrigger>
</app:TodosMainContentView.Triggers>
</app:TodosMainContentView.Triggers>-->
</app:TodosMainContentView>
</Grid>
</app:BasePage>
28 changes: 28 additions & 0 deletions src/TodoApp/Features/Todos/Pages/TodosPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,33 @@ public TodosPage()
{
InitializeComponent();
}

protected override void OnAppearing()
{
base.OnAppearing();

TodoContentView.OnMenuClicked += Menu_ClickedEvent;
SideBarView.OnBackClicked += Back_ClickedEvent;
}

protected override void OnDisappearing()
{
TodoContentView.OnMenuClicked -= Menu_ClickedEvent;
SideBarView.OnBackClicked -= Back_ClickedEvent;
}

private void Back_ClickedEvent()
{
TodoContentView.TranslateTo(0, 0, 500, Easing.CubicOut);
TodoContentView.ScaleTo(1, 500, Easing.CubicOut);
SideBarView.TranslateTo(-App.Current.MainPage.Width * 0.8, 0, 500, Easing.CubicOut);
}

private void Menu_ClickedEvent()
{
TodoContentView.TranslateTo(App.Current.MainPage.Width * 0.8, 0, 500, Easing.CubicIn);
TodoContentView.ScaleTo(0.85, 500, Easing.CubicIn);
SideBarView.TranslateTo(0, 0, 500, Easing.CubicIn);
}
}
}
7 changes: 0 additions & 7 deletions src/TodoApp/Features/Todos/Pages/TodosPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,5 @@ async void ExecuteDeleteCommand(TodoModel model)
Items.Remove(model);
RefreshStatistics();
}

public ICommand ToggleSidebarCommand => _ToggleSidebarCommand ??= new Command(ExecuteToggleSidebarCommand);
ICommand _ToggleSidebarCommand;
void ExecuteToggleSidebarCommand()
{
SidebarMenuVisible = !SidebarMenuVisible;
}
}
}
2 changes: 1 addition & 1 deletion src/TodoApp/Features/Todos/Views/SideBarMenuView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
All={x:Static app:Dimens.SpacingSm}}">
<Frame.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding ToggleSidebarCommand}" />
Tapped="TapGestureRecognizer_Tapped" />
</Frame.GestureRecognizers>
<Image
Source="{FontImage
Expand Down
13 changes: 10 additions & 3 deletions src/TodoApp/Features/Todos/Views/SideBarMenuView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace TodoApp
{
Expand All @@ -10,5 +8,14 @@ public SideBarMenuView()
{
InitializeComponent();
}

public delegate void OnBackClickedDelegate();

public OnBackClickedDelegate OnBackClicked { get; set; }

private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
OnBackClicked?.Invoke();
}
}
}
}
2 changes: 1 addition & 1 deletion src/TodoApp/Features/Todos/Views/TodosMainContentView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}" />
<ContentView.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding ToggleSidebarCommand}" />
Tapped="TapGestureRecognizer_Tapped" />
</ContentView.GestureRecognizers>
</ContentView>
<ContentView
Expand Down
12 changes: 10 additions & 2 deletions src/TodoApp/Features/Todos/Views/TodosMainContentView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace TodoApp
Expand All @@ -10,5 +9,14 @@ public TodosMainContentView()
{
InitializeComponent();
}

public delegate void OnMenuClickedDelegate();

public OnMenuClickedDelegate OnMenuClicked { get; set; }

private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
OnMenuClicked?.Invoke();
}
}
}
}

0 comments on commit dad1333

Please sign in to comment.