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

Commit

Permalink
Add Preserve attributes to all Export attributes (#10371)
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen authored Apr 18, 2020
1 parent 3d0108c commit 5a96f79
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
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, 9794, "[iOS] Tabbar Disappears with linker",
PlatformAffected.iOS)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
#endif
public class Issue9794 : TestShell
{
protected override void Init()
{
var page1 = AddBottomTab("tab1");
AddBottomTab("tab2");

page1.Content = new StackLayout()
{
Children =
{
new Label()
{
Text = "Push a page, click back button, and then click between the tabs. If the tab bar disappears the test has failed.",
},
new Button()
{
Text = "Push Page",
AutomationId = "GoForward",
Command = new Command(async () =>
{
await Navigation.PushAsync(new Issue9794Modal());
})
}
}
};
}

public class Issue9794Modal : ContentPage
{
public Issue9794Modal()
{
Shell.SetTabBarIsVisible(this, false);
Content = new StackLayout()
{
Children =
{
new Label()
{
Text = "Click Back Button"
}
}
};
}
}



#if UITEST && __SHELL__
[Test]
public void EnsureTabBarStaysVisibleAfterPoppingPage()
{
RunningApp.Tap("GoForward");
TapBackArrow();
RunningApp.Tap("tab2");
RunningApp.Tap("tab1");
RunningApp.Tap("tab2");
RunningApp.Tap("tab1");
RunningApp.Tap("tab2");
RunningApp.Tap("tab1");
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,12 @@ public virtual void TearDown()
public abstract class TestShell : Shell
{
protected const string FlyoutIconAutomationId = "OK";
#if __IOS__
protected const string BackButtonAutomationId = "Back";
#else
protected const string BackButtonAutomationId = "OK";
#endif

#if UITEST
public IApp RunningApp => AppSetup.RunningApp;
protected virtual bool Isolate => true;
Expand Down Expand Up @@ -796,6 +802,12 @@ public void ShowFlyout(string flyoutIcon = FlyoutIconAutomationId, bool usingSwi
}
}

public void TapBackArrow(string backArrowIcon = BackButtonAutomationId)
{
RunningApp.WaitForElement(backArrowIcon, "Back Arrow Not Found");
RunningApp.Tap(backArrowIcon);
}


public void TapInFlyout(string text, string flyoutIcon = FlyoutIconAutomationId, bool usingSwipe = false, string timeoutMessage = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue9417.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8272.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8964.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9794.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Platform.iOS/CollectionView/DefaultCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public abstract class DefaultCell : ItemsViewCell
protected NSLayoutConstraint Constraint { get; set; }

[Export("initWithFrame:")]
[Internals.Preserve(Conditional = true)]
protected DefaultCell(CGRect frame) : base(frame)
{
Label = new UILabel(frame)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Xamarin.Forms.Platform.iOS
internal abstract partial class HeightConstrainedTemplatedCell : TemplatedCell
{
[Export("initWithFrame:")]
[Internals.Preserve(Conditional = true)]
public HeightConstrainedTemplatedCell(CGRect frame) : base(frame)
{
}
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Xamarin.Forms.Platform.iOS
public abstract class ItemsViewCell : UICollectionViewCell
{
[Export("initWithFrame:")]
[Internals.Preserve(Conditional = true)]
protected ItemsViewCell(CGRect frame) : base(frame)
{
ContentView.BackgroundColor = UIColor.Clear;
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Platform.iOS/CollectionView/TemplatedCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class TemplatedCell : ItemsViewCell
Size _size;

[Export("initWithFrame:")]
[Internals.Preserve(Conditional = true)]
protected TemplatedCell(CGRect frame) : base(frame)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Xamarin.Forms.Platform.iOS
internal abstract class WidthConstrainedTemplatedCell : TemplatedCell
{
[Export("initWithFrame:")]
[Internals.Preserve(Conditional = true)]
public WidthConstrainedTemplatedCell(CGRect frame) : base(frame)
{
}
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Platform.iOS/ModalWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal ModalWrapper(IVisualElementRenderer modal)
}
#if __XCODE11__
[Export("presentationControllerDidDismiss:")]
[Internals.Preserve(Conditional = true)]
public async void DidDismiss(UIPresentationController presentationController)
{
await Application.Current.NavigationProxy.PopModalAsync(false);
Expand Down
3 changes: 3 additions & 0 deletions Xamarin.Forms.Platform.iOS/Renderers/PageContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected override void Dispose(bool disposing)
}

[Export("accessibilityElementCount")]
[Internals.Preserve(Conditional = true)]
nint AccessibilityElementCount()
{
if (AccessibilityElements == null || AccessibilityElements.Count == 0)
Expand All @@ -61,6 +62,7 @@ nint AccessibilityElementCount()
}

[Export("accessibilityElementAtIndex:")]
[Internals.Preserve(Conditional = true)]
NSObject GetAccessibilityElementAt(nint index)
{
if (AccessibilityElements == null || AccessibilityElements.Count == 0)
Expand All @@ -71,6 +73,7 @@ NSObject GetAccessibilityElementAt(nint index)
}

[Export("indexOfAccessibilityElement:")]
[Internals.Preserve(Conditional = true)]
int GetIndexOfAccessibilityElement(NSObject element)
{
if (AccessibilityElements == null || AccessibilityElements.Count == 0)
Expand Down
2 changes: 2 additions & 0 deletions Xamarin.Forms.Platform.iOS/Renderers/ShellFlyoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ public void FocusSearch(bool forwardDirection)
public UIViewController ViewController => throw new NotImplementedException();

[Foundation.Export("tabForward:")]
[Internals.Preserve(Conditional = true)]
void TabForward(UIKeyCommand cmd) => FocusSearch(forwardDirection: true);

[Foundation.Export("tabBackward:")]
[Internals.Preserve(Conditional = true)]
void TabBackward(UIKeyCommand cmd) => FocusSearch(forwardDirection: false);

void HandlePanGesture(UIPanGestureRecognizer pan)
Expand Down
3 changes: 2 additions & 1 deletion Xamarin.Forms.Platform.iOS/Renderers/ShellSectionRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public ShellSectionRenderer(IShellContext context)
}

[Export("navigationBar:shouldPopItem:")]
[Internals.Preserve(Conditional = true)]
public bool ShouldPopItem(UINavigationBar navigationBar, UINavigationItem item)
{
{
// this means the pop is already done, nothing we can do
if (ViewControllers.Length < NavigationBar.Items.Length)
return true;
Expand Down
2 changes: 2 additions & 0 deletions Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,11 @@ public override void KeyDown(NSEvent theEvent)


[Foundation.Export("tabForward:")]
[Internals.Preserve(Conditional = true)]
void TabForward(UIKeyCommand cmd) => FocusSearch(forwardDirection: true);

[Foundation.Export("tabBackward:")]
[Internals.Preserve(Conditional = true)]
void TabBackward(UIKeyCommand cmd) => FocusSearch(forwardDirection: false);
#endif

Expand Down

0 comments on commit 5a96f79

Please sign in to comment.