Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Fix NRE when using Custom Slide Transition #13494

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Xamarin.Forms.ControlGallery.iOS/CustomRenderers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using CoreGraphics;
using CoreLocation;
using Foundation;
using MapKit;
Expand All @@ -25,8 +26,27 @@
[assembly: ExportRenderer(typeof(Issue1683.EntryKeyboardFlags), typeof(EntryRendererKeyboardFlags))]
[assembly: ExportRenderer(typeof(Issue1683.EditorKeyboardFlags), typeof(EditorRendererKeyboardFlags))]
[assembly: ExportRenderer(typeof(Issue5830.ExtendedEntryCell), typeof(ExtendedEntryCellRenderer))]
[assembly: ExportRenderer(typeof(Issue13390), typeof(Issue13390Renderer))]
namespace Xamarin.Forms.ControlGallery.iOS
{
public class Issue13390Renderer : ShellRenderer
{
protected override IShellFlyoutRenderer CreateFlyoutRenderer()
{
return new ShellFlyoutRenderer()
{
FlyoutTransition = new SlideFlyoutTransition2()
};
}

public class SlideFlyoutTransition2 : IShellFlyoutTransition
{
public void LayoutViews(CGRect bounds, nfloat openPercent, UIView flyout, UIView shell, FlyoutBehavior behavior)
{
flyout.Frame = new CGRect(0, 0, 0, 0);
}
}
}

public class CustomIOSMapRenderer : ViewRenderer<Bugzilla39987.CustomMapView, MKMapView>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Linq;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;


#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 13390, "Custom SlideFlyoutTransition is not working",
PlatformAffected.iOS)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
#endif
public class Issue13390 : TestShell
{
protected override void Init()
{
CreateContentPage()
.Content = new Label()
{
Text = "If app has not crashed test has passed",
AutomationId = "Success"
};
}

#if UITEST && __IOS__
[Test]
public void CustomSlideFlyoutTransitionCausesCrash()
{
RunningApp.WaitForElement("Success");
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutContentOffest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutContentWithZeroMargin.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13436.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13390.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down
6 changes: 2 additions & 4 deletions Xamarin.Forms.Platform.iOS/Renderers/ShellFlyoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ void IAppearanceObserver.OnAppearanceChanged(ShellAppearance appearance)
{
_backdropBrush = appearance.FlyoutBackdrop;

if (appearance.FlyoutHeight != SlideFlyoutTransition.Height ||
appearance.FlyoutWidth != SlideFlyoutTransition.Width)
if (SlideFlyoutTransition?.UpdateFlyoutSize(appearance.FlyoutHeight, appearance.FlyoutWidth) ==
true)
{
SlideFlyoutTransition?.SetFlyoutSizes(appearance.FlyoutHeight, appearance.FlyoutWidth);

if(_layoutOccured)
LayoutSidebar(false, true);
}
Expand Down
15 changes: 11 additions & 4 deletions Xamarin.Forms.Platform.iOS/Renderers/SlideFlyoutTransition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ public class SlideFlyoutTransition : IShellFlyoutTransition
internal double Height { get; private set; } = -1d;
internal double Width { get; private set; } = -1d;

internal void SetFlyoutSizes(double height, double width)
public virtual bool UpdateFlyoutSize(double height, double width)
{
Height = height;
Width = width;
if (Height != height ||
Width != width)
{
Height = height;
Width = width;
return true;
}

return false;
}

public void LayoutViews(CGRect bounds, nfloat openPercent, UIView flyout, UIView shell, FlyoutBehavior behavior)
public virtual void LayoutViews(CGRect bounds, nfloat openPercent, UIView flyout, UIView shell, FlyoutBehavior behavior)
{
if (behavior == FlyoutBehavior.Locked)
openPercent = 1;
Expand Down