Skip to content

Commit

Permalink
chore: Revert PR unoplatform#11865 as it's no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Feb 19, 2024
1 parent 00c6bfe commit 56db9ce
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 129 deletions.
65 changes: 7 additions & 58 deletions src/Uno.UI/DataBinding/BindingPath.BindingItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ private sealed class BindingItem : IBindingItem, IDisposable
private ValueGetterHandler? _substituteValueGetter;
private ValueSetterHandler? _valueSetter;
private ValueSetterHandler? _localValueSetter;
private ValueSetterHandler? _animationFillingValueSetter;
private ValueUnsetterHandler? _valueUnsetter;
private ValueUnsetterHandler? _animationFillingValueUnsetter;

private Type? _dataContextType;

Expand Down Expand Up @@ -128,12 +126,6 @@ public void SetLocalValue(object value)
SetSourceValue(_localValueSetter!, value);
}

public void SetAnimationFillingValue(object value)
{
BuildAnimationFillingValueSetter();
SetSourceValue(_animationFillingValueSetter!, value);
}

public Type? PropertyType
{
get
Expand Down Expand Up @@ -247,15 +239,14 @@ private void BuildValueSetter()
{
if (_valueSetter == null && _dataContextType != null)
{
_valueSetter = BindingPropertyHelper.GetValueSetter(
_dataContextType,
PropertyName,
convert: true,
precedence: _precedence ?? DependencyPropertyValuePrecedences.Local
);
if (_precedence == null)
{
_localValueSetter = _valueSetter;
BuildLocalValueSetter();
_valueSetter = _localValueSetter;
}
else
{
_valueSetter = BindingPropertyHelper.GetValueSetter(_dataContextType, PropertyName, convert: true, precedence: _precedence.Value);
}
}
}
Expand All @@ -264,25 +255,7 @@ private void BuildLocalValueSetter()
{
if (_localValueSetter == null && _dataContextType != null)
{
_localValueSetter = BindingPropertyHelper.GetValueSetter(
_dataContextType,
PropertyName,
convert: true,
precedence: DependencyPropertyValuePrecedences.Local
);
}
}

private void BuildAnimationFillingValueSetter()
{
if (_animationFillingValueSetter == null && _dataContextType != null)
{
_animationFillingValueSetter = BindingPropertyHelper.GetValueSetter(
_dataContextType,
PropertyName,
convert: true,
precedence: DependencyPropertyValuePrecedences.FillingAnimations
);
_localValueSetter = BindingPropertyHelper.GetValueSetter(_dataContextType, PropertyName, convert: true);
}
}

Expand Down Expand Up @@ -408,30 +381,6 @@ internal void ClearValue()
}
}

private void BuildAnimationFillingValueUnsetter()
{
if (_animationFillingValueUnsetter == null && _dataContextType != null)
{
_animationFillingValueUnsetter = BindingPropertyHelper.GetValueUnsetter(
_dataContextType,
PropertyName,
precedence: DependencyPropertyValuePrecedences.FillingAnimations
);
}
}

internal void ClearAnimationFillingValue()
{
BuildAnimationFillingValueUnsetter();

// Capture the datacontext before the call to avoid a race condition with the GC.
var dataContext = DataContext;
if (dataContext != null)
{
_animationFillingValueUnsetter!(dataContext);
}
}

private void RaiseValueChanged(object? newValue)
{
ValueChangedListener?.OnValueChanged(newValue);
Expand Down
15 changes: 0 additions & 15 deletions src/Uno.UI/DataBinding/BindingPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,6 @@ internal void SetLocalValue(object value)
}
}

internal void SetAnimationFillingValue(object value)
{
if (!_disposed)
{
_value?.SetAnimationFillingValue(value);
}
}

/// <summary>
/// Clears the value of the current precedence.
/// </summary>
Expand All @@ -265,13 +257,6 @@ public void ClearValue()
_value?.ClearValue();
}
}
public void ClearAnimationFillingValue()
{
if (!_disposed)
{
_value?.ClearAnimationFillingValue();
}
}

public Type? ValueType => _value?.PropertyType;

Expand Down
29 changes: 2 additions & 27 deletions src/Uno.UI/UI/Xaml/DependencyPropertyDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,33 +178,8 @@ private void SetValueFull(object? value, DependencyPropertyValuePrecedences prec
return;
}

// On Windows, explicitly calling SetValue(dp, DP.UnsetValue) or ClearValue(dp) doesnt clear the animation value.
// (note: Both the methods target local value)
// This means that we should not be handling those special case in here. Instead,
// when Timeline clears the animation value, it should also clears the filling animation value at the same time.
// ---
// Clear the animated value, when we are setting a local value to a property
// with an animated value from the filling part of an HoldEnd animation.
// note: There is no equivalent block in SetValueFast, as its condition would never be satisfied:
// _stack would've been materialized if the property had been animated.
bool forceUpdatePrecedence = false;
if (!valueIsUnsetValue &&
_highestPrecedence == DependencyPropertyValuePrecedences.FillingAnimations &&
(precedence is DependencyPropertyValuePrecedences.Local or DependencyPropertyValuePrecedences.Animations))
{
stackAlias[(int)DependencyPropertyValuePrecedences.FillingAnimations] = UnsetValue.Instance;
if (precedence is DependencyPropertyValuePrecedences.Local)
{
stackAlias[(int)DependencyPropertyValuePrecedences.Animations] = UnsetValue.Instance;
}

forceUpdatePrecedence = true;
}

