Skip to content

Commit

Permalink
Add scroll animation to MaterialTopAppBar
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinBonilla committed Sep 29, 2022
1 parent 364e8eb commit 328a52b
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 80 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,6 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb

*.DS_Store
2 changes: 1 addition & 1 deletion MaterialDesignControls.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.8.1">
<id>Plugin.MaterialDesignControls</id>
<version>1.11.4</version>
<version>1.12.0</version>
<title>MaterialDesignControls Plugin for Xamarin Forms</title>
<authors>Horus</authors>
<owners>AgustinBonillaHorus</owners>
Expand Down
12 changes: 12 additions & 0 deletions example/ExampleMaterialDesignControls/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,17 @@
<Setter Property="ShadowColor" Value="Black" />
<Setter Property="TextColor" Value="White" />
</Style>

<!-- MaterialTopAppBar -->
<Style TargetType="material3:MaterialTopAppBar">
<Setter Property="Type" Value="CenterAligned" />
<Setter Property="HeadlineFontFamily" Value="{StaticResource RegularFont}" />
<Setter Property="HeadlineColor" Value="Black" />
<Setter Property="HeadlineMarginAdjustment">
<OnPlatform x:TypeArguments="Thickness">
<On Platform="Android" Value="0,3,0,0" />
</OnPlatform>
</Setter>
</Style>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
xmlns:animations="clr-namespace:ExampleMaterialDesignControls.Animations"
xmlns:contentViews="clr-namespace:ExampleMaterialDesignControls.ContentViews"
xmlns:ffimageloadingsvg="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
xmlns:material="clr-namespace:Plugin.MaterialDesignControls;assembly=Plugin.MaterialDesignControls"
xmlns:material3="clr-namespace:Plugin.MaterialDesignControls.Material3;assembly=Plugin.MaterialDesignControls"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="True"
BackgroundColor="White"
NavigationPage.HasNavigationBar="false">
Expand All @@ -27,14 +27,22 @@
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<Grid RowDefinitions="Auto,*">
<material3:MaterialTopAppBar Headline="MaterialButton" LeadingIconCommand="{Binding BackCommand}">

<Grid RowDefinitions="Auto,*" RowSpacing="0">
<material3:MaterialTopAppBar
Headline="MaterialButton"
LeadingIconCommand="{Binding BackCommand}"
ScrollViewName="scrollView"
Type="Large">
<material3:MaterialTopAppBar.LeadingIcon>
<ffimageloadingsvg:SvgCachedImage Source="resource://ExampleMaterialDesignControls.Resources.Svg.ic_back_b.svg" />
</material3:MaterialTopAppBar.LeadingIcon>
</material3:MaterialTopAppBar>

<ScrollView Grid.Row="1" VerticalScrollBarVisibility="Never">
<ScrollView
x:Name="scrollView"
Grid.Row="1"
VerticalScrollBarVisibility="Never">
<StackLayout Padding="20,0,20,20" Spacing="10">

<contentViews:InfoIndicatorView Message="MaterialButton follows the latest guidelines of Material Design 3" />
Expand Down
3 changes: 3 additions & 0 deletions src/MaterialDesignControls.Android/Effects/Effects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Xamarin.Forms;

[assembly: ResolutionGroupName(Plugin.MaterialDesignControls.Effects.EffectIdPrefix)]
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using Android.Views;
using Plugin.MaterialDesignControls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using View = Android.Views.View;
using TouchAndPressEffect = Plugin.MaterialDesignControls.Android.TouchAndPressEffect;

[assembly: ResolutionGroupName(Plugin.MaterialDesignControls.TouchAndPressEffect.EffectIdPrefix)]
[assembly: ExportEffect(typeof(TouchAndPressEffect), nameof(TouchAndPressEffect))]

namespace Plugin.MaterialDesignControls.Android
Expand Down
51 changes: 51 additions & 0 deletions src/MaterialDesignControls.Android/Effects/TouchReleaseEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using Android.Views;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using View = Android.Views.View;
using TouchReleaseEffect = Plugin.MaterialDesignControls.Android.TouchReleaseEffect;
using System.Linq;

[assembly: ExportEffect(typeof(TouchReleaseEffect), nameof(TouchReleaseEffect))]

namespace Plugin.MaterialDesignControls.Android
{
public class TouchReleaseEffect : PlatformEffect
{
private View _view;

private Action _onRelease;

protected override void OnAttached()
{
_view = Control ?? Container;

if (_view != null)
{
var touchReleaseEffect = (MaterialDesignControls.TouchReleaseEffect)Element.Effects.FirstOrDefault(x => x is MaterialDesignControls.TouchReleaseEffect);
if (touchReleaseEffect != null && touchReleaseEffect.OnRelease != null)
{
_onRelease = touchReleaseEffect.OnRelease;
_view.Touch += OnViewOnTouch;
}
}
}

protected override void OnDetached()
{
if (_view != null)
_view.Touch -= OnViewOnTouch;
}

private void OnViewOnTouch(object sender, View.TouchEventArgs e)
{
e.Handled = false;

if (e.Event.ActionMasked == MotionEventActions.Up)
{
System.Diagnostics.Debug.WriteLine(e.Event.ActionMasked);
_onRelease.Invoke();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
<Compile Include="Utils\TextAlignmentHelper.cs" />
<Compile Include="Renderers\MaterialDoublePickerRenderer.cs" />
<Compile Include="Renderers\CustomFrameRenderer.cs" />
<Compile Include="Effects\TouchReleaseEffect.cs" />
<Compile Include="Effects\Effects.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
Expand Down
3 changes: 3 additions & 0 deletions src/MaterialDesignControls.iOS/Effects/Effects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Xamarin.Forms;

[assembly: ResolutionGroupName(Plugin.MaterialDesignControls.Effects.EffectIdPrefix)]
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Foundation;
using Plugin.MaterialDesignControls;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using TouchAndPressEffect = Plugin.MaterialDesignControls.iOS.TouchAndPressEffect;

[assembly: ResolutionGroupName(Plugin.MaterialDesignControls.TouchAndPressEffect.EffectIdPrefix)]
[assembly: ExportEffect(typeof(TouchAndPressEffect), nameof(TouchAndPressEffect))]

namespace Plugin.MaterialDesignControls.iOS
Expand Down Expand Up @@ -89,4 +87,4 @@ public override void IgnoreTouch(UITouch touch, UIEvent forEvent)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<Compile Include="Utils\TextAlignmentHelper.cs" />
<Compile Include="Renderers\MaterialDoublePickerRenderer.cs" />
<Compile Include="Renderers\CustomFrameRenderer.cs" />
<Compile Include="Effects\Effects.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MaterialDesignControls\MaterialDesignControls.csproj">
Expand Down
Loading

0 comments on commit 328a52b

Please sign in to comment.