[Android, iOS] added re-measure of TimePicker after change value (#4999)
authorPavel Yakovlev <v-payako@microsoft.com>
Thu, 28 Feb 2019 01:49:11 +0000 (04:49 +0300)
committerSamantha Houts <samhouts@users.noreply.github.com>
Thu, 28 Feb 2019 01:49:11 +0000 (17:49 -0800)
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4961.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs
Xamarin.Forms.Platform.iOS/Renderers/TimePickerRenderer.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4961.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4961.cs
new file mode 100644 (file)
index 0000000..38f9d48
--- /dev/null
@@ -0,0 +1,33 @@
+using System;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Github, 4961, "TimePicker does not remeasure its size when picking a new time that is wider than the previously selected value",
+               PlatformAffected.Android | PlatformAffected.iOS)]
+       public class Issue4961 : TestContentPage
+       {
+               protected override void Init()
+               {
+                       Content = new StackLayout
+                       {
+                               Children =
+                               {
+                                       new Label
+                                       {
+                                               Text = "When changing the Time of the TimePicker the control should be remeasured and its size may change. " +
+                                                       "Set the time to 12:50 AM and check that the text does not get out of the screen."
+                                       },
+                                       new TimePicker
+                                       {
+                                               Time = TimeSpan.FromHours(1),
+                                               HorizontalOptions = LayoutOptions.EndAndExpand,
+                                               VerticalOptions = LayoutOptions.Start
+                                       }
+                               }
+                       };
+               }
+       }
+}
\ No newline at end of file
index 47fde52..ab05a3c 100644 (file)
@@ -19,6 +19,7 @@
       <DependentUpon>Issue1588.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="$(MSBuildThisFileDirectory)Issue4961.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue4629.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue4384.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue4782.cs" />
index d102b6d..d0ed9fc 100644 (file)
@@ -41,7 +41,6 @@ namespace Xamarin.Forms.Platform.Android
                void TimePickerDialog.IOnTimeSetListener.OnTimeSet(ATimePicker view, int hourOfDay, int minute)
                {
                        ElementController.SetValueFromRenderer(TimePicker.TimeProperty, new TimeSpan(hourOfDay, minute, 0));
-
                        ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
 
                        if (Forms.IsLollipopOrNewer)
@@ -134,6 +133,7 @@ namespace Xamarin.Forms.Platform.Android
                {
                        var timeFormat = Is24HourView ? "HH:mm" : Element.Format;
                        EditText.Text = DateTime.Today.Add(time).ToString(timeFormat);
+                       Element.InvalidateMeasureNonVirtual(Internals.InvalidationTrigger.MeasureChanged);
                }
 
                void UpdateFont()
index fd41a16..6d85dba 100644 (file)
@@ -159,6 +159,7 @@ namespace Xamarin.Forms.Platform.iOS
                {
                        _picker.Date = new DateTime(1, 1, 1).Add(Element.Time).ToNSDate();
                        Control.Text = DateTime.Today.Add(Element.Time).ToString(Element.Format);
+                       Element.InvalidateMeasureNonVirtual(Internals.InvalidationTrigger.MeasureChanged);
                }
        }
 }
\ No newline at end of file