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

Commit

Permalink
Fix NRE when using Custom Slide Transition (#13494) fixes #13390
Browse files Browse the repository at this point in the history
* Fix NRE when using Custom Slide Transition

* - virtual
  • Loading branch information
PureWeen authored Jan 26, 2021
1 parent 3276a59 commit 42a3faa
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
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

0 comments on commit 42a3faa

Please sign in to comment.