Skip to content

Commit

Permalink
updated sample
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Apr 28, 2019
1 parent ce56440 commit 61dff77
Show file tree
Hide file tree
Showing 10 changed files with 2,843 additions and 431 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2" />
<PackageReference Include="TouchView">
<Version>2.0.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
Expand Down Expand Up @@ -84,6 +87,7 @@
<AndroidResource Include="Resources\drawable-hdpi\arrow_drop_down.png" />
<AndroidResource Include="Resources\drawable\arrow_drop_down.png" />
<AndroidResource Include="Resources\drawable-xhdpi\arrow_drop_down.png" />
<AndroidResource Include="Resources\drawable\grad.jpg" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\drawable\" />
Expand Down
4 changes: 3 additions & 1 deletion ExpandableViewSample.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Android.Views;
using Android.Widget;
using Android.OS;
using TouchEffect.Droid;

namespace ExpandableViewSample.Droid
{
Expand All @@ -20,7 +21,8 @@ protected override void OnCreate(Bundle bundle)
base.OnCreate(bundle);

global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
new TouchViewRenderer();
LoadApplication(new App());
}
}
}
Expand Down
3,118 changes: 2,723 additions & 395 deletions ExpandableViewSample.Android/Resources/Resource.designer.cs

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions ExpandableViewSample.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Foundation;
using UIKit;
using TouchEffect.iOS;

