Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions samples/XCT.Sample/Pages/Views/ExpanderPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@
<Switch IsToggled="{Binding IsEnabled}" />
</StackLayout>
</xct:Expander.Header>
<xct:Expander IsEnabled="{Binding IsEnabled}">
<xct:Expander IsEnabled="{Binding IsEnabled}" TouchCaptureView="{x:Reference touchCaptureView}">
<xct:Expander.Header>
<Label Text="Nested expander" FontSize="30" FontAttributes="Bold"/>
<StackLayout Orientation="Horizontal">
<Label Text="Nested expander" FontSize="25" FontAttributes="Bold" VerticalOptions="Center"/>
<StackLayout x:Name="touchCaptureView" Orientation="Horizontal" VerticalOptions="Center" HorizontalOptions="EndAndExpand" xct:TouchEffect.NativeAnimation="True">
<Label Text=">" Rotation="90" FontSize="25" FontAttributes="Bold" TextColor="Black" />
<Label Text=">" Rotation="90" FontSize="25" FontAttributes="Bold" TextColor="Black" />
<Label Text=">" Rotation="90" FontSize="25" FontAttributes="Bold" TextColor="Black" />
</StackLayout>
</StackLayout>
</xct:Expander.Header>
<xct:Expander.ContentTemplate>
<DataTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,20 @@ public static readonly BindableProperty IsExpandedProperty
public static readonly BindableProperty DirectionProperty
= BindableProperty.Create(nameof(Direction), typeof(ExpandDirection), typeof(Expander), default(ExpandDirection), propertyChanged: OnDirectionPropertyChanged);

public static readonly BindableProperty TouchCaptureViewProperty
= BindableProperty.Create(nameof(TouchCaptureView), typeof(View), typeof(Expander), propertyChanged: OnTouchCaptureViewPropertyChanged);

public static readonly BindableProperty AnimationLengthProperty
= BindableProperty.Create(nameof(AnimationLength), typeof(uint), typeof(Expander), defaultAnimationLength);

public static readonly BindableProperty ExpandAnimationLengthProperty
= BindableProperty.Create(nameof(ExpandAnimationLength), typeof(uint), typeof(Expander), defaultAnimationLength);
= BindableProperty.Create(nameof(ExpandAnimationLength), typeof(uint), typeof(Expander), uint.MaxValue);

public static readonly BindableProperty CollapseAnimationLengthProperty
= BindableProperty.Create(nameof(CollapseAnimationLength), typeof(uint), typeof(Expander), defaultAnimationLength);
= BindableProperty.Create(nameof(CollapseAnimationLength), typeof(uint), typeof(Expander), uint.MaxValue);

public static readonly BindableProperty AnimationEasingProperty
= BindableProperty.Create(nameof(AnimationEasing), typeof(Easing), typeof(Expander));

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

public View? TouchCaptureView
{
get => (View?)GetValue(TouchCaptureViewProperty);
set => SetValue(TouchCaptureViewProperty, value);
}

public uint AnimationLength
{
get => (uint)GetValue(AnimationLengthProperty);
set => SetValue(AnimationLengthProperty, value);
}

public uint ExpandAnimationLength
{
get => (uint)GetValue(ExpandAnimationLengthProperty);
Expand All @@ -158,6 +179,12 @@ public uint CollapseAnimationLength
set => SetValue(CollapseAnimationLengthProperty, value);
}

public Easing AnimationEasing
{
get => (Easing)GetValue(AnimationEasingProperty);
set => SetValue(AnimationEasingProperty, value);
}

public Easing ExpandAnimationEasing
{
get => (Easing)GetValue(ExpandAnimationEasingProperty);
Expand Down Expand Up @@ -256,6 +283,9 @@ static void OnIsExpandedPropertyChanged(BindableObject bindable, object oldValue
static void OnDirectionPropertyChanged(BindableObject bindable, object oldValue, object newValue)
=> ((Expander)bindable).OnDirectionPropertyChanged((ExpandDirection)oldValue);

static void OnTouchCaptureViewPropertyChanged(BindableObject bindable, object oldValue, object newValue)
=> ((Expander)bindable).OnTouchCaptureViewPropertyChanged((View?)oldValue);

static object GetDefaultForceUpdateSizeCommand(BindableObject bindable)
=> new Command(((Expander)bindable).ForceUpdateSize);

Expand All @@ -271,8 +301,11 @@ void OnContentTemplatePropertyChanged()
void OnIsExpandedPropertyChanged()
=> SetContent(false);

void OnDirectionPropertyChanged(ExpandDirection olddirection)
=> SetDirection(olddirection);
void OnDirectionPropertyChanged(ExpandDirection oldDirection)
=> SetDirection(oldDirection);

void OnTouchCaptureViewPropertyChanged(View? oldView)
=> SetTouchCaptureView(oldView);

void OnIsExpandedChanged(bool shouldIgnoreAnimation = false)
{
Expand Down Expand Up @@ -319,7 +352,6 @@ void SetHeader(View? oldHeader)
{
if (oldHeader != null)
{
oldHeader.GestureRecognizers.Remove(headerTapGestureRecognizer);
Control?.Children.Remove(oldHeader);
}

Expand All @@ -329,9 +361,9 @@ void SetHeader(View? oldHeader)
Control?.Children.Insert(0, Header);
else
Control?.Children.Add(Header);

Header.GestureRecognizers.Add(headerTapGestureRecognizer);
}

SetTouchCaptureView(oldHeader);
}

void SetContent(bool isForceUpdate, bool shouldIgnoreAnimation = false, bool isForceContentReset = false)
Expand Down Expand Up @@ -417,6 +449,14 @@ void SetDirection(ExpandDirection oldDirection)
SetContent(true, true, true);
}

void SetTouchCaptureView(View? oldView)
{
oldView?.GestureRecognizers.Remove(headerTapGestureRecognizer);
TouchCaptureView?.GestureRecognizers?.Remove(headerTapGestureRecognizer);
Header?.GestureRecognizers.Remove(headerTapGestureRecognizer);
(TouchCaptureView ?? Header)?.GestureRecognizers.Add(headerTapGestureRecognizer);
}

void InvokeAnimation(double startSize, double endSize, bool shouldIgnoreAnimation)
{
State = IsExpanded
Expand All @@ -443,6 +483,11 @@ void InvokeAnimation(double startSize, double endSize, bool shouldIgnoreAnimatio
easing = ExpandAnimationEasing;
}

if (length == uint.MaxValue)
length = AnimationLength;

easing ??= AnimationEasing;

if (lastVisibleSize > 0)
length = (uint)(length * (Abs(endSize - startSize) / lastVisibleSize));

Expand Down