This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Issue10679, avoid NRE accessing a disposed SwipeView (#10682)
Co-authored-by: Rui Marinho <me@ruimarinho.net>
- Loading branch information
1 parent
1d46ce9
commit f5575fb
Showing
3 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue10679.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<local:TestShell xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:d="http://xamarin.com/schemas/2014/forms/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
xmlns:local="using:Xamarin.Forms.Controls" | ||
xmlns:issues="using:Xamarin.Forms.Controls.Issues" | ||
x:Class="Xamarin.Forms.Controls.Issues.Issue10679"> | ||
<Shell.Resources> | ||
<ResourceDictionary> | ||
|
||
<Color x:Key="NavigationPrimary">#2196F3</Color> | ||
|
||
<Style x:Key="BaseStyle" | ||
TargetType="Element"> | ||
<Setter Property="Shell.BackgroundColor" Value="{StaticResource NavigationPrimary}" /> | ||
<Setter Property="Shell.ForegroundColor" Value="White" /> | ||
<Setter Property="Shell.TitleColor" Value="White" /> | ||
<Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" /> | ||
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" /> | ||
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource NavigationPrimary}" /> | ||
<Setter Property="Shell.TabBarForegroundColor" Value="White" /> | ||
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF" /> | ||
<Setter Property="Shell.TabBarTitleColor" Value="White" /> | ||
</Style> | ||
|
||
<Style BasedOn="{StaticResource BaseStyle}" | ||
TargetType="TabBar" /> | ||
|
||
</ResourceDictionary> | ||
</Shell.Resources> | ||
<ShellContent ContentTemplate="{DataTemplate issues:FirstIssue10679Page}" /> | ||
</local:TestShell> |
148 changes: 148 additions & 0 deletions
148
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue10679.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
using System.Collections.Generic; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
#if UITEST | ||
using Xamarin.Forms.Core.UITests; | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 10679, "SwipeView crash with NullReferenceException", | ||
PlatformAffected.Android)] | ||
public partial class Issue10679 : TestShell | ||
{ | ||
public Issue10679() | ||
{ | ||
#if APP | ||
Device.SetFlags(new List<string>(Device.Flags ?? new List<string>()) { "SwipeView_Experimental" }); | ||
InitializeComponent(); | ||
#endif | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
|
||
} | ||
} | ||
|
||
[Preserve(AllMembers = true)] | ||
public class FirstIssue10679Page : ContentPage | ||
{ | ||
public FirstIssue10679Page() | ||
{ | ||
Title = "Issue 10679"; | ||
|
||
var layout = new Grid(); | ||
|
||
var button = new Button | ||
{ | ||
VerticalOptions = LayoutOptions.Center, | ||
Text = "Go to Next Page" | ||
}; | ||
|
||
layout.Children.Add(button); | ||
|
||
Content = layout; | ||
|
||
button.Clicked += async (sender, args) => | ||
{ | ||
await Shell.Current.Navigation.PushAsync(new SecondIssue10679Page()).ConfigureAwait(false); | ||
}; | ||
} | ||
} | ||
|
||
[Preserve(AllMembers = true)] | ||
public class SecondIssue10679Page : ContentPage | ||
{ | ||
public SecondIssue10679Page() | ||
{ | ||
var layout = new Grid(); | ||
|
||
var swipeView = new SwipeView(); | ||
|
||
var leftItem = new SwipeItem | ||
{ | ||
BackgroundColor = Color.Red | ||
}; | ||
|
||
var leftItems = new SwipeItems | ||
{ | ||
Mode = SwipeMode.Execute, | ||
SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.Close | ||
}; | ||
|
||
leftItems.Add(leftItem); | ||
|
||
var rightItem = new SwipeItem | ||
{ | ||
BackgroundColor = Color.Green | ||
}; | ||
|
||
var rightItems = new SwipeItems | ||
{ | ||
Mode = SwipeMode.Execute, | ||
SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.Close | ||
}; | ||
|
||
rightItems.Add(rightItem); | ||
|
||
var content = new Grid | ||
{ | ||
BackgroundColor = Color.White | ||
}; | ||
|
||
var contentLabel = new Label | ||
{ | ||
HorizontalOptions = LayoutOptions.Center, | ||
VerticalOptions = LayoutOptions.Center, | ||
Text = "Swipe Left or Right" | ||
}; | ||
|
||
content.Children.Add(contentLabel); | ||
|
||
swipeView.Content = content; | ||
swipeView.LeftItems = leftItems; | ||
swipeView.RightItems = rightItems; | ||
|
||
layout.Children.Add(swipeView); | ||
|
||
Content = layout; | ||
|
||
leftItem.Invoked += async (sender, args) => | ||
{ | ||
Shell.Current.Navigation.InsertPageBefore(new ThirdIssue10679Page(), this); | ||
_ = await Shell.Current.Navigation.PopAsync(false); | ||
}; | ||
|
||
rightItem.Invoked += async (sender, args) => | ||
{ | ||
Shell.Current.Navigation.InsertPageBefore(new ThirdIssue10679Page(), this); | ||
_ = await Shell.Current.Navigation.PopAsync(false); | ||
}; | ||
} | ||
} | ||
|
||
[Preserve(AllMembers = true)] | ||
public class ThirdIssue10679Page : ContentPage | ||
{ | ||
public ThirdIssue10679Page() | ||
{ | ||
var layout = new StackLayout(); | ||
|
||
var infoLabel = new Label | ||
{ | ||
HorizontalOptions = LayoutOptions.Center, | ||
VerticalOptions = LayoutOptions.Center, | ||
Text = "Without NullReferenceException, the test has passed." | ||
}; | ||
|
||
layout.Children.Add(infoLabel); | ||
|
||
Content = layout; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters