Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Drawing View #740

Merged
merged 41 commits into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8292f3b
DrawingView (#468)
VladislavAntonyuk Nov 22, 2020
9b2c001
fixed codestyle on Android renderer
pictos Nov 22, 2020
6132b34
GTK renderer adjustments
pictos Nov 23, 2020
caae16f
iOS renderer adjustments
pictos Nov 23, 2020
5ff9aa0
MacOS renderer adjustments
pictos Nov 23, 2020
0b884b4
TIzen rendere adjustments
pictos Nov 23, 2020
648438c
UWP renderer adjustments
pictos Nov 23, 2020
2a30395
WPF tests
pictos Nov 25, 2020
6cce0f3
Merge branch 'develop' of https://github.com/xamarin/XamarinCommunity…
pictos Jan 9, 2021
e37af72
Fixed merge conflict
pictos Jan 9, 2021
c0addd2
Fixed wpf stackoverflow exception
pictos Jan 9, 2021
9d427d9
fixed iOS leaks
pictos Jan 10, 2021
f41d645
revert toast change
pictos Jan 14, 2021
02e1fc4
removed wpf implementations
pictos Feb 1, 2021
15fe5df
Merge branch 'develop' of https://github.com/xamarin/XamarinCommunity…
pictos Feb 1, 2021
4f22164
root sample page to WelcomePage
pictos Feb 1, 2021
42a36c8
removed DrawingView ctor from MainWindow
pictos Feb 1, 2021
d47a7a4
removed drawing instructions from readme
pictos Feb 14, 2021
a203fdc
Merge branch 'develop' into pj/drawingWork
pictos Feb 14, 2021
b987997
Update README.md
pictos Feb 14, 2021
8035c2d
Merge branch 'develop' into pj/drawingWork
TheCodeTraveler Mar 9, 2021
496444d
Merge branch 'develop' into pj/drawingWork
TheCodeTraveler Mar 15, 2021
cb02457
Merge branch 'develop' into pj/drawingWork
TheCodeTraveler Mar 18, 2021
3c54c11
Merge branch 'develop' into pj/drawingWork
TheCodeTraveler Mar 18, 2021
1561449
Merge branch 'develop' into pj/drawingWork
jsuarezruiz Mar 19, 2021
865e5eb
Merge branch 'develop' into pj/drawingWork
jsuarezruiz Mar 24, 2021
80360fb
Merge branch 'develop' into pj/drawingWork
pictos Mar 30, 2021
873cdd5
Merge branch 'develop' into pj/drawingWork
TheCodeTraveler Apr 5, 2021
6d4dcfe
Merge branch 'develop' into pj/drawingWork
TheCodeTraveler Apr 6, 2021
2f3fc5c
Merge branch 'develop' into pj/drawingWork
TheCodeTraveler Apr 8, 2021
782a749
Merge branch 'develop' into pj/drawingWork
TheCodeTraveler Apr 21, 2021
8f6c43d
Merge branch 'develop' into pj/drawingWork
jsuarezruiz May 4, 2021
30e60a6
Merge branch 'develop' into pj/drawingWork
pictos May 13, 2021
0462801
Drawing View - Fix nullable, add doc to the public method (#1293)
VladislavAntonyuk May 16, 2021
dc46d32
Merge branch 'develop' into pj/drawingWork
pictos May 21, 2021
7248f21
return null instead of exception (#1339)
VladislavAntonyuk May 27, 2021
c59a709
Merge branch 'develop' into pj/drawingWork
pictos Jun 7, 2021
0acada1
Merge branch 'develop' into pj/drawingWork
pictos Jun 16, 2021
feef70b
Merge branch 'develop' into pj/drawingWork
jfversluis Jun 18, 2021
7a2996a
Merge branch 'develop' into pj/drawingWork
jfversluis Jun 18, 2021
dfabca1
Merge branch 'develop' into pj/drawingWork
jfversluis Jun 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions samples/XCT.Sample.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ protected override void OnCreate(Bundle savedInstanceState)
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(savedInstanceState);

global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅


Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
10 changes: 0 additions & 10 deletions samples/XCT.Sample.UWP/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace Xamarin.CommunityToolkit.Sample.UWP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,4 @@
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
</Project>
</Project>
102 changes: 102 additions & 0 deletions samples/XCT.Sample.WPF/DrawingViewRenderer.wpf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using Xamarin.CommunityToolkit.Sample.WPF;
using Xamarin.CommunityToolkit.UI.Views;
using Xamarin.Forms;
using Xamarin.Forms.Platform.WPF;

[assembly: ExportRenderer(typeof(DrawingView), typeof(DrawingViewRenderer))]
namespace Xamarin.CommunityToolkit.Sample.WPF
{
public class DrawingViewRenderer : ViewRenderer<DrawingView, InkCanvas>
{
InkCanvas? canvas;

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == DrawingView.PointsProperty.PropertyName)
{
canvas!.Strokes.StrokesChanged -= OnStrokesChanged;
canvas.Strokes.Clear();
LoadPoints();
canvas.Strokes.StrokesChanged += OnStrokesChanged;
}
}

protected override void OnElementChanged(ElementChangedEventArgs<DrawingView> e)
{
base.OnElementChanged(e);
if (Control == null && Element != null)
{
canvas = new InkCanvas
{
DefaultDrawingAttributes =
{
Color = Element.LineColor.ToMediaColor(),
Width = Element.LineWidth,
Height = Element.LineWidth
},
Background = Element.BackgroundColor.ToBrush()
};
Element.Points.CollectionChanged += OnCollectionChanged;
SetNativeControl(canvas);

canvas.Strokes.StrokesChanged += OnStrokesChanged;
Control!.PreviewMouseDown += OnPreviewMouseDown;
}

if (e.OldElement != null)
{
canvas!.Strokes.StrokesChanged -= OnStrokesChanged;
Element!.Points.CollectionChanged -= OnCollectionChanged;
if (Control != null)
Control.PreviewMouseDown -= OnPreviewMouseDown;
}
}

void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args) => LoadPoints();

void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
canvas!.Strokes.Clear();
Element.Points.Clear();
}

void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
{
Element.Points.CollectionChanged -= OnCollectionChanged;
if (e.Added.Count > 0)
{
var points = e.Added.First().StylusPoints.Select(point => new Point(point.X, point.Y));
Element.Points.Clear();
foreach (var point in points)
Element.Points.Add(point);

if (Element.Points.Count > 0)
{
if (Element.DrawingCompletedCommand.CanExecute(null))
Element.DrawingCompletedCommand.Execute(Element.Points);
}

if (Element.ClearOnFinish)
Element.Points.Clear();
}
Element.Points.CollectionChanged += OnCollectionChanged;
}

void LoadPoints()
{
var stylusPoints = Element?.Points.Select(point => new StylusPoint(point.X, point.Y)).ToList();
if (stylusPoints is { Count: > 0 })
{
var stroke = new Stroke(new StylusPointCollection(stylusPoints), canvas!.DefaultDrawingAttributes);
canvas.Strokes.Add(stroke);
}
}
}
}
17 changes: 2 additions & 15 deletions samples/XCT.Sample.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Xamarin.CommunityToolkit.UI.Views;
using Xamarin.Forms.PancakeView.Platforms.WPF;
using Xamarin.Forms.Platform.WPF;

