-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Window and AnimationManager #1653
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e5a595e
Improve Window and AnimationManager
mattleibow 0989c3c
More tweaks
mattleibow 6400b16
-
mattleibow e9358b6
and that
mattleibow 49a6a03
fix that
mattleibow 44ad80d
Lazy
mattleibow ebc0f16
not readonly
mattleibow 0f05593
??=
mattleibow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has changed. Right now we first check for
IScopedMauiContext
, and if it is not that (for some reason) fall back to the services. Once we get scoped services, the internal interface will go away and we can keep the else branch.