// Update highest precedence, when the current highest value was unset or
// when animation value was overridden by local value.
if ((valueIsUnsetValue && precedence == _highestPrecedence) ||
forceUpdatePrecedence)
// If we were unsetting the current highest precedence value, we need to find the next highest
if (valueIsUnsetValue && precedence == _highestPrecedence)
{
// Start from current precedence and find next highest
for (int i = (int)precedence; i < (int)DependencyPropertyValuePrecedences.DefaultValue; i++)
Expand Down
6 changes: 0 additions & 6 deletions src/Uno.UI/UI/Xaml/DependencyPropertyValuePrecedences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ public enum DependencyPropertyValuePrecedences : int
/// </summary>
Coercion = 0,

/// <summary>
/// Defined when filling from a HoldEnd animation
/// </summary>
/// <remarks>Set the animation or local value will clear this value.</remarks>
FillingAnimations,

/// <summary>
/// Defined by animation storyboards
/// </summary>
Expand Down
25 changes: 12 additions & 13 deletions src/Uno.UI/UI/Xaml/Media/Animation/Timeline.animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ private TimelineState State
private string[] GetTraceProperties() => _owner?.GetTraceProperties();

private void ClearValue() => _owner?.ClearValue();
private void ClearAnimationFillingValue() => _owner?.ClearAnimationFillingValue();
private void SetValue(object value) => _owner?.SetValue(value);
private void SetAnimationFillingValue(object value) => _owner?.SetAnimationFillingValue(value);
private object GetValue() => _owner?.GetValue();
private object GetNonAnimatedValue() => _owner?.GetNonAnimatedValue();
private bool NeedsRepeat(Stopwatch activeDuration, int replayCount) => _owner?.NeedsRepeat(activeDuration, replayCount) ?? false;
Expand Down Expand Up @@ -116,7 +114,6 @@ public void Stop()
_animator?.Cancel(); // stop could be called before the initialization
_startingValue = null;
ClearValue();
ClearAnimationFillingValue();
State = TimelineState.Stopped;
}

Expand Down Expand Up @@ -197,7 +194,6 @@ public void SkipToFill()
// Set property to its final value
var value = ComputeToValue();
SetValue(value);
SetAnimationFillingValue(value);

OnEnd();
}
Expand Down Expand Up @@ -352,20 +348,24 @@ private void OnEnd()
// There are two types of fill behaviors:
if (FillBehavior == FillBehavior.HoldEnd) // HoldEnd: Keep displaying the last frame
{
#if __IOS__ || __MACOS__
// iOS && macOS: Here we make sure that the final frame is applied properly (it may have been skipped by animator)
// Note: The value is applied using the "Animations" precedence, which means that the user won't be able to alter
// it from application code. Instead we should set the value using a lower precedence
// (possibly "Local" with PropertyInfo.SetLocalValue(ComputeToValue())) but we must keep the
// original "Local" value, so will be able to rollback the animation when
// going to another VisualState (if the storyboard ran in that context).
// In that case we should also do "ClearValue();" to remove the "Animations" value, even if using "HoldEnd"
// cf. https://github.com/unoplatform/uno/issues/631
PropertyInfo.Value = ComputeToValue();
#endif
State = TimelineState.Filling;

// The HoldEnd value can be overriden by setting a Local value while it is filling, but not while it is animating.
// Since in the dependency property, we doesnt have the context here as to wheter the "animation value" is animating or filling,
// we also need to set the AnimationFilling value to indicate the case.
SetValue(ComputeToValue());
SetAnimationFillingValue(ComputeToValue());
}
else // Stop: Put back the initial state
{
State = TimelineState.Stopped;

ClearValue();
ClearAnimationFillingValue();
}

_owner.OnCompleted();
Expand All @@ -381,7 +381,6 @@ private void OnAnimatorFailed(object sender, EventArgs e)
State = TimelineState.Stopped;

ClearValue();
ClearAnimationFillingValue();

_owner.OnFailed();
}
Expand Down Expand Up @@ -441,7 +440,7 @@ private T ComputeFromValue()
var value = FeatureConfiguration.Timeline.DefaultsStartingValueFromAnimatedValue
? GetValueCore()
: GetNonAnimatedValue();
if (value != null && value != DependencyProperty.UnsetValue)
if (value != null)
{
return AnimationOwner.Convert(value);
}
Expand Down
10 changes: 0 additions & 10 deletions src/Uno.UI/UI/Xaml/Media/Animation/Timeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,6 @@ protected void SetValue(object value)
PropertyInfo.Value = value;
}

internal void SetAnimationFillingValue(object value)
{
PropertyInfo.SetAnimationFillingValue(value);
}

/// <summary>
/// Clears the animated value of the dependency property value precedence system
/// </summary>
Expand All @@ -316,11 +311,6 @@ protected void ClearValue()
PropertyInfo.ClearValue();
}

internal void ClearAnimationFillingValue()
{
PropertyInfo.ClearAnimationFillingValue();
}

void ITimeline.Begin()
{
// Timeline should not be used directly. Please use derived class.
Expand Down

0 comments on commit 56db9ce

Please sign in to comment.