Skip to content

Commit 61dff77

Browse files
updated sample
1 parent ce56440 commit 61dff77

File tree

10 files changed

+2843
-431
lines changed

10 files changed

+2843
-431
lines changed

ExpandableViewSample.Android/ExpandableViewSample.Android.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2" />
5454
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2" />
5555
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2" />
56+
<PackageReference Include="TouchView">
57+
<Version>2.0.3</Version>
58+
</PackageReference>
5659
</ItemGroup>
5760
<ItemGroup>
5861
<Compile Include="MainActivity.cs" />
@@ -84,6 +87,7 @@
8487
<AndroidResource Include="Resources\drawable-hdpi\arrow_drop_down.png" />
8588
<AndroidResource Include="Resources\drawable\arrow_drop_down.png" />
8689
<AndroidResource Include="Resources\drawable-xhdpi\arrow_drop_down.png" />
90+
<AndroidResource Include="Resources\drawable\grad.jpg" />
8791
</ItemGroup>
8892
<ItemGroup>
8993
<Folder Include="Resources\drawable\" />

ExpandableViewSample.Android/MainActivity.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Android.Views;
77
using Android.Widget;
88
using Android.OS;
9+
using TouchEffect.Droid;
910

1011
namespace ExpandableViewSample.Droid
1112
{
@@ -20,7 +21,8 @@ protected override void OnCreate(Bundle bundle)
2021
base.OnCreate(bundle);
2122

2223
global::Xamarin.Forms.Forms.Init(this, bundle);
23-
LoadApplication(new App());
24+
new TouchViewRenderer();
25+
LoadApplication(new App());
2426
}
2527
}
2628
}

ExpandableViewSample.Android/Resources/Resource.designer.cs

Lines changed: 2723 additions & 395 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
80.9 KB
Loading

ExpandableViewSample.iOS/AppDelegate.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using Foundation;
66
using UIKit;
7+
using TouchEffect.iOS;
78

89
namespace ExpandableViewSample.iOS
910
{
@@ -23,6 +24,7 @@ public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsAppli
2324
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
2425
{
2526
global::Xamarin.Forms.Forms.Init();
27+
TouchViewRenderer.Initialize();
2628
LoadApplication(new App());
2729

2830
return base.FinishedLaunching(app, options);

ExpandableViewSample.iOS/ExpandableViewSample.iOS.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@
148148
</ItemGroup>
149149
<ItemGroup>
150150
<PackageReference Include="Xamarin.Forms" Version="3.0.0.446417" />
151+
<PackageReference Include="TouchView">
152+
<Version>2.0.3</Version>
153+
</PackageReference>
151154
</ItemGroup>
152155
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
153156
<ItemGroup>
@@ -160,5 +163,6 @@
160163
<BundleResource Include="Resources\arrow_drop_down.png" />
161164
<BundleResource Include="Resources\arrow_drop_down%402x.png" />
162165
<BundleResource Include="Resources\arrow_drop_down%403x.png" />
166+
<BundleResource Include="Resources\grad.jpg" />
163167
</ItemGroup>
164168
</Project>
80.9 KB
Loading

ExpandableViewSample/AttachTapGestureToCustomViewPage.xaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ protected override void OnDisappearing()
2626

2727
private async void OnStatusChanged(object sender, StatusChangedEventArgs e)
2828
{
29-
var rotation = -1;
29+
var rotation = 0;
3030
switch(e.Status)
3131
{
3232
case ExpandStatus.Collapsing:
33-
rotation = 0;
3433
break;
3534
case ExpandStatus.Expanding:
3635
rotation = 180;
@@ -39,7 +38,7 @@ private async void OnStatusChanged(object sender, StatusChangedEventArgs e)
3938
return;
4039
}
4140

42-
await arrow.RotateTo(rotation, 250, Easing.BounceIn);
41+
await arrow.RotateTo(rotation, 200, Easing.CubicInOut);
4342
}
4443
}
4544
}

