зеркало из https://github.com/DeGsoft/maui-linux.git
Fix entry renderer font size (#1258)
This commit is contained in:
Родитель
40eadeb644
Коммит
cf0c594fd9
|
@ -0,0 +1,74 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Bugzilla, 59925, "Issue Description", PlatformAffected.Default)]
|
||||
public class Bugzilla59925 : TestContentPage // or TestMasterDetailPage, etc ...
|
||||
{
|
||||
const int Delta = 1;
|
||||
Entry _entry;
|
||||
|
||||
private void ChangeFontSize(int delta)
|
||||
{
|
||||
_entry.FontSize += delta;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
_entry = new Entry
|
||||
{
|
||||
Text = "Hello World!"
|
||||
};
|
||||
|
||||
var buttonBigger = new Button
|
||||
{
|
||||
Text = "Bigger",
|
||||
};
|
||||
buttonBigger.Clicked += (x, o) => ChangeFontSize(Delta);
|
||||
|
||||
var buttonSmaller = new Button
|
||||
{
|
||||
Text = "Smaller"
|
||||
};
|
||||
buttonSmaller.Clicked += (x, o) => ChangeFontSize(-Delta);
|
||||
|
||||
var stack = new StackLayout
|
||||
{
|
||||
Children = {
|
||||
buttonBigger,
|
||||
buttonSmaller,
|
||||
_entry
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize ui here instead of ctor
|
||||
Content = stack;
|
||||
}
|
||||
|
||||
#if UITEST
|
||||
[Test]
|
||||
public void Issue123456Test ()
|
||||
{
|
||||
RunningApp.Screenshot ("I am at Issue 123456");
|
||||
RunningApp.WaitForElement (q => q.Marked ("Bigger"));
|
||||
RunningApp.Screenshot ("0");
|
||||
|
||||
RunningApp.Tap ("Bigger");
|
||||
RunningApp.Screenshot("1");
|
||||
|
||||
RunningApp.Tap ("Bigger");
|
||||
RunningApp.Screenshot("2");
|
||||
|
||||
RunningApp.Tap ("Bigger");
|
||||
RunningApp.Screenshot("3");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Bugzilla, 59925, "Font size does not change vertical height of Entry on iOS", PlatformAffected.Default)]
|
||||
public class Bugzilla59925 : TestContentPage // or TestMasterDetailPage, etc ...
|
||||
{
|
||||
const int Delta = 1;
|
||||
Entry _entry;
|
||||
|
||||
private void ChangeFontSize(int delta)
|
||||
{
|
||||
_entry.FontSize += delta;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
_entry = new Entry
|
||||
{
|
||||
Text = "Hello World!"
|
||||
};
|
||||
|
||||
var buttonBigger = new Button
|
||||
{
|
||||
Text = "Bigger",
|
||||
};
|
||||
buttonBigger.Clicked += (x, o) => ChangeFontSize(Delta);
|
||||
|
||||
var buttonSmaller = new Button
|
||||
{
|
||||
Text = "Smaller"
|
||||
};
|
||||
buttonSmaller.Clicked += (x, o) => ChangeFontSize(-Delta);
|
||||
|
||||
var stack = new StackLayout
|
||||
{
|
||||
Children = {
|
||||
buttonBigger,
|
||||
buttonSmaller,
|
||||
_entry
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize ui here instead of ctor
|
||||
Content = stack;
|
||||
}
|
||||
|
||||
#if UITEST
|
||||
[Test]
|
||||
public void Issue123456Test ()
|
||||
{
|
||||
RunningApp.Screenshot ("I am at Issue 59925");
|
||||
RunningApp.WaitForElement (q => q.Marked ("Bigger"));
|
||||
RunningApp.Screenshot ("0");
|
||||
|
||||
RunningApp.Tap ("Bigger");
|
||||
RunningApp.Screenshot("1");
|
||||
|
||||
RunningApp.Tap ("Bigger");
|
||||
RunningApp.Screenshot("2");
|
||||
|
||||
RunningApp.Tap ("Bigger");
|
||||
RunningApp.Screenshot("3");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -331,6 +331,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59896.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla56771.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla60524.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59925.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42620.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />
|
||||
|
|
|
@ -1126,8 +1126,6 @@ namespace Xamarin.Forms.Platform.Android
|
|||
}
|
||||
|
||||
return result;
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ using System;
|
|||
using System.ComponentModel;
|
||||
|
||||
using System.Drawing;
|
||||
using CoreGraphics;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
|
||||
|
||||
|
@ -12,21 +14,27 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
UIColor _defaultTextColor;
|
||||
bool _disposed;
|
||||
|
||||
public EntryRenderer()
|
||||
static readonly int baseHeight = 30;
|
||||
static CGSize initialSize = CGSize.Empty;
|
||||
|
||||
public EntryRenderer()
|
||||
{
|
||||
Frame = new RectangleF(0, 20, 320, 40);
|
||||
}
|
||||
|
||||
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
|
||||
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
|
||||
{
|
||||
//with borderStyle set to RoundedRect, iOS always returns a height of 30
|
||||
//https://stackoverflow.com/a/36569247/1063783
|
||||
//we get the current value, and restor it, to allow custom renderers to change the border style
|
||||
var borderStyle = Control.BorderStyle;
|
||||
Control.BorderStyle = UITextBorderStyle.None;
|
||||
var size = Control.GetSizeRequest(widthConstraint, double.PositiveInfinity);
|
||||
Control.BorderStyle = borderStyle;
|
||||
return size;
|
||||
var baseResult = base.GetDesiredSize(widthConstraint, heightConstraint);
|
||||
|
||||
if (Forms.IsiOS11OrNewer)
|
||||
return baseResult;
|
||||
|
||||
NSString testString = new NSString("Tj");
|
||||
var testSize = testString.GetSizeUsingAttributes(new UIStringAttributes { Font = Control.Font });
|
||||
double height = baseHeight + testSize.Height - initialSize.Height;
|
||||
height = Math.Round(height);
|
||||
|
||||
return new SizeRequest(new Size(baseResult.Request.Width, height));
|
||||
}
|
||||
|
||||
IElementController ElementController => Element as IElementController;
|
||||
|
@ -168,6 +176,12 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
|
||||
void UpdateFont()
|
||||
{
|
||||
if (initialSize == CGSize.Empty)
|
||||
{
|
||||
NSString testString = new NSString("Tj");
|
||||
initialSize = testString.StringSize(Control.Font);
|
||||
}
|
||||
|
||||
Control.Font = Element.ToUIFont();
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче