-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Window and AnimationManager (#1653)
* Improve Window and AnimationManager * More tweaks * - * and that * fix that * Lazy * not readonly * ??=
- Loading branch information
1 parent
87ce84c
commit 6c5b3c7
Showing
19 changed files
with
201 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/Controls/tests/Core.UnitTests/TestClasses/AnimationReadyHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.Animations; | ||
using Microsoft.Maui.Handlers; | ||
|
||
namespace Microsoft.Maui.Controls.Core.UnitTests | ||
{ | ||
class AnimationReadyHandler : AnimationReadyHandler<BlockingTicker> | ||
{ | ||
public AnimationReadyHandler() | ||
: base(new TestAnimationManager(new BlockingTicker())) | ||
{ | ||
} | ||
} | ||
|
||
class AnimationReadyHandlerAsync : AnimationReadyHandler<AsyncTicker> | ||
{ | ||
public AnimationReadyHandlerAsync() | ||
: base(new TestAnimationManager(new AsyncTicker())) | ||
{ | ||
} | ||
} | ||
|
||
class AnimationReadyHandler<TTicker> : ViewHandler<IView, object> | ||
where TTicker : ITicker, new() | ||
{ | ||
public AnimationReadyHandler(IAnimationManager animationManager) | ||
: base(new PropertyMapper<IView>()) | ||
{ | ||
SetMauiContext(new AnimationReadyMauiContext(animationManager)); | ||
} | ||
|
||
public static AnimationReadyHandler<TTicker> Prepare<T>(params T[] views) | ||
where T : View | ||
{ | ||
var handler = new AnimationReadyHandler<TTicker>(new TestAnimationManager(new TTicker())); | ||
|
||
foreach (var view in views) | ||
view.Handler = handler; | ||
|
||
return handler; | ||
} | ||
|
||
public static T Prepare<T>(T view, out AnimationReadyHandler<TTicker> handler) | ||
where T : View | ||
{ | ||
handler = new AnimationReadyHandler<TTicker>(new TestAnimationManager(new TTicker())); | ||
|
||
view.Handler = handler; | ||
|
||
return view; | ||
} | ||
|
||
public static T Prepare<T>(T view) | ||
where T : View | ||
{ | ||
view.Handler = new AnimationReadyHandler(); | ||
|
||
return view; | ||
} | ||
|
||
protected override object CreateNativeView() => new(); | ||
|
||
public IAnimationManager AnimationManager => ((AnimationReadyMauiContext)MauiContext).AnimationManager; | ||
|
||
class AnimationReadyMauiContext : IMauiContext, IScopedMauiContext | ||
{ | ||
readonly IAnimationManager _animationManager; | ||
|
||
public AnimationReadyMauiContext(IAnimationManager manager = null) | ||
{ | ||
_animationManager = manager ?? new TestAnimationManager(); | ||
} | ||
|
||
public IServiceProvider Services => throw new NotImplementedException(); | ||
|
||
public IMauiHandlersServiceProvider Handlers => throw new NotImplementedException(); | ||
|
||
public IAnimationManager AnimationManager => _animationManager; | ||
} | ||
} | ||
|
||
static class AnimationReadyWindowExtensions | ||
{ | ||
public static async Task DisableTicker(this AnimationReadyHandler<AsyncTicker> handler) | ||
{ | ||
await Task.Delay(32); | ||
|
||
((AsyncTicker)handler.AnimationManager.Ticker).SetEnabled(false); | ||
} | ||
|
||
public static async Task EnableTicker(this AnimationReadyHandler<AsyncTicker> handler) | ||
{ | ||
await Task.Delay(32); | ||
|
||
((AsyncTicker)handler.AnimationManager.Ticker).SetEnabled(true); | ||
} | ||
} | ||
} |
116 changes: 0 additions & 116 deletions
116
src/Controls/tests/Core.UnitTests/TestClasses/AnimationReadyWindow.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.