ExpandableViewSample/ExpandableViewSample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="Xamarin.Forms" Version="3.0.0.446417" />
9+
<PackageReference Include="TouchView" Version="2.0.3" />
910
</ItemGroup>
1011
<ItemGroup>
1112
<Compile Remove="MainPage.xaml.cs" />
Lines changed: 104 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
using System;
22
using Expandable;
33
using Xamarin.Forms;
4+
using TouchEffect;
5+
using System.Diagnostics;
46
namespace ExpandableViewSample
57
{
68
public class ManyViewsPage : ContentPage
79
{
810
public ManyViewsPage()
911
{
10-
var mainStack = new StackLayout();
12+
var mainStack = new StackLayout
13+
{
14+
Spacing = 15
15+
};
1116

1217
for (int i = 0; i < 15; ++i)
1318
{
1419
mainStack.Children.Add(CreateExpandable(i));
1520
}
1621

17-
BackgroundColor = Color.White;
22+
BackgroundColor = Color.Black;
1823
Content = new ScrollView
1924
{
2025
Padding = new Thickness(20, Device.RuntimePlatform == Device.iOS ? 20 : 0, 20, 0),
@@ -24,31 +29,24 @@ public ManyViewsPage()
2429

2530
private View CreateExpandable(int number)
2631
{
27-
var secondLabel = new Label
32+
var middleImage = new Image
2833
{
29-
VerticalTextAlignment = TextAlignment.Center,
30-
HorizontalTextAlignment = TextAlignment.Center,
31-
FontAttributes = FontAttributes.Italic,
3234
HeightRequest = 40,
33-
BackgroundColor = Color.Black,
34-
TextColor = Color.White,
35-
Text = $"The Label of {number}"
35+
Aspect = Aspect.Fill,
36+
Source = "grad.jpg"
3637
};
3738

38-
return new ExpandableView
39+
var arrowImage = new Image
3940
{
40-
PrimaryView = new Label
41-
{
42-
FontSize = 22,
43-
VerticalTextAlignment = TextAlignment.Center,
44-
HorizontalTextAlignment = TextAlignment.Center,
45-
FontAttributes = FontAttributes.Bold,
46-
HeightRequest = 60,
47-
BackgroundColor = Color.Black,
48-
TextColor = Color.White,
49-
Text = $"Click to expand {number}"
50-
},
41+
HorizontalOptions = LayoutOptions.EndAndExpand,
42+
Source = "arrow_drop_down.png",
43+
HeightRequest = 45,
44+
WidthRequest = 45
45+
};
5146

47+
var exp = new ExpandableView
48+
{
49+
IsTouchToExpandEnabled = false,
5250
SecondaryViewTemplate = new DataTemplate(() => new StackLayout
5351
{
5452
Spacing = 10,
@@ -59,31 +57,105 @@ private View CreateExpandable(int number)
5957
CornerRadius = 0,
6058
FontAttributes = FontAttributes.Italic,
6159
HeightRequest = 40,
62-
BackgroundColor = Color.Black,
63-
TextColor = Color.White,
64-
Text = $"Increase height of label",
65-
Command = new Command(() => ChangeHeight(secondLabel, 20))
60+
BackgroundColor = Color.White,
61+
TextColor = Color.Black,
62+
Text = $"Increase height",
63+
Command = new Command(() => ChangeHeight(middleImage, 20))
6664
},
67-
secondLabel,
65+
middleImage,
6866
new Button
6967
{
7068
CornerRadius = 0,
7169
FontAttributes = FontAttributes.Italic,
7270
HeightRequest = 40,
73-
BackgroundColor = Color.Black,
74-
TextColor = Color.White,
75-
Text = $"Decrease height of the label",
76-
Command = new Command(() => ChangeHeight(secondLabel, -20))
71+
BackgroundColor = Color.White,
72+
TextColor = Color.Black,
73+
Text = $"Decrease height",
74+
Command = new Command(() => ChangeHeight(middleImage, -20))
7775
}
7876
}
7977
})
8078
};
79+
80+
exp.StatusChanged += (sender, e) =>
81+
{
82+
var rotation = 0;
83+
switch (e.Status)
84+
{
85+
case ExpandStatus.Collapsing:
86+
break;
87+
case ExpandStatus.Expanding:
88+
rotation = 180;
89+
break;
90+
default:
91+
return;
92+
}
93+
arrowImage.RotateTo(rotation, 200, Easing.CubicInOut);
94+
};
95+
96+
exp.PrimaryView = new TouchView
97+
{
98+
RegularAnimationEasing = Easing.CubicInOut,
99+
PressedAnimationEasing = Easing.CubicInOut,
100+
RegularAnimationDuration = 600,
101+
PressedAnimationDuration = 600,
102+
RegularBackgroundColor = Color.White,
103+
RippleCount = -1,
104+
PressedBackgroundColor = Color.LightGray,
105+
PressedScale = 1.2,
106+
Command = new Command(() => exp.IsExpanded = !exp.IsExpanded)
107+
};
108+
109+
exp.PrimaryView.ChildAdded += (sender, e) => ExpandableOnChildAdded(e.Element);
110+
111+
(exp.PrimaryView as TouchView).Children.Add(new Frame
112+
{
113+
CornerRadius = 5,
114+
Padding = new Thickness(10, 0),
115+
Content = new StackLayout
116+
{
117+
Orientation = StackOrientation.Horizontal,
118+
HorizontalOptions = LayoutOptions.FillAndExpand,
119+
Children =
120+
{
121+
new Label
122+
{
123+
FontSize = 22,
124+
VerticalTextAlignment = TextAlignment.Center,
125+
HorizontalTextAlignment = TextAlignment.Center,
126+
FontAttributes = FontAttributes.Bold,
127+
HeightRequest = 60,
128+
TextColor = Color.Black,
129+
Text = $"Click to expand {number}"
130+
},
131+
arrowImage
132+
}
133+
}
134+
});
135+
136+
137+
(exp.PrimaryView as TouchView).StatusChanged += (sender, args) =>
138+
{
139+
if(args.Status == TouchEffect.Enums.TouchStatus.Canceled)
140+
{
141+
(exp.PrimaryView as TouchView).Command.Execute(null);
142+
}
143+
};
144+
145+
return exp;
146+
}
147+
148+
protected void ExpandableOnChildAdded(Element child)
149+
{
150+
AbsoluteLayout.SetLayoutFlags(child, AbsoluteLayoutFlags.All);
151+
AbsoluteLayout.SetLayoutBounds(child, new Rectangle(0, 0, 1, 1));
152+
base.OnChildAdded(child);
81153
}
82154

83-
private void ChangeHeight(Label target, double sizeChange)
155+
private void ChangeHeight(View target, double sizeChange)
84156
{
85157
target.HeightRequest += sizeChange;
86-
(target.Parent.Parent as ExpandableView).ForceUpdateSizeCommand.Execute(null);
158+
(target.Parent.Parent as ExpandableView).ForceUpdateSize();
87159
}
88160
}
89161
}

0 commit comments

Comments
 (0)