namespace ExpandableViewSample.iOS
{
Expand All @@ -23,6 +24,7 @@ public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsAppli
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
TouchViewRenderer.Initialize();
LoadApplication(new App());

return base.FinishedLaunching(app, options);
Expand Down
4 changes: 4 additions & 0 deletions ExpandableViewSample.iOS/ExpandableViewSample.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.0.0.446417" />
<PackageReference Include="TouchView">
<Version>2.0.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand All @@ -160,5 +163,6 @@
<BundleResource Include="Resources\arrow_drop_down.png" />
<BundleResource Include="Resources\arrow_drop_down%402x.png" />
<BundleResource Include="Resources\arrow_drop_down%403x.png" />
<BundleResource Include="Resources\grad.jpg" />
</ItemGroup>
</Project>
Binary file added ExpandableViewSample.iOS/Resources/grad.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions ExpandableViewSample/AttachTapGestureToCustomViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ protected override void OnDisappearing()

private async void OnStatusChanged(object sender, StatusChangedEventArgs e)
{
var rotation = -1;
var rotation = 0;
switch(e.Status)
{
case ExpandStatus.Collapsing:
rotation = 0;
break;
case ExpandStatus.Expanding:
rotation = 180;
Expand All @@ -39,7 +38,7 @@ private async void OnStatusChanged(object sender, StatusChangedEventArgs e)
return;
}

await arrow.RotateTo(rotation, 250, Easing.BounceIn);
await arrow.RotateTo(rotation, 200, Easing.CubicInOut);
}
}
}
1 change: 1 addition & 0 deletions ExpandableViewSample/ExpandableViewSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.0.0.446417" />
<PackageReference Include="TouchView" Version="2.0.3" />
</ItemGroup>
<ItemGroup>
<Compile Remove="MainPage.xaml.cs" />
Expand Down
136 changes: 104 additions & 32 deletions ExpandableViewSample/ManyViewsPage.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
using System;
using Expandable;
using Xamarin.Forms;
using TouchEffect;
using System.Diagnostics;
namespace ExpandableViewSample
{
public class ManyViewsPage : ContentPage
{
public ManyViewsPage()
{
var mainStack = new StackLayout();
var mainStack = new StackLayout
{
Spacing = 15
};

for (int i = 0; i < 15; ++i)
{
mainStack.Children.Add(CreateExpandable(i));
}

BackgroundColor = Color.White;
BackgroundColor = Color.Black;
Content = new ScrollView
{
Padding = new Thickness(20, Device.RuntimePlatform == Device.iOS ? 20 : 0, 20, 0),
Expand All @@ -24,31 +29,24 @@ public ManyViewsPage()

private View CreateExpandable(int number)
{
var secondLabel = new Label
var middleImage = new Image
{
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.Center,
FontAttributes = FontAttributes.Italic,
HeightRequest = 40,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = $"The Label of {number}"
Aspect = Aspect.Fill,
Source = "grad.jpg"
};

return new ExpandableView
var arrowImage = new Image
{
PrimaryView = new Label
{
FontSize = 22,
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.Center,
FontAttributes = FontAttributes.Bold,
HeightRequest = 60,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = $"Click to expand {number}"
},
HorizontalOptions = LayoutOptions.EndAndExpand,
Source = "arrow_drop_down.png",
HeightRequest = 45,
WidthRequest = 45
};

var exp = new ExpandableView
{
IsTouchToExpandEnabled = false,
SecondaryViewTemplate = new DataTemplate(() => new StackLayout
{
Spacing = 10,
Expand All @@ -59,31 +57,105 @@ private View CreateExpandable(int number)
CornerRadius = 0,
FontAttributes = FontAttributes.Italic,
HeightRequest = 40,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = $"Increase height of label",
Command = new Command(() => ChangeHeight(secondLabel, 20))
BackgroundColor = Color.White,
TextColor = Color.Black,
Text = $"Increase height",
Command = new Command(() => ChangeHeight(middleImage, 20))
},
secondLabel,
middleImage,
new Button
{
CornerRadius = 0,
FontAttributes = FontAttributes.Italic,
HeightRequest = 40,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = $"Decrease height of the label",
Command = new Command(() => ChangeHeight(secondLabel, -20))
BackgroundColor = Color.White,
TextColor = Color.Black,
Text = $"Decrease height",
Command = new Command(() => ChangeHeight(middleImage, -20))
}
}
})
};

exp.StatusChanged += (sender, e) =>
{
var rotation = 0;
switch (e.Status)
{
case ExpandStatus.Collapsing:
break;
case ExpandStatus.Expanding:
rotation = 180;
break;
default:
return;
}
arrowImage.RotateTo(rotation, 200, Easing.CubicInOut);
};

exp.PrimaryView = new TouchView
{
RegularAnimationEasing = Easing.CubicInOut,
PressedAnimationEasing = Easing.CubicInOut,
RegularAnimationDuration = 600,
PressedAnimationDuration = 600,
RegularBackgroundColor = Color.White,
RippleCount = -1,
PressedBackgroundColor = Color.LightGray,
PressedScale = 1.2,
Command = new Command(() => exp.IsExpanded = !exp.IsExpanded)
};

exp.PrimaryView.ChildAdded += (sender, e) => ExpandableOnChildAdded(e.Element);

(exp.PrimaryView as TouchView).Children.Add(new Frame
{
CornerRadius = 5,
Padding = new Thickness(10, 0),
Content = new StackLayout
{
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.FillAndExpand,
Children =
{
new Label
{
FontSize = 22,
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.Center,
FontAttributes = FontAttributes.Bold,
HeightRequest = 60,
TextColor = Color.Black,
Text = $"Click to expand {number}"
},
arrowImage
}
}
});


(exp.PrimaryView as TouchView).StatusChanged += (sender, args) =>
{
if(args.Status == TouchEffect.Enums.TouchStatus.Canceled)
{
(exp.PrimaryView as TouchView).Command.Execute(null);
}
};

return exp;
}

protected void ExpandableOnChildAdded(Element child)
{
AbsoluteLayout.SetLayoutFlags(child, AbsoluteLayoutFlags.All);
AbsoluteLayout.SetLayoutBounds(child, new Rectangle(0, 0, 1, 1));
base.OnChildAdded(child);
}

private void ChangeHeight(Label target, double sizeChange)
private void ChangeHeight(View target, double sizeChange)
{
target.HeightRequest += sizeChange;
(target.Parent.Parent as ExpandableView).ForceUpdateSizeCommand.Execute(null);
(target.Parent.Parent as ExpandableView).ForceUpdateSize();
}
}
}

0 comments on commit 61dff77

Please sign in to comment.