Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 4711e71

Browse files
Expander: Add touch capture view + common animation length / easing properties (#1349)
* Added base animation props * Added TouchCaptureView property
1 parent b558d91 commit 4711e71

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

samples/XCT.Sample/Pages/Views/ExpanderPage.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@
2727
<Switch IsToggled="{Binding IsEnabled}" />
2828
</StackLayout>
2929
</xct:Expander.Header>
30-
<xct:Expander IsEnabled="{Binding IsEnabled}">
30+
<xct:Expander IsEnabled="{Binding IsEnabled}" TouchCaptureView="{x:Reference touchCaptureView}">
3131
<xct:Expander.Header>
32-
<Label Text="Nested expander" FontSize="30" FontAttributes="Bold"/>
32+
<StackLayout Orientation="Horizontal">
33+
<Label Text="Nested expander" FontSize="25" FontAttributes="Bold" VerticalOptions="Center"/>
34+
<StackLayout x:Name="touchCaptureView" Orientation="Horizontal" VerticalOptions="Center" HorizontalOptions="EndAndExpand" xct:TouchEffect.NativeAnimation="True">
35+
<Label Text=">" Rotation="90" FontSize="25" FontAttributes="Bold" TextColor="Black" />
36+
<Label Text=">" Rotation="90" FontSize="25" FontAttributes="Bold" TextColor="Black" />
37+
<Label Text=">" Rotation="90" FontSize="25" FontAttributes="Bold" TextColor="Black" />
38+
</StackLayout>
39+
</StackLayout>
3340
</xct:Expander.Header>
3441
<xct:Expander.ContentTemplate>
3542
<DataTemplate>

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Expander/Expander.shared.cs

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,20 @@ public static readonly BindableProperty IsExpandedProperty
5151
public static readonly BindableProperty DirectionProperty
5252
= BindableProperty.Create(nameof(Direction), typeof(ExpandDirection), typeof(Expander), default(ExpandDirection), propertyChanged: OnDirectionPropertyChanged);
5353

54+
public static readonly BindableProperty TouchCaptureViewProperty
55+
= BindableProperty.Create(nameof(TouchCaptureView), typeof(View), typeof(Expander), propertyChanged: OnTouchCaptureViewPropertyChanged);
56+
57+
public static readonly BindableProperty AnimationLengthProperty
58+
= BindableProperty.Create(nameof(AnimationLength), typeof(uint), typeof(Expander), defaultAnimationLength);
59+
5460
public static readonly BindableProperty ExpandAnimationLengthProperty
55-
= BindableProperty.Create(nameof(ExpandAnimationLength), typeof(uint), typeof(Expander), defaultAnimationLength);
61+
= BindableProperty.Create(nameof(ExpandAnimationLength), typeof(uint), typeof(Expander), uint.MaxValue);
5662

5763
public static readonly BindableProperty CollapseAnimationLengthProperty
58-
= BindableProperty.Create(nameof(CollapseAnimationLength), typeof(uint), typeof(Expander), defaultAnimationLength);
64+
= BindableProperty.Create(nameof(CollapseAnimationLength), typeof(uint), typeof(Expander), uint.MaxValue);
65+
66+
public static readonly BindableProperty AnimationEasingProperty
67+
= BindableProperty.Create(nameof(AnimationEasing), typeof(Easing), typeof(Expander));
5968

6069
public static readonly BindableProperty ExpandAnimationEasingProperty
6170
= BindableProperty.Create(nameof(ExpandAnimationEasing), typeof(Easing), typeof(Expander));
@@ -146,6 +155,18 @@ public ExpandDirection Direction
146155
set => SetValue(DirectionProperty, value);
147156
}
148157

158+
public View? TouchCaptureView
159+
{
160+
get => (View?)GetValue(TouchCaptureViewProperty);
161+
set => SetValue(TouchCaptureViewProperty, value);
162+
}
163+
164+
public uint AnimationLength
165+
{
166+
get => (uint)GetValue(AnimationLengthProperty);
167+
set => SetValue(AnimationLengthProperty, value);
168+
}
169+
149170
public uint ExpandAnimationLength
150171
{
151172
get => (uint)GetValue(ExpandAnimationLengthProperty);
@@ -158,6 +179,12 @@ public uint CollapseAnimationLength
158179
set => SetValue(CollapseAnimationLengthProperty, value);
159180
}
160181

