Skip to content

Commit 7c8d00f

Browse files
Fixed iOS crash, added new props
1 parent 0fb942d commit 7c8d00f

File tree

5 files changed

+82
-70
lines changed

5 files changed

+82
-70
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ HoveredRotationX | `double` | 0.0 | RotationX of hovered state
155155
RegularRotationY | `double` | 0.0 | RotationY of regular state
156156
PressedRotationY | `double` | 0.0 | RotationY of pressed state
157157
HoveredRotationY | `double` | 0.0 | RotationY of hovered state
158+
AnimationDuration | `int` | 0 | The common duration of animation
159+
AnimationEasing | `Easing` | null | The common easing of animation
158160
PressedAnimationDuration | `int` | 0 | The duration of animation by applying PressedOpacity and/or PressedBackgroundColor and/or PressedScale
159161
PressedAnimationEasing | `Easing` | null | The easing of animation by applying PressedOpacity and/or PressedBackgroundColor and/or PressedScale
160162
HoveredAnimationDuration | `int` | 0 | The duration of animation by applying HoveredOpacity and/or HoveredBackgroundColor and/or HoveredScale

TouchEffect.iOS/PlatformTouchEff.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void HandleTouch(TouchStatus status, UserInteractionState? userInteractio
152152
_effect.HandleTouch(status);
153153
if (userInteractionState.HasValue)
154154
{
155-
_effect.HandleUserInteraction(userInteractionState.Value);
155+
_effect?.HandleUserInteraction(userInteractionState.Value);
156156
}
157157

158158
if (_effect == null || !_effect.NativeAnimation || !_effect.CanExecute)

TouchEffect/TouchEff.cs

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class TouchEff : RoutingEffect
2020
public TouchEff() : base($"{nameof(TouchEffect)}.{nameof(TouchEff)}")
2121
=> _visualManager = new TouchVisualManager();
2222

23-
internal TouchEff(Func<TouchEff, TouchState, HoverState, int, CancellationToken, Task> animationTaskGetter) : this()
23+
internal TouchEff(Func<TouchEff, TouchState, HoverState, int, Easing, CancellationToken, Task> animationTaskGetter) : this()
2424
=> _visualManager.SetCustomAnimationTask(animationTaskGetter);
2525

2626
public event TEffectStatusChangedHandler StatusChanged;
@@ -38,7 +38,7 @@ internal TouchEff(Func<TouchEff, TouchState, HoverState, int, CancellationToken,
3838
public event AnimationStartedHandler AnimationStarted;
3939

4040
//The backdor for https://github.com/AndreiMisiukevich/TouchEffect/issues/71
41-
[EditorBrowsable(EditorBrowsableState.Advanced)]
41+
[EditorBrowsable(EditorBrowsableState.Never)]
4242
public static bool IsForceUpdateStateAnimatedForIsToggledProperty { get; set; }
4343

4444
public static readonly BindableProperty IsAvailableProperty = BindableProperty.CreateAttached(
@@ -80,7 +80,6 @@ internal TouchEff(Func<TouchEff, TouchState, HoverState, int, CancellationToken,
8080
default(object),
8181
propertyChanged: TryGenerateEffect);
8282

83-
8483
public static readonly BindableProperty LongPressCommandParameterProperty = BindableProperty.CreateAttached(
8584
nameof(LongPressCommandParameter),
8685
typeof(object),
@@ -394,6 +393,20 @@ internal TouchEff(Func<TouchEff, TouchState, HoverState, int, CancellationToken,
394393
TryGenerateEffect(bindable, oldValue, newValue);
395394
});
396395

396+
public static readonly BindableProperty AnimationDurationProperty = BindableProperty.CreateAttached(
397+
nameof(AnimationDuration),
398+
typeof(int),
399+
typeof(TouchEff),
400+
default(int),
401+
propertyChanged: TryGenerateEffect);
402+
403+
public static readonly BindableProperty AnimationEasingProperty = BindableProperty.CreateAttached(
404+
nameof(AnimationEasing),
405+
typeof(Easing),
406+
typeof(TouchEff),
407+
null,
408+
propertyChanged: TryGenerateEffect);
409+
397410
public static readonly BindableProperty PressedAnimationDurationProperty = BindableProperty.CreateAttached(
398411
nameof(PressedAnimationDuration),
399412
typeof(int),
@@ -415,20 +428,20 @@ internal TouchEff(Func<TouchEff, TouchState, HoverState, int, CancellationToken,
415428
default(int),
416429
propertyChanged: TryGenerateEffect);
417430

418-
public static readonly BindableProperty HoveredAnimationDurationProperty = BindableProperty.CreateAttached(
419-
nameof(HoveredAnimationDuration),
420-
typeof(int),
421-
typeof(TouchEff),
422-
default(int),
423-
propertyChanged: TryGenerateEffect);
424-
425431
public static readonly BindableProperty RegularAnimationEasingProperty = BindableProperty.CreateAttached(
426432
nameof(RegularAnimationEasing),
427433
typeof(Easing),
428434
typeof(TouchEff),
429435
null,
430436
propertyChanged: TryGenerateEffect);
431437

438+
public static readonly BindableProperty HoveredAnimationDurationProperty = BindableProperty.CreateAttached(
439+
nameof(HoveredAnimationDuration),
440+
typeof(int),
441+
typeof(TouchEff),
442+
default(int),
443+
propertyChanged: TryGenerateEffect);
444+
432445
public static readonly BindableProperty HoveredAnimationEasingProperty = BindableProperty.CreateAttached(
433446
nameof(HoveredAnimationEasing),
434447
typeof(Easing),
@@ -459,9 +472,6 @@ internal TouchEff(Func<TouchEff, TouchState, HoverState, int, CancellationToken,
459472
TryGenerateEffect(bindable, oldValue, newValue);
460473
});
461474

462-
/// <summary>
463-
/// Android only
464-
/// </summary>
465475
public static readonly BindableProperty DisallowTouchThresholdProperty = BindableProperty.CreateAttached(
466476
nameof(DisallowTouchThreshold),
467477
typeof(int),
@@ -713,42 +723,54 @@ public static double GetPressedRotationY(BindableObject bindable)
713723
public static void SetPressedRotationY(BindableObject bindable, double value)
714724
=> bindable.SetValue(PressedRotationYProperty, value);
715725

716-
public static int GetRegularAnimationDuration(BindableObject bindable)
717-
=> (int)bindable.GetValue(RegularAnimationDurationProperty);
726+
public static int GetAnimationDuration(BindableObject bindable)
727+
=> (int)bindable.GetValue(AnimationDurationProperty);
718728

719-
public static void SetRegularAnimationDuration(BindableObject bindable, int value)
720-
=> bindable.SetValue(RegularAnimationDurationProperty, value);
729+
public static void SetAnimationDuration(BindableObject bindable, int value)
730+
=> bindable.SetValue(AnimationDurationProperty, value);
721731

722-
public static int GetHoveredAnimationDuration(BindableObject bindable)
723-
=> (int)bindable.GetValue(HoveredAnimationDurationProperty);
732+
public static Easing GetAnimationEasing(BindableObject bindable)
733+
=> bindable.GetValue(AnimationEasingProperty) as Easing;
724734

725-
public static void SetHoveredAnimationDuration(BindableObject bindable, int value)
726-
=> bindable.SetValue(HoveredAnimationDurationProperty, value);
735+
public static void SetAnimationEasing(BindableObject bindable, Easing value)
736+
=> bindable.SetValue(AnimationEasingProperty, value);
727737

728738
public static int GetPressedAnimationDuration(BindableObject bindable)
729-
=> (int)bindable.GetValue(PressedAnimationDurationProperty);
739+
=> (int)bindable.GetValue(PressedAnimationDurationProperty);
730740

731741
public static void SetPressedAnimationDuration(BindableObject bindable, int value)
732742
=> bindable.SetValue(PressedAnimationDurationProperty, value);
733743

744+
public static Easing GetPressedAnimationEasing(BindableObject bindable)
745+
=> bindable.GetValue(PressedAnimationEasingProperty) as Easing;
746+
747+
public static void SetPressedAnimationEasing(BindableObject bindable, Easing value)
748+
=> bindable.SetValue(PressedAnimationEasingProperty, value);
749+
750+
public static int GetRegularAnimationDuration(BindableObject bindable)
751+
=> (int)bindable.GetValue(RegularAnimationDurationProperty);
752+
753+
public static void SetRegularAnimationDuration(BindableObject bindable, int value)
754+
=> bindable.SetValue(RegularAnimationDurationProperty, value);
755+
734756
public static Easing GetRegularAnimationEasing(BindableObject bindable)
735757
=> bindable.GetValue(RegularAnimationEasingProperty) as Easing;
736758

737759
public static void SetRegularAnimationEasing(BindableObject bindable, Easing value)
738760
=> bindable.SetValue(RegularAnimationEasingProperty, value);
739761

762+
public static int GetHoveredAnimationDuration(BindableObject bindable)
763+
=> (int)bindable.GetValue(HoveredAnimationDurationProperty);
764+
765+
public static void SetHoveredAnimationDuration(BindableObject bindable, int value)
766+
=> bindable.SetValue(HoveredAnimationDurationProperty, value);
767+
740768
public static Easing GetHoveredAnimationEasing(BindableObject bindable)
741769
=> bindable.GetValue(HoveredAnimationEasingProperty) as Easing;
742770

743771
public static void SetHoveredAnimationEasing(BindableObject bindable, Easing value)
744772
=> bindable.SetValue(HoveredAnimationEasingProperty, value);
745773

746-
public static Easing GetPressedAnimationEasing(BindableObject bindable)
747-
=> bindable.GetValue(PressedAnimationEasingProperty) as Easing;
748-
749-
public static void SetPressedAnimationEasing(BindableObject bindable, Easing value)
750-
=> bindable.SetValue(PressedAnimationEasingProperty, value);
751-
752774
public static int GetRippleCount(BindableObject bindable)
753775
=> (int)bindable.GetValue(RippleCountProperty);
754776

@@ -909,16 +931,20 @@ public HoverState HoverState
909931

910932
public double PressedRotationY => GetPressedRotationY(Control);
911933

934+
public int AnimationDuration => GetAnimationDuration(Control);
935+
936+
public Easing AnimationEasing => GetAnimationEasing(Control);
937+
912938
public int PressedAnimationDuration => GetPressedAnimationDuration(Control);
913939

914940
public Easing PressedAnimationEasing => GetPressedAnimationEasing(Control);
915941

916942
public int RegularAnimationDuration => GetRegularAnimationDuration(Control);
917943

918-
public int HoveredAnimationDuration => GetHoveredAnimationDuration(Control);
919-
920944
public Easing RegularAnimationEasing => GetRegularAnimationEasing(Control);
921945

946+
public int HoveredAnimationDuration => GetHoveredAnimationDuration(Control);
947+
922948
public Easing HoveredAnimationEasing => GetHoveredAnimationEasing(Control);
923949

924950
public int RippleCount => GetRippleCount(Control);

TouchEffect/TouchImage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public bool ShouldSetImageOnAnimationEnd
121121
set => SetValue(ShouldSetImageOnAnimationEndProperty, value);
122122
}
123123

124-
private async Task GetAnimationTask(TouchEff sender, TouchState touchState, HoverState hoverState, int duration, CancellationToken token)
124+
private async Task GetAnimationTask(TouchEff sender, TouchState touchState, HoverState hoverState, int duration, Easing easing, CancellationToken token)
125125
{
126126
var regularBackgroundImageSource = RegularBackgroundImageSource;
127127
var pressedBackgroundImageSource = PressedBackgroundImageSource;

0 commit comments

Comments
 (0)