This commit is contained in:
Javier Suárez Ruiz 2021-01-03 17:57:04 +01:00
Родитель fefd7cb265
Коммит a88db60c35
13 изменённых файлов: 170 добавлений и 4 удалений

Двоичные данные
data/DrawnButton Performance.xlsx Normal file

Двоичный файл не отображается.

Двоичные данные
data/DrawnEntry Performance.xlsx Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -18,6 +18,7 @@ namespace GraphicsControls.Sample.iOS
// //
public override bool FinishedLaunching(UIApplication app, NSDictionary options) public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{ {
Xamarin.Forms.FormsMaterial.Init();
Xamarin.Forms.Forms.Init(); Xamarin.Forms.Forms.Init();
LoadApplication(new App()); LoadApplication(new App());

Просмотреть файл

@ -125,6 +125,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1687" /> <PackageReference Include="Xamarin.Forms" Version="4.8.0.1687" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" /> <PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
<PackageReference Include="Xamarin.Forms.Visual.Material">
<Version>4.8.0.1687</Version>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\GraphicsControls.Sample\GraphicsControls.Sample.csproj"> <ProjectReference Include="..\GraphicsControls.Sample\GraphicsControls.Sample.csproj">

Просмотреть файл

@ -9,6 +9,7 @@ namespace GraphicsControls.Sample
InitializeComponent(); InitializeComponent();
MainPage = new MainPage(); MainPage = new MainPage();
//MainPage = new NavigationPage(new BenchmarkPage());
} }
protected override void OnStart() protected override void OnStart()

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using Xamarin.Forms;
namespace GraphicsControls.Sample
{
public static class BenchmarkSettings
{
public static int NumberOfViews { get; } = 10;
}
public class BenchmarkPage : ContentPage
{
public BenchmarkPage()
{
Title = "GraphicsControls Benchmark";
var layout = new StackLayout();
var nativeButton = new Button
{
Text = "Use Native Controls"
};
var drawnButton = new Button
{
Text = "Use Drawn Controls"
};
layout.Children.Add(nativeButton);
layout.Children.Add(drawnButton);
Content = layout;
nativeButton.Clicked += OnNativeButtonClicked;
drawnButton.Clicked += OnDrawnButtonClicked;
}
void OnNativeButtonClicked(object sender, EventArgs e)
{
Navigation.PushAsync(new NativeBenchmarkPage());
}
void OnDrawnButtonClicked(object sender, EventArgs e)
{
Navigation.PushAsync(new DrawnBenchmarkPage());
}
}
}

Просмотреть файл

@ -0,0 +1,50 @@
using System.Diagnostics;
using Xamarin.Forms;
namespace GraphicsControls.Sample
{
public class DrawnBenchmarkPage : ContentPage
{
readonly Stopwatch _stopwatch;
readonly Label _infoLabel;
public DrawnBenchmarkPage()
{
Title = "Use Drawn Controls";
_stopwatch = new Stopwatch();
_stopwatch.Start();
var scrollView = new ScrollView();
var layout = new StackLayout();
_infoLabel = new Label
{
FontSize = 36,
HorizontalOptions = LayoutOptions.Center
};
layout.Children.Add(_infoLabel);
for (int i = 0; i < BenchmarkSettings.NumberOfViews; i++)
{
var drawnButton = new Button { VisualType = VisualType.Material, Text = $"Button {i + 1}" };
layout.Children.Add(drawnButton);
}
scrollView.Content = layout;
Content = scrollView;
}
protected override void OnAppearing()
{
base.OnAppearing();
_stopwatch.Stop();
_infoLabel.Text = $"{_stopwatch.ElapsedMilliseconds} ms";
}
}
}

Просмотреть файл

