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

Commit dbb0eeb

Browse files
authored
Merge branch 'develop' into guoldev/cameraview_linker_issue
2 parents 845d5ea + 8d688e4 commit dbb0eeb

35 files changed

+1428
-444
lines changed

samples/XCT.Sample.WPF/DrawingViewRenderer.wpf.cs

Lines changed: 76 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Specialized;
1+
using System.Collections.ObjectModel;
2+
using System.Collections.Specialized;
23
using System.ComponentModel;
34
using System.Linq;
45
using System.Windows.Controls;
@@ -10,6 +11,7 @@
1011
using Xamarin.Forms.Platform.WPF;
1112

1213
[assembly: ExportRenderer(typeof(DrawingView), typeof(DrawingViewRenderer))]
14+
1315
namespace Xamarin.CommunityToolkit.Sample.WPF
1416
{
1517
public class DrawingViewRenderer : ViewRenderer<DrawingView, InkCanvas>
@@ -19,11 +21,11 @@ public class DrawingViewRenderer : ViewRenderer<DrawingView, InkCanvas>
1921
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
2022
{
2123
base.OnElementPropertyChanged(sender, e);
22-
if (e.PropertyName == DrawingView.PointsProperty.PropertyName)
24+
if (e.PropertyName == DrawingView.LinesProperty.PropertyName)
2325
{
2426
canvas!.Strokes.StrokesChanged -= OnStrokesChanged;
2527
canvas.Strokes.Clear();
26-
LoadPoints();
28+
LoadLines();
2729
canvas.Strokes.StrokesChanged += OnStrokesChanged;
2830
}
2931
}
@@ -35,15 +37,15 @@ protected override void OnElementChanged(ElementChangedEventArgs<DrawingView> e)
3537
{
3638
canvas = new InkCanvas
3739
{
38-
DefaultDrawingAttributes =
40+
Background = Element.BackgroundColor.ToBrush(),
41+
DefaultDrawingAttributes = new()
3942
{
40-
Color = Element.LineColor.ToMediaColor(),
41-
Width = Element.LineWidth,
42-
Height = Element.LineWidth
43-
},
44-
Background = Element.BackgroundColor.ToBrush()
43+
Color = Element.DefaultLineColor.ToMediaColor(),
44+
Width = Element.DefaultLineWidth,
45+
Height = Element.DefaultLineWidth
46+
}
4547
};
46-
Element.Points.CollectionChanged += OnCollectionChanged;
48+
Element.Lines.CollectionChanged += OnCollectionChanged;
4749
SetNativeControl(canvas);
4850

4951
canvas.Strokes.StrokesChanged += OnStrokesChanged;
@@ -53,55 +55,96 @@ protected override void OnElementChanged(ElementChangedEventArgs<DrawingView> e)
5355
if (e.OldElement != null)
5456
{
5557
canvas!.Strokes.StrokesChanged -= OnStrokesChanged;
56-
Element!.Points.CollectionChanged -= OnCollectionChanged;
58+
Element!.Lines.CollectionChanged -= OnCollectionChanged;
5759
if (Control != null)
5860
Control.PreviewMouseDown -= OnPreviewMouseDown;
5961
}
6062
}
6163

62-
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args) => LoadPoints();
64+
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
65+
{
66+
canvas!.Strokes.StrokesChanged -= OnStrokesChanged;
67+
canvas.Strokes.Clear();
68+
LoadLines();
69+
canvas.Strokes.StrokesChanged += OnStrokesChanged;
70+
}
71+
72+
void OnPreviewMouseDown(object sender, MouseButtonEventArgs e) => Clear();
6373

64-
void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
74+
void Clear(bool force = false)
6575
{
66-
canvas!.Strokes.Clear();
67-
Element.Points.Clear();
76+
if (!Element.MultiLineMode || force)
77+
{
78+
canvas!.Strokes.Clear();
79+
Element.Lines.Clear();
80+
}
6881
}
6982

