Skip to content

Commit

Permalink
Merge from master.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keflon committed Feb 26, 2024
2 parents c97f2ad + e88591a commit 38426ec
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 32 deletions.
69 changes: 69 additions & 0 deletions FunctionZero.Maui.Controls/BackingStore/BindableBackingStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using FunctionZero.ExpressionParserZero.BackingStore;
using FunctionZero.ExpressionParserZero.Operands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace FunctionZero.Maui.BackingStore
{
public class BindableBackingStore : IBackingStore
{
private static char[] _dot = new[] { '.' };

public BindableBackingStore(object host)
{
Host = host;
}

public object Host { get; }

public (OperandType type, object value) GetValue(string qualifiedName)
{
var hostInfo = GetPropertyInfo(Host, qualifiedName);
var value = hostInfo.info.GetValue(hostInfo.host);

if (BackingStoreHelpers.OperandTypeLookup.TryGetValue(hostInfo.info.PropertyType, out var theOperandType))
return (theOperandType, value);

if (value == null)
return (OperandType.Null, null);

return (OperandType.Object, value);
}

public void SetValue(string qualifiedName, object value)
{
var hostInfo = GetPropertyInfo(Host, qualifiedName);

//if(hostInfo.info.CanWrite)
{
hostInfo.info.SetValue(hostInfo.host, value);
}
}

protected (object host, PropertyInfo info) GetPropertyInfo(object host, string qualifiedName)
{
var bits = qualifiedName.Split(_dot);

PropertyInfo pi = null;
object nextHost = host;
foreach (var bit in bits)
{
host = nextHost;

// Get info for the property
pi = host.GetType().GetProperty(bit, BindingFlags.Public | BindingFlags.Instance);
if (pi == null || pi.CanRead == false)
return (null, null);


nextHost = pi.GetValue(host);
}
return (host, pi);
}

}
}
36 changes: 18 additions & 18 deletions FunctionZero.Maui.Controls/Controls/MultiView/MultiViewAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,6 @@ private static void ToChanged(BindableObject bindable, object oldValue, object n

#endregion

//#region DurationProperty

//public static readonly BindableProperty DurationProperty = BindableProperty.Create(nameof(Duration), typeof(double), typeof(MultiViewAnimation), 0.0, BindingMode.OneWay, null, DurationChanged);

//public double Duration
//{
// get { return (double)GetValue(DurationProperty); }
// set { SetValue(DurationProperty, value); }
//}

//private static void DurationChanged(BindableObject bindable, object oldValue, object newValue)
//{
// var self = (MultiViewAnimation)bindable;

//}

//#endregion

#region EasingFuncProperty

public static readonly BindableProperty EasingFuncProperty = BindableProperty.Create(nameof(EasingFunc), typeof(Easing), typeof(MultiViewAnimation), Easing.Linear, BindingMode.OneWay, null, EasingFuncChanged);
Expand Down Expand Up @@ -97,6 +79,24 @@ private static void ExpressionChanged(BindableObject bindable, object oldValue,

#endregion

#region StartingExpressionProperty

public static readonly BindableProperty StartingExpressionProperty = BindableProperty.Create(nameof(StartingExpression), typeof(string), typeof(MultiViewAnimation), string.Empty, BindingMode.OneWay, null, StartingExpressionChanged);

public string StartingExpression
{
get { return (string)GetValue(StartingExpressionProperty); }
set { SetValue(StartingExpressionProperty, value); }
}

private static void StartingExpressionChanged(BindableObject bindable, object oldValue, object newValue)
{
var self = (MultiViewAnimation)bindable;
}

#endregion


#region FinishedExpressionProperty

public static readonly BindableProperty FinishedExpressionProperty = BindableProperty.Create(nameof(FinishedExpression), typeof(string), typeof(MultiViewAnimation), string.Empty, BindingMode.OneWay, null, FinishedExpressionChanged);
Expand Down
44 changes: 34 additions & 10 deletions FunctionZero.Maui.Controls/Controls/MultiView/MultiViewZero.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FunctionZero.ExpressionParserZero.BackingStore;
using FunctionZero.ExpressionParserZero.Evaluator;
using FunctionZero.Maui.zBind.z;
using Microsoft.Maui.Layouts;
using System.Diagnostics;
Expand All @@ -10,14 +11,12 @@ public class MultiViewZero : Layout
{
private readonly PocoBackingStore _backingStore;

private static int _instanceCount = 0;
public MultiViewZero()
{
InAnimations = new List<MultiViewAnimation>();
OutAnimations = new List<MultiViewAnimation>();

_backingStore = new PocoBackingStore(this);
_instanceCount++;

}
protected override ILayoutManager CreateLayoutManager()
Expand Down Expand Up @@ -130,6 +129,8 @@ private static void TopViewNameChanged(BindableObject bindable, object oldValue,

private void SetTopView(View theChildView)
{
(PreviousView as View)?.AbortAnimation("PreviousAnimation");
(CurrentView as View)?.AbortAnimation("CurrentAnimation");

PreviousView = CurrentView;
CurrentView = theChildView;
Expand All @@ -142,57 +143,66 @@ private void SetTopView(View theChildView)
// Workaround for https://github.com/dotnet/maui/issues/18433
if (previousViewAsView.IsLoaded)
{
previousViewAsView.AbortAnimation("PreviousAnimation"+ _instanceCount.ToString());
previousViewAsView.AbortAnimation("PreviousAnimation");

var a = new Animation();

foreach (var anim in OutAnimations)
{
// TODO: Horribly inefficient!
var compiledExpression = ep.Parse(anim.Expression);
var compiledStartingExpression = ep.Parse(anim.StartingExpression);
var compiledFinishedExpression = ep.Parse(anim.FinishedExpression);

a.Add(0, 1, new Animation(val => { value = val; compiledExpression.Evaluate(_backingStore); }, anim.From, anim.To, anim.EasingFunc, () => compiledFinishedExpression.Evaluate(_backingStore)));
TryEvaluate(compiledStartingExpression, _backingStore);

a.Add(0, 1, new Animation(val => { value = val; TryEvaluate(compiledExpression, _backingStore); }, anim.From, anim.To, anim.EasingFunc, () => TryEvaluate(compiledFinishedExpression,_backingStore)));
}
a.Commit(this, "PreviousAnimation" + _instanceCount.ToString(), 16, OutDuration, null, null, () => false);
a.Commit(this, "PreviousAnimation", 16, OutDuration, null, null, () => false);
}
else
{
foreach (var anim in OutAnimations)
{
// TODO: Call compiledStartingExpression, compiledFinishedExpression
// TODO: Horribly inefficient!
var compiledExpression = ep.Parse(anim.Expression);
value = 1.0;
compiledExpression.Evaluate(_backingStore);
TryEvaluate(compiledExpression, _backingStore);
}
}
}
if (CurrentView is View currentViewAsView)
{
if (currentViewAsView.IsLoaded)
{
currentViewAsView.AbortAnimation("CurrentAnimation" + _instanceCount.ToString());
currentViewAsView.AbortAnimation("CurrentAnimation");

var a = new Animation();

foreach (var anim in InAnimations)
{
// TODO: Horribly inefficient!
var compiledExpression = ep.Parse(anim.Expression);
var compiledStartingExpression = ep.Parse(anim.StartingExpression);
var compiledFinishedExpression = ep.Parse(anim.FinishedExpression);
a.Add(0, 1, new Animation(val => { value = val; compiledExpression.Evaluate(_backingStore); }, anim.From, anim.To, anim.EasingFunc,()=> compiledFinishedExpression.Evaluate(_backingStore)));

TryEvaluate(compiledStartingExpression,_backingStore);

a.Add(0, 1, new Animation(val => { value = val; TryEvaluate(compiledExpression,_backingStore); }, anim.From, anim.To, anim.EasingFunc, () => TryEvaluate(compiledFinishedExpression,_backingStore)));
}
a.Commit(this, "CurrentAnimation" + _instanceCount.ToString(), 16, InDuration, null, null, () => false);
a.Commit(this, "CurrentAnimation", 16, InDuration, null, null, () => false);

}
else
{
// TODO: Call compiledStartingExpression, compiledFinishedExpression
foreach (var anim in InAnimations)
{
// TODO: Horribly inefficient!
var compiledExpression = ep.Parse(anim.Expression);
value = 1.0;
compiledExpression.Evaluate(_backingStore);
TryEvaluate(compiledExpression,_backingStore);
}
}
}
Expand All @@ -201,6 +211,20 @@ private void SetTopView(View theChildView)
(this as IView).InvalidateArrange();
}

private bool TryEvaluate(ExpressionTree compiledExpression, PocoBackingStore backingStore)
{
try
{
compiledExpression.Evaluate(_backingStore);
return true;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
return false;
}
}

#endregion

public double value { get; protected set; }
Expand Down
Binary file added FunctionZero.Maui.Controls/F0_gravatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions FunctionZero.Maui.Controls/FunctionZero.Maui.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<PackageProjectUrl>https://github.com/Keflon/FunctionZero.Maui.Controls</PackageProjectUrl>
<RepositoryUrl>https://github.com/Keflon/FunctionZero.Maui.Controls</RepositoryUrl>
<PackageTags>MAUI; ListView; ListViewZero; TreeView; TreeViewZero; MaskView; iOS; WinUI; Windows; Android; Control </PackageTags>
<PackageReleaseNotes>Added a preview of a MultiView control.</PackageReleaseNotes>
<PackageReleaseNotes>Added StartingExpressionProperty to MultiViewAnimation used by the preview MultiView control.</PackageReleaseNotes>
<PackageLicenseFile>License.md</PackageLicenseFile>
<IncludeSymbols>True</IncludeSymbols>
<IncludeSymbols>False</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>8.0.0.2-pre8</Version>
<Version>8.0.0.2-pre7</Version>
<PackageIcon>F0 gravatar.png</PackageIcon>
</PropertyGroup>

Expand Down
3 changes: 2 additions & 1 deletion SampleApp/Mvvm/Pages/MultiView/MultiViewModalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@



<cz:MultiViewZero Grid.Row="1" TopViewName="{Binding TopViewName}" InDuration="666" OutDuration="666" BackgroundColor="Yellow">
<cz:MultiViewZero Grid.Row="1" TopViewName="{Binding TopViewName}" InDuration="6666" OutDuration="6666" BackgroundColor="Yellow">
<!--TODO: Add ItemControlTemplate-->
<cz:MultiViewZero.InAnimations>
<cz:MultiViewAnimation
From="0"
To="1"
EasingFunc="{x:Static Easing.BounceOut}"
StartingExpression="CurrentView.Scale=value"
Expression="CurrentView.Scale=value"
FinishedExpression=""
>
Expand Down

0 comments on commit 38426ec

Please sign in to comment.