Added benckmark samples
This commit is contained in:
Родитель
fefd7cb265
Коммит
a88db60c35
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -18,6 +18,7 @@ namespace GraphicsControls.Sample.iOS
|
|||
//
|
||||
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
|
||||
{
|
||||
Xamarin.Forms.FormsMaterial.Init();
|
||||
Xamarin.Forms.Forms.Init();
|
||||
LoadApplication(new App());
|
||||
|
||||
|
|
|
@ -125,6 +125,9 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1687" />
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
|
||||
<PackageReference Include="Xamarin.Forms.Visual.Material">
|
||||
<Version>4.8.0.1687</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GraphicsControls.Sample\GraphicsControls.Sample.csproj">
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace GraphicsControls.Sample
|
|||
InitializeComponent();
|
||||
|
||||
MainPage = new MainPage();
|
||||
//MainPage = new NavigationPage(new BenchmarkPage());
|
||||
}
|
||||
|
||||
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>
|
||||
<ProjectReference Include="..\GraphicsControls\GraphicsControls.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Benchmark\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -29,7 +29,14 @@ namespace GraphicsControls
|
|||
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 =
|
||||
BindableProperty.Create(nameof(IInput.TextColor), typeof(XColor), typeof(IInput), XColor.Default,
|
||||
|
@ -109,6 +116,7 @@ namespace GraphicsControls
|
|||
AnimateMaterialPlaceholder(IsFocused);
|
||||
|
||||
UpdateEntryPosition();
|
||||
UpdateText();
|
||||
UpdateTextColor();
|
||||
UpdateCharacterSpacing();
|
||||
}
|
||||
|
@ -278,6 +286,11 @@ namespace GraphicsControls
|
|||
_entry.Text = string.Empty;
|
||||
}
|
||||
|
||||
void UpdateText()
|
||||
{
|
||||
_entry.Text = Text;
|
||||
}
|
||||
|
||||
void UpdateTextColor()
|
||||
{
|
||||
if (TextColor != XColor.Default)
|
||||
|
|
|
@ -29,7 +29,6 @@ namespace GraphicsControls.Android
|
|||
if (e.OldElement != null)
|
||||
{
|
||||
e.OldElement.Invalidated -= OnDrawInvalidated;
|
||||
SetNativeControl(null);
|
||||
}
|
||||
|
||||
if (e.NewElement != null)
|
||||
|
|
|
@ -33,7 +33,6 @@ namespace GraphicsControls.iOS
|
|||
if (e.OldElement != null)
|
||||
{
|
||||
e.OldElement.Invalidated -= OnDrawInvalidated;
|
||||
SetNativeControl(null);
|
||||
}
|
||||
|
||||
if (e.NewElement != null)
|
||||
|
|
|
@ -33,7 +33,6 @@ namespace GraphicsControls.Mac
|
|||
if (e.OldElement != null)
|
||||
{
|
||||
e.OldElement.Invalidated -= OnDrawInvalidated;
|
||||
SetNativeControl(null);
|
||||
}
|
||||
|
||||
if (e.NewElement != null)
|
||||
|
|
Загрузка…
Ссылка в новой задаче