7083
void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
7184
{
72-
Element.Points.CollectionChanged -= OnCollectionChanged;
85+
Element.Lines.CollectionChanged -= OnCollectionChanged;
7386
if (e.Added.Count > 0)
7487
{
75-
var points = e.Added.First().StylusPoints.Select(point => new Point(point.X, point.Y));
76-
Element.Points.Clear();
77-
foreach (var point in points)
78-
Element.Points.Add(point);
88+
if (!Element.MultiLineMode)
89+
{
90+
Element.Lines.Clear();
91+
}
7992

80-
if (Element.Points.Count > 0)
93+
var lines = Element.MultiLineMode ? e.Added : new StrokeCollection() {e.Added.First()};
94+
95+
foreach (var line in lines)
96+
{
97+
var points = line.StylusPoints.Select(point => new Point(point.X, point.Y)).ToList();
98+
Element.Lines.Add(new Line()
99+
{
100+
Points = new ObservableCollection<Point>(points),
101+
LineColor = Color.FromRgba(line.DrawingAttributes.Color.R, line.DrawingAttributes.Color.G,
102+
line.DrawingAttributes.Color.B, line.DrawingAttributes.Color.A),
103+
LineWidth = (float) line.DrawingAttributes.Width
104+
});
105+
}
106+
107+
if (Element.Lines.Count > 0)
81108
{
82-
if (Element.DrawingCompletedCommand?.CanExecute(null) ?? false)
83-
Element.DrawingCompletedCommand.Execute(Element.Points);
109+
var lastLine = Element.Lines.Last();
110+
if (Element.DrawingLineCompletedCommand?.CanExecute(lastLine) ?? false)
111+
Element.DrawingLineCompletedCommand.Execute(lastLine);
84112
}
85113

86114
if (Element.ClearOnFinish)
87115
{
88-
canvas!.Strokes.StrokesChanged -= OnStrokesChanged;
89-
canvas.Strokes.Clear();
90-
canvas.Strokes.StrokesChanged += OnStrokesChanged;
91-
Element.Points.Clear();
116+
Element.Lines.CollectionChanged -= OnCollectionChanged;
117+
Clear(true);
118+
canvas!.Strokes.StrokesChanged += OnStrokesChanged;
92119
}
93120
}
94121

95-
Element.Points.CollectionChanged += OnCollectionChanged;
122+
Element.Lines.CollectionChanged += OnCollectionChanged;
96123
}
97124

98-
void LoadPoints()
125+
void LoadLines()
99126
{
100-
var stylusPoints = Element?.Points.Select(point => new StylusPoint(point.X, point.Y)).ToList();
101-
if (stylusPoints is { Count: > 0 })
127+
var lines = Element.MultiLineMode
128+
? Element.Lines
129+
: Element.Lines.Any()
130+
? new ObservableCollection<Line> {Element.Lines.LastOrDefault()}
131+
: new ObservableCollection<Line>();
132+
foreach (var line in lines)
102133
{
103-
var stroke = new Stroke(new StylusPointCollection(stylusPoints), canvas!.DefaultDrawingAttributes);
104-
canvas.Strokes.Add(stroke);
134+
var stylusPoints = line.Points.Select(point => new StylusPoint(point.X, point.Y)).ToList();
135+
if (stylusPoints is {Count: > 0})
136+
{
137+
var stroke = new Stroke(new StylusPointCollection(stylusPoints))
138+
{
139+
DrawingAttributes = new()
140+
{
141+
Color = line.LineColor.ToMediaColor(),
142+
Width = line.LineWidth,
143+
Height = line.LineWidth
144+
}
145+
};
146+
canvas!.Strokes.Add(stroke);
147+
}
105148
}
106149
}
107150
}

samples/XCT.Sample/Pages/Effects/SemanticEffectPage.xaml

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
xct:SemanticEffect.Hint="Hint text"/>
116116

117117
<Label
118-
Text="The rest of the controls read out DH"
118+
Text="The next set of controls read out DH and then experiments with controls in layouts that have a SemanticDescription."
119119
TextColor="RoyalBlue"
120120
FontAttributes="Bold"
121121
FontSize="16"
@@ -159,6 +159,25 @@
159159
xct:SemanticEffect.Description="Description text"
160160
xct:SemanticEffect.Hint="Hint text"/>
161161

162+
<StackLayout xct:SemanticEffect.Description="Layout description text">
163+
<Label
164+
Text="Label in StackLayout with semantic description"
165+
FontSize="14"/>
166+
<Label
167+
Text="Label in StackLayout with semantic description"
168+
FontSize="14"/>
169+
</StackLayout>
170+
171+
<!-- [iOS] Button is not individually accessible. -->
172+
<StackLayout xct:SemanticEffect.Description="Layout description text">
173+
<Label
174+
Text="Label in StackLayout with semantic description"
175+
FontSize="14"/>
176+
<Button
177+
Text="Button in StackLayout with semantic description"
178+
FontSize="14"/>
179+
</StackLayout>
180+
162181
<Label
163182
Text="This next set of controls exist solely for testing the HeadingLevel property. If testing on mobile, be sure to activate Headings and swipe up/down with one finger to test."
164183
TextColor="RoyalBlue"
@@ -193,25 +212,30 @@
193212
FontSize="14"
194213
xct:SemanticEffect.HeadingLevel="Level3"/>
195214

196-
<StackLayout xct:SemanticEffect.Description="Layout description text">
197-
<Label
198-
Text="Label in StackLayout with semantic description"
199-
FontSize="14"/>
200-
<Label
201-
Text="Label in StackLayout with semantic description"
202-
FontSize="14"/>
203-
</StackLayout>
215+
<Label
216+
Text="This next set of controls exist solely for testing the SemanticInclusion property."
217+
TextColor="RoyalBlue"
218+
FontAttributes="Bold"
219+
FontSize="16"
220+
Margin="0,10"/>
221+
222+
<StackLayout x:Name="semanticInclusionSampleLayout">
223+
<Label
224+
Text="Label that is semantically default included"
225+
xct:SemanticEffect.SemanticInclusion="Default" />
204226

