Skip to content

Commit

Permalink
Fixed iOS crash, added new props
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Nov 9, 2020
1 parent 0fb942d commit 7c8d00f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 70 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ HoveredRotationX | `double` | 0.0 | RotationX of hovered state
RegularRotationY | `double` | 0.0 | RotationY of regular state
PressedRotationY | `double` | 0.0 | RotationY of pressed state
HoveredRotationY | `double` | 0.0 | RotationY of hovered state
AnimationDuration | `int` | 0 | The common duration of animation
AnimationEasing | `Easing` | null | The common easing of animation
PressedAnimationDuration | `int` | 0 | The duration of animation by applying PressedOpacity and/or PressedBackgroundColor and/or PressedScale
PressedAnimationEasing | `Easing` | null | The easing of animation by applying PressedOpacity and/or PressedBackgroundColor and/or PressedScale
HoveredAnimationDuration | `int` | 0 | The duration of animation by applying HoveredOpacity and/or HoveredBackgroundColor and/or HoveredScale
Expand Down
2 changes: 1 addition & 1 deletion TouchEffect.iOS/PlatformTouchEff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void HandleTouch(TouchStatus status, UserInteractionState? userInteractio
_effect.HandleTouch(status);
if (userInteractionState.HasValue)
{
_effect.HandleUserInteraction(userInteractionState.Value);
_effect?.HandleUserInteraction(userInteractionState.Value);
}

if (_effect == null || !_effect.NativeAnimation || !_effect.CanExecute)
Expand Down
86 changes: 56 additions & 30 deletions TouchEffect/TouchEff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TouchEff : RoutingEffect
public TouchEff() : base($"{nameof(TouchEffect)}.{nameof(TouchEff)}")
=> _visualManager = new TouchVisualManager();

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

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

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

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


public static readonly BindableProperty LongPressCommandParameterProperty = BindableProperty.CreateAttached(
nameof(LongPressCommandParameter),
typeof(object),
Expand Down Expand Up @@ -394,6 +393,20 @@ internal TouchEff(Func<TouchEff, TouchState, HoverState, int, CancellationToken,
TryGenerateEffect(bindable, oldValue, newValue);
});

public static readonly BindableProperty AnimationDurationProperty = BindableProperty.CreateAttached(
nameof(AnimationDuration),
typeof(int),
typeof(TouchEff),
default(int),
propertyChanged: TryGenerateEffect);

public static readonly BindableProperty AnimationEasingProperty = BindableProperty.CreateAttached(
nameof(AnimationEasing),
typeof(Easing),
typeof(TouchEff),
null,
propertyChanged: TryGenerateEffect);

public static readonly BindableProperty PressedAnimationDurationProperty = BindableProperty.CreateAttached(
nameof(PressedAnimationDuration),
typeof(int),
Expand All @@ -415,20 +428,20 @@ internal TouchEff(Func<TouchEff, TouchState, HoverState, int, CancellationToken,
default(int),
propertyChanged: TryGenerateEffect);

public static readonly BindableProperty HoveredAnimationDurationProperty = BindableProperty.CreateAttached(
nameof(HoveredAnimationDuration),
typeof(int),
typeof(TouchEff),
default(int),
propertyChanged: TryGenerateEffect);

public static readonly BindableProperty RegularAnimationEasingProperty = BindableProperty.CreateAttached(
nameof(RegularAnimationEasing),
typeof(Easing),
typeof(TouchEff),
null,
propertyChanged: TryGenerateEffect);

public static readonly BindableProperty HoveredAnimationDurationProperty = BindableProperty.CreateAttached(
nameof(HoveredAnimationDuration),
typeof(int),
typeof(TouchEff),
default(int),
propertyChanged: TryGenerateEffect);

public static readonly BindableProperty HoveredAnimationEasingProperty = BindableProperty.CreateAttached(
nameof(HoveredAnimationEasing),
typeof(Easing),
Expand Down Expand Up @@ -459,9 +472,6 @@ internal TouchEff(Func<TouchEff, TouchState, HoverState, int, CancellationToken,
TryGenerateEffect(bindable, oldValue, newValue);
});

/// <summary>
/// Android only
/// </summary>
public static readonly BindableProperty DisallowTouchThresholdProperty = BindableProperty.CreateAttached(
nameof(DisallowTouchThreshold),
typeof(int),
Expand Down Expand Up @@ -713,42 +723,54 @@ public static double GetPressedRotationY(BindableObject bindable)
public static void SetPressedRotationY(BindableObject bindable, double value)
=> bindable.SetValue(PressedRotationYProperty, value);

public static int GetRegularAnimationDuration(BindableObject bindable)
=> (int)bindable.GetValue(RegularAnimationDurationProperty);
public static int GetAnimationDuration(BindableObject bindable)
=> (int)bindable.GetValue(AnimationDurationProperty);

public static void SetRegularAnimationDuration(BindableObject bindable, int value)
=> bindable.SetValue(RegularAnimationDurationProperty, value);
public static void SetAnimationDuration(BindableObject bindable, int value)
=> bindable.SetValue(AnimationDurationProperty, value);

public static int GetHoveredAnimationDuration(BindableObject bindable)
=> (int)bindable.GetValue(HoveredAnimationDurationProperty);
public static Easing GetAnimationEasing(BindableObject bindable)
=> bindable.GetValue(AnimationEasingProperty) as Easing;

public static void SetHoveredAnimationDuration(BindableObject bindable, int value)
=> bindable.SetValue(HoveredAnimationDurationProperty, value);
public static void SetAnimationEasing(BindableObject bindable, Easing value)
=> bindable.SetValue(AnimationEasingProperty, value);

public static int GetPressedAnimationDuration(BindableObject bindable)
=> (int)bindable.GetValue(PressedAnimationDurationProperty);
=> (int)bindable.GetValue(PressedAnimationDurationProperty);

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

public static Easing GetPressedAnimationEasing(BindableObject bindable)
=> bindable.GetValue(PressedAnimationEasingProperty) as Easing;

public static void SetPressedAnimationEasing(BindableObject bindable, Easing value)
=> bindable.SetValue(PressedAnimationEasingProperty, value);

public static int GetRegularAnimationDuration(BindableObject bindable)
=> (int)bindable.GetValue(RegularAnimationDurationProperty);

public static void SetRegularAnimationDuration(BindableObject bindable, int value)
=> bindable.SetValue(RegularAnimationDurationProperty, value);

public static Easing GetRegularAnimationEasing(BindableObject bindable)
=> bindable.GetValue(RegularAnimationEasingProperty) as Easing;

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

public static int GetHoveredAnimationDuration(BindableObject bindable)
=> (int)bindable.GetValue(HoveredAnimationDurationProperty);

public static void SetHoveredAnimationDuration(BindableObject bindable, int value)
=> bindable.SetValue(HoveredAnimationDurationProperty, value);

public static Easing GetHoveredAnimationEasing(BindableObject bindable)
=> bindable.GetValue(HoveredAnimationEasingProperty) as Easing;

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

public static Easing GetPressedAnimationEasing(BindableObject bindable)
=> bindable.GetValue(PressedAnimationEasingProperty) as Easing;

public static void SetPressedAnimationEasing(BindableObject bindable, Easing value)
=> bindable.SetValue(PressedAnimationEasingProperty, value);

public static int GetRippleCount(BindableObject bindable)
=> (int)bindable.GetValue(RippleCountProperty);

Expand Down Expand Up @@ -909,16 +931,20 @@ public HoverState HoverState

public double PressedRotationY => GetPressedRotationY(Control);

public int AnimationDuration => GetAnimationDuration(Control);

public Easing AnimationEasing => GetAnimationEasing(Control);

public int PressedAnimationDuration => GetPressedAnimationDuration(Control);

public Easing PressedAnimationEasing => GetPressedAnimationEasing(Control);

public int RegularAnimationDuration => GetRegularAnimationDuration(Control);

public int HoveredAnimationDuration => GetHoveredAnimationDuration(Control);

public Easing RegularAnimationEasing => GetRegularAnimationEasing(Control);

public int HoveredAnimationDuration => GetHoveredAnimationDuration(Control);

public Easing HoveredAnimationEasing => GetHoveredAnimationEasing(Control);

public int RippleCount => GetRippleCount(Control);
Expand Down
2 changes: 1 addition & 1 deletion TouchEffect/TouchImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public bool ShouldSetImageOnAnimationEnd
set => SetValue(ShouldSetImageOnAnimationEndProperty, value);
}

private async Task GetAnimationTask(TouchEff sender, TouchState touchState, HoverState hoverState, int duration, CancellationToken token)
private async Task GetAnimationTask(TouchEff sender, TouchState touchState, HoverState hoverState, int duration, Easing easing, CancellationToken token)
{
var regularBackgroundImageSource = RegularBackgroundImageSource;
var pressedBackgroundImageSource = PressedBackgroundImageSource;
Expand Down
Loading

0 comments on commit 7c8d00f

Please sign in to comment.