-
Notifications
You must be signed in to change notification settings - Fork 423
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
Enhance DrawingView and DrawingViewService to provide the ability to export the full image size #2193
Conversation
@VladislavAntonyuk what do you think to this approach to enable developers to export the whole canvas should they wish? It needs to be completed for all platforms but I have the PoC working for Apple platforms |
Thanks @bijington , looks good. What do you think about renaming imageSize to lineBounds? Because ImageSize and CanvasSize may be confused. |
@VladislavAntonyuk great idea! I will carry on then and include that suggestion thanks. Also sadly I can't work out how to make this non breaking so I'll add the breaking label |
To make it not a breaking change, we can move the canvasSize parameter to the last position, but it's not good to have something after CancellationToken. However, I don't think it's a problem as we had breaking changes before. We can probably merge it with .net 9 support |
I did originally try that but one of our analysis rules complained as it is 'best practise' to keep the |
Or I guess rather than a default parameter we have an overload and therefore the current behaviour will stay as the default... That might work |
…CommunityToolkit/Maui into feature/sl-1397-drawing-view-full-image
The latest push removes the breaking nature of this PR |
FYI I haven't tested Android, Windows or Tizen yet. The last 2 I wrote on a Mac so I don't even know if it compiles yet... |
I am unable to test on Windows or Tizen right now as my home network is down while we do some renovations. If anyone can test either platform that would be really helpful. Otherwise I will move onto the docs |
src/CommunityToolkit.Maui.Core/Views/DrawingView/Service/DrawingViewService.shared.cs
Outdated
Show resolved
Hide resolved
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.
Copilot reviewed 5 out of 15 changed files in this pull request and generated no suggestions.
Files not reviewed (10)
- samples/CommunityToolkit.Maui.Sample/Pages/Views/DrawingViewPage.xaml: Language not supported
- samples/CommunityToolkit.Maui.Sample/Pages/Views/DrawingViewPage.xaml.cs: Evaluated as low risk
- samples/CommunityToolkit.Maui.Sample/ViewModels/Views/DrawingViewViewModel.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.Core/Interfaces/IDrawingLine.shared.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.Core/Interfaces/IDrawingView.shared.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.Core/Primitives/DrawingViewOutputOption.shared.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.Core/Views/DrawingView/DrawingLine.shared.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.Core/Views/DrawingView/Service/DrawingViewService.android.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.Core/Views/DrawingView/Service/DrawingViewService.macios.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.Core/Views/DrawingView/Service/DrawingViewService.net.cs: Evaluated as low risk
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.
Looks well done! I have tested in Windows, Android, and IOS. It works as intended. I have noticed you have implemented an options class which tidies things up a lot. That works well and makes things look clean. I have a few suggestions for fixing the tests.
On line 105 in DrawingLineTests.cs
I would replace
var stream = await DrawingLine.GetImageStream(Array.Empty<PointF>(), new Size(10, 10), 5, Colors.Yellow, Colors.Blue.AsPaint(), CancellationToken.None);
with
ImagePointOptions pointOptions = new([], Size.Zero, 0, Colors.Transparent, new SolidPaint(Colors.Transparent), Size.Zero);
var stream = await DrawingLine.GetImageStream(pointOptions, CancellationToken.None);
Line 162 in DrawingViewTests.cs
I would replace
await Assert.ThrowsAsync<OperationCanceledException>(async () => await DrawingView.GetImageStream([new DrawingLine()], Size.Zero, Colors.Blue, cts.Token));
with
ImageLineOptions options = ImageLineOptions.JustLines([new DrawingLine()], Size.Zero, new SolidPaint(Colors.Transparent));
await Assert.ThrowsAsync<OperationCanceledException>(async () => await DrawingView.GetImageStream(options, cts.Token));
On line 173 to 175 of the same file I would replace:
await Assert.ThrowsAsync<OperationCanceledException>(async () => await DrawingView.GetImageStream([
new DrawingLine()
], Size.Zero, Colors.Blue, cts.Token));
with:
ImageLineOptions options = ImageLineOptions.JustLines([new DrawingLine()], Size.Zero, new SolidPaint(Colors.Transparent));
await Assert.ThrowsAsync<OperationCanceledException>(async () => await DrawingView.GetImageStream(options, cts.Token));
This will fix the unit tests. Once you have fixed the unit tests I would say this is good to go. I would be happy to approve it. I can't test for tizen as I do not believe it supports dotnet 9 at all atm? I think they are still on dotnet 8?
…CommunityToolkit/Maui into feature/sl-1397-drawing-view-full-image
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.
Good Catch on tizen. The fixes for tests look good. the tests passed locally. I am happy to approve this now.
cc2fc5e
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.
Approved. Can't wait for this to be merged. Excited to see this in the Community toolkit! I ran the unit test changes through a local test loop for a bit to see if there would be any issues. None to be found!
Description of Change
The aim of this PR is to allow developers to export their drawings in multiple ways:
The following image shows the result in the Files app in the simulator on iOS based on using the sample application from the toolkit.
The change allows a developer to provide an
ImageOutputOption
value to theDrawingView
:This will then pass into the
DrawingViewService
the bounds of the currentDrawingView
. Developers can then also supply their out dimensions should they wish to theDrawingViewService
.Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information