182+
public Easing AnimationEasing
183+
{
184+
get => (Easing)GetValue(AnimationEasingProperty);
185+
set => SetValue(AnimationEasingProperty, value);
186+
}
187+
161188
public Easing ExpandAnimationEasing
162189
{
163190
get => (Easing)GetValue(ExpandAnimationEasingProperty);
@@ -256,6 +283,9 @@ static void OnIsExpandedPropertyChanged(BindableObject bindable, object oldValue
256283
static void OnDirectionPropertyChanged(BindableObject bindable, object oldValue, object newValue)
257284
=> ((Expander)bindable).OnDirectionPropertyChanged((ExpandDirection)oldValue);
258285

286+
static void OnTouchCaptureViewPropertyChanged(BindableObject bindable, object oldValue, object newValue)
287+
=> ((Expander)bindable).OnTouchCaptureViewPropertyChanged((View?)oldValue);
288+
259289
static object GetDefaultForceUpdateSizeCommand(BindableObject bindable)
260290
=> new Command(((Expander)bindable).ForceUpdateSize);
261291

@@ -271,8 +301,11 @@ void OnContentTemplatePropertyChanged()
271301
void OnIsExpandedPropertyChanged()
272302
=> SetContent(false);
273303

274-
void OnDirectionPropertyChanged(ExpandDirection olddirection)
275-
=> SetDirection(olddirection);
304+
void OnDirectionPropertyChanged(ExpandDirection oldDirection)
305+
=> SetDirection(oldDirection);
306+
307+
void OnTouchCaptureViewPropertyChanged(View? oldView)
308+
=> SetTouchCaptureView(oldView);
276309

277310
void OnIsExpandedChanged(bool shouldIgnoreAnimation = false)
278311
{
@@ -319,7 +352,6 @@ void SetHeader(View? oldHeader)
319352
{
320353
if (oldHeader != null)
321354
{
322-
oldHeader.GestureRecognizers.Remove(headerTapGestureRecognizer);
323355
Control?.Children.Remove(oldHeader);
324356
}
325357

@@ -329,9 +361,9 @@ void SetHeader(View? oldHeader)
329361
Control?.Children.Insert(0, Header);
330362
else
331363
Control?.Children.Add(Header);
332-
333-
Header.GestureRecognizers.Add(headerTapGestureRecognizer);
334364
}
365+
366+
SetTouchCaptureView(oldHeader);
335367
}
336368

337369
void SetContent(bool isForceUpdate, bool shouldIgnoreAnimation = false, bool isForceContentReset = false)
@@ -417,6 +449,14 @@ void SetDirection(ExpandDirection oldDirection)
417449
SetContent(true, true, true);
418450
}
419451

452+
void SetTouchCaptureView(View? oldView)
453+
{
454+
oldView?.GestureRecognizers.Remove(headerTapGestureRecognizer);
455+
TouchCaptureView?.GestureRecognizers?.Remove(headerTapGestureRecognizer);
456+
Header?.GestureRecognizers.Remove(headerTapGestureRecognizer);
457+
(TouchCaptureView ?? Header)?.GestureRecognizers.Add(headerTapGestureRecognizer);
458+
}
459+
420460
void InvokeAnimation(double startSize, double endSize, bool shouldIgnoreAnimation)
421461
{
422462
State = IsExpanded
@@ -443,6 +483,11 @@ void InvokeAnimation(double startSize, double endSize, bool shouldIgnoreAnimatio
443483
easing = ExpandAnimationEasing;
444484
}
445485

486+
if (length == uint.MaxValue)
487+
length = AnimationLength;
488+
489+
easing ??= AnimationEasing;
490+
446491
if (lastVisibleSize > 0)
447492
length = (uint)(length * (Abs(endSize - startSize) / lastVisibleSize));
448493

0 commit comments

Comments
 (0)