Expand All @@ -25,7 +12,7 @@ public partial class MainWindow : FormsApplicationPage
public MainWindow()
{
InitializeComponent();
Xamarin.Forms.Forms.Init();
Forms.Forms.Init();
PancakeViewRenderer.Init();
LoadApplication(new Xamarin.CommunityToolkit.Sample.App());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="DrawingViewRenderer.wpf.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
5 changes: 2 additions & 3 deletions samples/XCT.Sample.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Xamarin.CommunityToolkit.Sample.iOS
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
[Register(nameof(AppDelegate))]
public class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
Expand All @@ -16,7 +16,6 @@ public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsAppli
// You have 17 seconds to return from this method, or iOS will terminate your application.
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@
<ItemGroup>
<BundleResource Include="Resources\triangle.png" />
</ItemGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions samples/XCT.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Globalization;
using Xamarin.CommunityToolkit.Helpers;
using Xamarin.CommunityToolkit.Sample.Pages;
using Xamarin.CommunityToolkit.Sample.Pages.Views;
using Xamarin.CommunityToolkit.Sample.Resx;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
Expand Down
67 changes: 67 additions & 0 deletions samples/XCT.Sample/Pages/Views/DrawingViewPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.DrawingViewPage"
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
xmlns:viewsVodel="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.Views;assembly=Xamarin.CommunityToolkit.Sample">

<pages:BasePage.BindingContext>
<viewsVodel:DrawingViewViewModel/>
</pages:BasePage.BindingContext>

<ScrollView>
<StackLayout>
<Switch x:Name="ClearOnFinish" />
<Button
BackgroundColor="White"
Clicked="LoadPointsButtonClicked"
Text="Load points"
TextColor="Black" />
<Button
BackgroundColor="White"
Command="{Binding SetPointsCommand}"
Text="Load points ViewModel"
TextColor="Black" />
<Label
x:Name="HiddenLabel"
HorizontalOptions="CenterAndExpand"
IsVisible="False"
Text="Draw &amp; GO" />
<Button
BackgroundColor="White"
Clicked="DisplayHiddenLabelButtonClicked"
Text="Display hidden label"
TextColor="Black" />
<Button
BackgroundColor="White"
Command="{Binding GetPointsCommand}"
Text="Get points ViewModel"
TextColor="Black" />
<Button
BackgroundColor="White"
Clicked="GetCurrentDrawingViewImageClicked"
Text="Display current gesture pad image"
TextColor="Black" />
<Button
BackgroundColor="White"
Clicked="GetImageClicked"
Text="Display image"
TextColor="Black" />
<Image
x:Name="GestureImage"
HeightRequest="100"
WidthRequest="100" />
<views:DrawingView
x:Name="DrawingViewControl"
Points="{Binding MacroPoints, Mode=TwoWay}"
BackgroundColor="DarkGray"
ClearOnFinish="{Binding Source={x:Reference ClearOnFinish}, Path=IsToggled}"
HorizontalOptions="FillAndExpand"
LineColor="Red"
LineWidth="10"
VerticalOptions="FillAndExpand" />
<Editor x:Name="Logs" AutoSize="TextChanges" />
</StackLayout>
</ScrollView>
</pages:BasePage>
56 changes: 56 additions & 0 deletions samples/XCT.Sample/Pages/Views/DrawingViewPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.CommunityToolkit.UI.Views;
using System.Collections.ObjectModel;

namespace Xamarin.CommunityToolkit.Sample.Pages.Views
{
public partial class DrawingViewPage : BasePage
{
public DrawingViewPage()
{
InitializeComponent();
DrawingViewControl.Points = GeneratePoints(200);
DrawingViewControl.DrawingCompletedCommand = new Command<ObservableCollection<Point>>(points =>
{
Logs.Text += "GestureCompletedCommand executed" + Environment.NewLine;
DrawImage(points);
});
}

void LoadPointsButtonClicked(object sender, EventArgs e) => DrawingViewControl.Points = GeneratePoints(50);

void DisplayHiddenLabelButtonClicked(object sender, EventArgs e) => HiddenLabel.IsVisible = !HiddenLabel.IsVisible;

void GetCurrentDrawingViewImageClicked(object sender, EventArgs e)
{
var stream = DrawingViewControl.GetImageStream(GestureImage.Width, GestureImage.Height);
GestureImage.Source = ImageSource.FromStream(() => stream);
}

void GetImageClicked(object sender, EventArgs e)
{
var points = GeneratePoints(100);
DrawImage(points);
}

static ObservableCollection<Point> GeneratePoints(int count)
{
var points = new ObservableCollection<Point>();
for (var i = 0; i < count; i++)
{
points.Add(new Point(i, i));
}

return points;
}

void DrawImage(IEnumerable<Point> points)
{
var stream = DrawingView.GetImageStream(points, new Size(GestureImage.Width, GestureImage.Height), 10,
Color.White, Color.Black);
GestureImage.Source = ImageSource.FromStream(() => stream);
}
}
}
Loading