Merge branch '4.1.0' into 4.2.0
authorSamantha Houts <samantha.houts@xamarin.com>
Sat, 17 Aug 2019 00:51:53 +0000 (17:51 -0700)
committerSamantha Houts <samantha.houts@xamarin.com>
Sat, 17 Aug 2019 00:51:53 +0000 (17:51 -0700)
Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj
Xamarin.Forms.ControlGallery.WindowsUniversal/_5886DependencyService.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5886.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/Platform.cs
Xamarin.Forms.Platform.UAP/ScrollViewRenderer.cs
Xamarin.Forms.Platform.iOS/ContextActionCell.cs
Xamarin.Forms.Platform.iOS/Extensions/Extensions.cs
Xamarin.Forms.Platform.iOS/Forms.cs
Xamarin.Forms.Platform.iOS/ModalWrapper.cs
Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs

index 4200241..46d3a01 100644 (file)
     <Compile Include="_2489CustomRenderer.cs" />
     <Compile Include="_57114Renderer.cs" />
     <Compile Include="_58406EffectRenderer.cs" />
+    <Compile Include="_5886DependencyService.cs" />
     <Compile Include="_60122ImageRenderer.cs" />
     <Content Include="Assets\Fonts\OFL.txt" />
     <Content Include="bank.png" />
diff --git a/Xamarin.Forms.ControlGallery.WindowsUniversal/_5886DependencyService.cs b/Xamarin.Forms.ControlGallery.WindowsUniversal/_5886DependencyService.cs
new file mode 100644 (file)
index 0000000..3ef2c2d
--- /dev/null
@@ -0,0 +1,32 @@
+using Xamarin.Forms;
+using Xamarin.Forms.ControlGallery.WindowsUniversal;
+using Xamarin.Forms.Platform.UWP;
+using static Xamarin.Forms.Controls.Issues.Issue5886;
+
+[assembly: Dependency(typeof(MyInterfaceImplementation))]
+namespace Xamarin.Forms.ControlGallery.WindowsUniversal
+{
+       public class MyInterfaceImplementation : IReplaceUWPRendererService
+       {
+               public MyInterfaceImplementation()
+               {
+               }
+
+               public void ConvertToNative(View formsView)
+               {
+                       var renderer = Xamarin.Forms.Platform.UWP.Platform.GetRenderer(formsView);
+                       if (renderer != null)
+                       {
+                               renderer.Dispose();
+                               Platform.UWP.Platform.SetRenderer(formsView, null);
+                       }
+
+                       var newRenderer = formsView.GetOrCreateRenderer();
+               }
+
+               public void CreateRenderer(View formsView)
+               {
+                       var newRenderer = formsView.GetOrCreateRenderer();
+               }
+       }
+}
\ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5886.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5886.cs
new file mode 100644 (file)
index 0000000..c30a794
--- /dev/null
@@ -0,0 +1,98 @@
+using System;
+#if UITEST
+using NUnit.Framework;
+using Xamarin.Forms.Core.UITests;
+using System.Linq;
+#endif
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+namespace Xamarin.Forms.Controls.Issues
+{
+#if UITEST
+       [Category(UITestCategories.Layout)]
+#endif
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Github, 5886, "Value does not fall with in the expected range Exception while creating NativeView Xamarin Forms UWP", PlatformAffected.UWP)]
+       public class Issue5886 : TestContentPage
+       {
+               public interface IReplaceUWPRendererService
+               {
+                       void ConvertToNative(View formsView);
+                       void CreateRenderer(View formsView);
+               }
+
+               ScrollView scrollView;
+               Label label;
+               Button button0;
+               Button button1;
+               protected override void Init()
+               {
+                       scrollView = new ScrollView();
+
+                       var grid = new Grid();
+                       grid.Children.Add(new Label { Text = "Discard Draft ?" });
+
+                       scrollView.Content = grid;
+
+                       button0 = new Button
+                       {
+                               Text = "Create native renderer",
+                               AutomationId = "Step1"
+                       };
+
+                       button0.Clicked += Button_Clicked1;
+
+                       button1 = new Button
+                       {
+                               Text = "Start native view conversion",
+                               AutomationId = "Step2",
+                               IsVisible = false
+                       };
+
+                       button1.Clicked += Button_Clicked;
+
+                       label = new Label
+                       {
+                               Text = "You should be able to push first the top button, then the bottom without any exception (Element is already the child of another element.)",
+                               AutomationId = "ResultLabel"
+                       };
+
+                       var stack = new StackLayout();
+                       stack.Children.Add(button0);
+                       stack.Children.Add(button1);
+                       stack.Children.Add(label);
+
+                       Content = stack;
+               }
+
+               void Button_Clicked(object sender, EventArgs e)
+               {
+                       DependencyService.Get<IReplaceUWPRendererService>().ConvertToNative(this.scrollView);
+                       label.Text = "Step 2 OK";
+               }
+
+               void Button_Clicked1(object sender, EventArgs e)
+               {
+                       DependencyService.Get<IReplaceUWPRendererService>().CreateRenderer(this.scrollView);
+                       label.Text = "Step 1 OK";
+                       button1.IsVisible = true;
+               }
+
+#if UITEST && __WINDOWS__
+               [Test]
+               public void ReplaceRenderer()
+               {
+                       RunningApp.WaitForElement("Step1");
+                       RunningApp.Tap("Step1");
+
+                       RunningApp.WaitForElement("Step2");
+                       RunningApp.Tap("Step2");
+
+                       var resultLabel = RunningApp.Query("ResultLabel").FirstOrDefault();
+
+                       Assert.AreEqual("Step 2 OK", resultLabel.Description);
+               }
+#endif
+       }
+}
index 5e1c48a..f0800b8 100644 (file)
@@ -41,6 +41,7 @@
     </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla59172.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)FlagTestHelpers.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Issue5886.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue6260.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue5766.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)CollectionViewBoundMultiSelection.cs" />
     <Compile Update="$(MSBuildThisFileDirectory)Issue6644.xaml.cs">
       <DependentUpon>Issue6644.xaml</DependentUpon>
     </Compile>
