diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla123456.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla123456.cs new file mode 100644 index 000000000..921b8a70b --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla123456.cs @@ -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 + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla59925.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla59925.cs new file mode 100644 index 000000000..86500d40b --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla59925.cs @@ -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 + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 9805d4b13..56c362ff9 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -342,6 +342,7 @@ + diff --git a/Xamarin.Forms.Platform.Android/Platform.cs b/Xamarin.Forms.Platform.Android/Platform.cs index 0614b1e00..949089240 100644 --- a/Xamarin.Forms.Platform.Android/Platform.cs +++ b/Xamarin.Forms.Platform.Android/Platform.cs @@ -1146,8 +1146,6 @@ namespace Xamarin.Forms.Platform.Android } return result; - { - } } } diff --git a/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs index 042f59e03..e8cdaab13 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs @@ -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; @@ -170,6 +178,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(); }