@ -0,0 +1,50 @@
using System.Diagnostics;
using Xamarin.Forms;
namespace GraphicsControls.Sample
{
public class NativeBenchmarkPage : ContentPage
{
readonly Stopwatch _stopwatch;
readonly Label _infoLabel;
public NativeBenchmarkPage()
{
Title = "Use Native Controls";
_stopwatch = new Stopwatch();
_stopwatch.Start();
var scrollView = new ScrollView();
var layout = new StackLayout();
_infoLabel = new Label
{
FontSize = 36,
HorizontalOptions = LayoutOptions.Center
};
layout.Children.Add(_infoLabel);
for (int i = 0; i < BenchmarkSettings.NumberOfViews; i++)
{
var drawnButton = new Xamarin.Forms.Button { Visual = VisualMarker.Material, Text = $"Button {i + 1}" };
layout.Children.Add(drawnButton);
}
scrollView.Content = layout;
Content = scrollView;
}
protected override void OnAppearing()
{
base.OnAppearing();
_stopwatch.Stop();
_infoLabel.Text = $"{_stopwatch.ElapsedMilliseconds} ms";
}
}
}

Просмотреть файл

@ -17,4 +17,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\GraphicsControls\GraphicsControls.csproj" /> <ProjectReference Include="..\GraphicsControls\GraphicsControls.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Benchmark\" />
</ItemGroup>
</Project> </Project>

Просмотреть файл

@ -29,7 +29,14 @@ namespace GraphicsControls
Content = _entry; Content = _entry;
} }
public static readonly BindableProperty TextProperty = InputElement.TextProperty; public static readonly BindableProperty TextProperty =
BindableProperty.Create(nameof(IInput.Text), typeof(string), typeof(IInput), string.Empty,
propertyChanged: OnTextChanged);
static void OnTextChanged(BindableObject bindable, object oldValue, object newValue)
{
(bindable as Entry)?.UpdateText();
}
public static readonly BindableProperty TextColorProperty = public static readonly BindableProperty TextColorProperty =
BindableProperty.Create(nameof(IInput.TextColor), typeof(XColor), typeof(IInput), XColor.Default, BindableProperty.Create(nameof(IInput.TextColor), typeof(XColor), typeof(IInput), XColor.Default,
@ -109,6 +116,7 @@ namespace GraphicsControls
AnimateMaterialPlaceholder(IsFocused); AnimateMaterialPlaceholder(IsFocused);
UpdateEntryPosition(); UpdateEntryPosition();
UpdateText();
UpdateTextColor(); UpdateTextColor();
UpdateCharacterSpacing(); UpdateCharacterSpacing();
} }
@ -278,6 +286,11 @@ namespace GraphicsControls
_entry.Text = string.Empty; _entry.Text = string.Empty;
} }
void UpdateText()
{
_entry.Text = Text;
}
void UpdateTextColor() void UpdateTextColor()
{ {
if (TextColor != XColor.Default) if (TextColor != XColor.Default)

Просмотреть файл

@ -29,7 +29,6 @@ namespace GraphicsControls.Android
if (e.OldElement != null) if (e.OldElement != null)
{ {
e.OldElement.Invalidated -= OnDrawInvalidated; e.OldElement.Invalidated -= OnDrawInvalidated;
SetNativeControl(null);
} }
if (e.NewElement != null) if (e.NewElement != null)

Просмотреть файл

@ -33,7 +33,6 @@ namespace GraphicsControls.iOS
if (e.OldElement != null) if (e.OldElement != null)
{ {
e.OldElement.Invalidated -= OnDrawInvalidated; e.OldElement.Invalidated -= OnDrawInvalidated;
SetNativeControl(null);
} }
if (e.NewElement != null) if (e.NewElement != null)

Просмотреть файл

@ -33,7 +33,6 @@ namespace GraphicsControls.Mac
if (e.OldElement != null) if (e.OldElement != null)
{ {
e.OldElement.Invalidated -= OnDrawInvalidated; e.OldElement.Invalidated -= OnDrawInvalidated;
SetNativeControl(null);
} }
if (e.NewElement != null) if (e.NewElement != null)