+    <Compile Update="$(MSBuildThisFileDirectory)Issue6254.xaml.cs">
+      <DependentUpon>Issue6254.xaml</DependentUpon>
+    </Compile>
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue5268.xaml">
index cff0261..c277e2c 100644 (file)
@@ -582,7 +582,7 @@ namespace Xamarin.Forms.Platform.Android
                                ClearMasterDetailToggle();
                                return;
                        }
-                       if (!CurrentMasterDetailPage.ShouldShowToolbarButton() || CurrentMasterDetailPage.Master.IconImageSource.IsEmpty ||
+                       if (!CurrentMasterDetailPage.ShouldShowToolbarButton() || (CurrentMasterDetailPage.Master.IconImageSource?.IsEmpty ?? true) ||
                                (MasterDetailPageController.ShouldShowSplitMode && CurrentMasterDetailPage.IsPresented))
                        {
                                //clear out existing icon;
index 378c6c0..918991a 100644 (file)
@@ -72,6 +72,9 @@ namespace Xamarin.Forms.Platform.UWP
                                        element.LayoutUpdated -= SetInitialRtlPosition;
                                }
                        }
+
+                       if (_currentView != null)
+                               _currentView.Cleanup();
                }
 
                protected override void OnElementChanged(ElementChangedEventArgs<ScrollView> e)
index 2686de1..913be60 100644 (file)
@@ -146,7 +146,6 @@ namespace Xamarin.Forms.Platform.iOS
                        var handler = new PropertyChangedEventHandler(OnMenuItemPropertyChanged);
 
                        _tableView = tableView;
-                       SetupSelection(tableView);
 
                        if (_cell != null)
                        {
@@ -641,7 +640,7 @@ namespace Xamarin.Forms.Platform.iOS
                        return null;
                }
 
-               static void SetupSelection(UITableView table)
+               internal static void SetupSelection(UITableView table)
                {
                        if (table.GestureRecognizers == null)
                                return;
@@ -722,4 +721,4 @@ namespace Xamarin.Forms.Platform.iOS
                        }
                }
        }
-}
\ No newline at end of file
+}
index 828f206..aecc175 100644 (file)
@@ -1,3 +1,4 @@
+using System;
 using UIKit;
 using Xamarin.Forms.Internals;
 
@@ -74,6 +75,19 @@ namespace Xamarin.Forms.Platform.iOS
                        }
                }
 
+               internal static UIModalPresentationStyle ToNativeModalPresentationStyle(this PlatformConfiguration.iOSSpecific.UIModalPresentationStyle style)
+               {
+                       switch (style)
+                       {
+                               case PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.FormSheet:
+                                       return UIModalPresentationStyle.FormSheet;
+                               case PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.FullScreen:
+                                       return UIModalPresentationStyle.FullScreen;
+                               default:
+                                       throw new ArgumentOutOfRangeException(nameof(style));
+                       }
+               }
+
                internal static UIReturnKeyType ToUIReturnKeyType(this ReturnType returnType)
                {
                        switch (returnType)
index 1911760..b674f8c 100644 (file)
@@ -36,6 +36,7 @@ namespace Xamarin.Forms
                static bool? s_isiOS9OrNewer;
                static bool? s_isiOS10OrNewer;
                static bool? s_isiOS11OrNewer;
+               static bool? s_isiOS13OrNewer;
                static bool? s_respondsTosetNeedsUpdateOfHomeIndicatorAutoHidden;
                static bool? s_isiOS13OrNewer;
 #endif
@@ -72,6 +73,16 @@ namespace Xamarin.Forms
                        }
                }
 
+               internal static bool IsiOS13OrNewer
+               {
+                       get
+                       {
+                               if (!s_isiOS13OrNewer.HasValue)
+                                       s_isiOS13OrNewer = UIDevice.CurrentDevice.CheckSystemVersion(13, 0);
+                               return s_isiOS13OrNewer.Value;
+                       }
+               }
+
                internal static bool RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden
                {
                        get
@@ -404,4 +415,4 @@ namespace Xamarin.Forms
                        }
                }
        }
-}
\ No newline at end of file
+}
index 6e22cb7..49299fa 100644 (file)
@@ -14,8 +14,8 @@ namespace Xamarin.Forms.Platform.iOS
                        _modal = modal;
 
                        var elementConfiguration = modal.Element as IElementConfiguration<Page>;
-                       if (elementConfiguration?.On<PlatformConfiguration.iOS>().ModalPresentationStyle() == PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.FormSheet)
-                               ModalPresentationStyle = UIKit.UIModalPresentationStyle.FormSheet;
+                       var modalPresentationStyle = elementConfiguration?.On<PlatformConfiguration.iOS>()?.ModalPresentationStyle() ?? PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.FullScreen;
+                       ModalPresentationStyle = modalPresentationStyle.ToNativeModalPresentationStyle();
 
                        View.BackgroundColor = UIColor.White;
                        View.AddSubview(modal.ViewController.View);
index 69c2239..5aa6d64 100644 (file)
@@ -945,6 +945,7 @@ namespace Xamarin.Forms.Platform.iOS
                        protected ListView List;
                        protected ITemplatedItemsView<Cell> TemplatedItemsView => List;
                        bool _isDragging;
+                       bool _setupSelection;
                        bool _selectionFromNative;
                        bool _disposed;
                        bool _wasEmpty;
@@ -1000,6 +1001,19 @@ namespace Xamarin.Forms.Platform.iOS
                                _isDragging = true;
                        }
 
+                       void SetupSelection(UITableViewCell nativeCell, UITableView tableView)
+                       {
+                               if (!(nativeCell is ContextActionsCell))
+                                       return;
+
+                               if (_setupSelection)
+                                       return;
+
+                               ContextActionsCell.SetupSelection(tableView);
+
+                               _setupSelection = true;
+                       }
+
                        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
                        {
                                Cell cell;
@@ -1037,6 +1051,8 @@ namespace Xamarin.Forms.Platform.iOS
                                else
                                        throw new NotSupportedException();
 
+                               SetupSelection(nativeCell, tableView);
+
                                if (List.IsSet(Specifics.SeparatorStyleProperty))
                                {
                                        if (List.OnThisPlatform().GetSeparatorStyle() == SeparatorStyle.FullWidth)