205-
<!-- [iOS] Button is not individually accessible. -->
206-
<StackLayout xct:SemanticEffect.Description="Layout description text">
207227
<Label
208-
Text="Label in StackLayout with semantic description"
209-
FontSize="14"/>
210-
<Button
211-
Text="Button in StackLayout with semantic description"
212-
FontSize="14"/>
213-
</StackLayout>
228+
Text="Label that is semantically included"
229+
xct:SemanticEffect.SemanticInclusion="Include" />
214230

231+
<Label
232+
Text="Label that is semantically excluded"
233+
xct:SemanticEffect.SemanticInclusion="Exclude" />
234+
235+
<Button
236+
Text="Hide all above content from screen reader accessibility"
237+
Clicked="ExcludeButton_Clicked" />
238+
</StackLayout>
215239
</StackLayout>
216240
</ScrollView>
217241
</ContentPage.Content>

samples/XCT.Sample/Pages/Effects/SemanticEffectPage.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-

1+
using Xamarin.CommunityToolkit.Effects;
2+
using Xamarin.CommunityToolkit.Effects.Semantic;
23
using Xamarin.Forms;
34

45
namespace Xamarin.CommunityToolkit.Sample.Pages.Effects
@@ -9,5 +10,10 @@ public SemanticEffectPage()
910
{
1011
InitializeComponent();
1112
}
13+
14+
void ExcludeButton_Clicked(object sender, System.EventArgs e)
15+
{
16+
SemanticEffect.SetSemanticInclusion(semanticInclusionSampleLayout, SemanticInclusion.ExcludeWithChildren);
17+
}
1218
}
1319
}

samples/XCT.Sample/Pages/Views/DrawingViewPage.xaml

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
77
xmlns:viewsVodel="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.Views;assembly=Xamarin.CommunityToolkit.Sample">
88

9-
<pages:BasePage.BindingContext>
10-
<viewsVodel:DrawingViewViewModel/>
11-
</pages:BasePage.BindingContext>
12-
139
<ScrollView>
1410
<StackLayout>
15-
<Switch x:Name="ClearOnFinish" />
11+
<StackLayout Orientation="Horizontal" Margin="5">
12+
<Label Text="Clear on Finish" Margin="0,0,5,0" />
13+
<Switch x:Name="ClearOnFinish" />
14+
</StackLayout>
15+
<StackLayout Orientation="Horizontal" Margin="5">
16+
<Label Text="Multi-Line Mode" Margin="0,0,5,0" />
17+
<Switch x:Name="MultiLineMode" />
18+
</StackLayout>
1619
<Button
1720
BackgroundColor="White"
18-
Clicked="LoadPointsButtonClicked"
19-
Text="Load points"
21+
Clicked="AddNewLine"
22+
Text="Add new line"
2023
TextColor="Black" />
2124
<Button
2225
BackgroundColor="White"
23-
Command="{Binding SetPointsCommand}"
24-
Text="Load points ViewModel"
26+
Clicked="LoadPointsButtonClicked"
27+
Text="Load points"
2528
TextColor="Black" />
2629
<Label
2730
x:Name="HiddenLabel"
@@ -33,11 +36,6 @@
3336
Clicked="DisplayHiddenLabelButtonClicked"
3437
Text="Display hidden label"
3538
TextColor="Black" />
36-
<Button
37-
BackgroundColor="White"
38-
Command="{Binding GetPointsCommand}"
39-
Text="Get points ViewModel"
40-
TextColor="Black" />
4139
<Button
4240
BackgroundColor="White"
4341
Clicked="GetCurrentDrawingViewImageClicked"
@@ -53,21 +51,16 @@
5351
HeightRequest="100"
5452
WidthRequest="100" />
5553

56-
<Label Text="Default DrawingView"/>
57-
<views:DrawingView BackgroundColor="LightGray" HeightRequest="200" />
54+
<Label Text="DrawingView (Code behind)"/>
55+
<views:DrawingView x:Name="DrawingViewControl"
56+
BackgroundColor="LightGray"
57+
HeightRequest="200"
58+
DefaultLineColor="Red"
59+
DefaultLineWidth="3"
60+
Lines="{Binding Lines, Mode=TwoWay}"
61+
ClearOnFinish="{Binding Source={x:Reference ClearOnFinish}, Path=IsToggled}"
62+
MultiLineMode="{Binding Source={x:Reference MultiLineMode}, Path=IsToggled}"/>
5863

59-
<Label Text="Advanced DrawingView"/>
60-
<views:DrawingView
61-
x:Name="DrawingViewControl"
62-
Points="{Binding MacroPoints, Mode=TwoWay}"
63-
EnableSmoothedPath="false"
64-
Granularity="5"
65-
BackgroundColor="DarkGray"
66-
ClearOnFinish="{Binding Source={x:Reference ClearOnFinish}, Path=IsToggled}"
67-
HorizontalOptions="FillAndExpand"
68-
LineColor="Red"
69-
LineWidth="10"
70-
HeightRequest="200" />
7164
<Editor x:Name="Logs" HeightRequest="50" />
7265
</StackLayout>
7366
</ScrollView>

0 commit comments

Comments
 (0)