This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 456
Remove Device
dependency from command implementation (#825)
#830
Merged
TheCodeTraveler
merged 10 commits into
xamarin:main
from
WebDucer:feature/825_asynccommand_without_device_dependency
Feb 8, 2021
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9fbeffd
Remove `Device` dependency from command implementation (#804)
722b7b5
Merge branch 'main' into feature/825_asynccommand_without_device_depe…
TheCodeTraveler b85e3ac
Move Xamarin.CommunityToolkit.ObjectModel.Internals classes to `Inter…
TheCodeTraveler 9057a97
Add Platform-Specific MainThread Implementations, Update Unit Tests t…
TheCodeTraveler 754a962
Update BaseCommand.uwp.cs
TheCodeTraveler 553ab66
Add BaseCommand.wpf.cs
TheCodeTraveler 09339d7
Finish BaseCommand.gtk.cs
TheCodeTraveler 871c71d
Update BaseCommand.shared.cs
TheCodeTraveler b3b68fe
Merge branch 'main' into feature/825_asynccommand_without_device_depe…
TheCodeTraveler 73c08a5
Merge branch 'main' into feature/825_asynccommand_without_device_depe…
TheCodeTraveler 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 hidden or 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 hidden or 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 hidden or 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
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.
now it doesn't marshall to the Main Thread (cuz synchronizationContext can be not UI thread's context)
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.
well I think the Post method of SyncContext does run the task in the android message loop (aka UI thread).
https://github.com/xamarin/xamarin-android/blob/aad2c29e30e362b19bf526eb14075d8325a1f2d8/src/Mono.Android/Android.App/SyncContext.cs#L30
Uh oh!
There was an error while loading. Please reload this page.
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.
Hey Gang! I'm going to update this PR to use the platform-specific code for both checking if the current thread is the Main Thread and invoking Main Thread.
It'll be inspired by Xamarin.Essentials.MainThread: https://github.com/xamarin/Essentials/tree/main/Xamarin.Essentials/MainThread
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.
The bad part of it's now we have 3 implementations of the same thing, on Forms, essentials and here... I would say to mock the Device platform services as @brminnick said on issue and @AndreiMisiukevich here...
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.
Well to be honest the point raised by @WebDucer is valid: a command belongs to the view model layer and then should be UI independent. The synchronization context is the correct way to implement main thread Marshalling in the net standard fashion. Since Post method make sure the task is executed on the main thread, this code is valid and does not need any modification (in fact this code is taken from prism implementation of delegate command...). Essentials and Forms are UI frameworks so it's only natural they are using directly Xamarin.Forms Device helpers.
Uh oh!
There was an error while loading. Please reload this page.
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.
@pictos I agree that having 3 implementations of marshaling code to the Main Thread is not idea, but I see it as a short-term stop-gap:
Xamarin.Essentials is being folded into .NET MAUI, so once we migrate Xamarin.CommunityToolkit from Xamarin.Forms v5.0 to .NET MAUI, we can replace this duplicate implementation with Xamarin.Essentials.MainThread's implementation.
And to avoid this 3rd implementation surfacing to (and potential confusing) developers using Xamarin.CommunityToolkit , I plan on keeping our implementation
private
/internal
.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.
I'm afraid the net standard implementation of the MainThread of essentials will not work:
So without SynchronizationContext object, it will force people unit testing view models to mock essentials or forms.
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.
@brminnick if you think this is a valuable change, let's keep it then (:
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.
@roubachof yeah, for forms people need to wrap the APIs inside interfaces if they want to test it