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

Commit

Permalink
Add Core flags feature; add flag verification for CollectionView feat…
Browse files Browse the repository at this point in the history
…ures
  • Loading branch information
hartez committed Nov 8, 2018
1 parent 0500bd3 commit d0c962b
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 59 deletions.
Expand Up @@ -41,11 +41,11 @@ protected override void OnCreate(Bundle bundle)
base.OnCreate(bundle);

#if TEST_EXPERIMENTAL_RENDERERS
Forms.SetFlags("FastRenderers_Experimental", "CollectionView_Experimental");
Forms.SetFlags("FastRenderers_Experimental");
#else
// Fake_Flag is here so we can test for flag initialization issues
// CollectionView lets us test CollectionView stuff until it's officially released
Forms.SetFlags("Fake_Flag", "CollectionView_Experimental");
Forms.SetFlags("Fake_Flag");
#endif

Forms.Init(this, bundle);
Expand Down
2 changes: 0 additions & 2 deletions Xamarin.Forms.ControlGallery.WindowsUniversal/App.xaml.cs
Expand Up @@ -65,8 +65,6 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)

rootFrame.NavigationFailed += OnNavigationFailed;

Forms.SetFlags("CollectionView_Experimental");

Forms.Init (e);
//FormsMaps.Init (Controls.App.Config["UWPMapsAuthKey"]);

Expand Down
2 changes: 0 additions & 2 deletions Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs
Expand Up @@ -160,8 +160,6 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary

Xamarin.Calabash.Start();

Forms.SetFlags("CollectionView_Experimental");

Forms.Init();
FormsMaps.Init();
Forms.ViewInitialized += (object sender, ViewInitializedEventArgs e) =>
Expand Down
5 changes: 5 additions & 0 deletions Xamarin.Forms.Controls/App.cs
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -31,6 +33,9 @@ public App()
{
_testCloudService = DependencyService.Get<ITestCloudService>();

// Allow use of CollectionView in Control Gallery
SetFlags("CollectionView_Experimental");

SetMainPage(CreateDefaultMainPage());

//TestMainPageSwitches();
Expand Down
26 changes: 26 additions & 0 deletions Xamarin.Forms.Core/Application.cs
Expand Up @@ -7,6 +7,7 @@
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform;
using System.Diagnostics;
using System.Linq;

namespace Xamarin.Forms
{
Expand Down Expand Up @@ -51,6 +52,17 @@ public static bool LogWarningsToApplicationOutput
}
}

static IReadOnlyList<string> s_flags;
#if NETSTANDARD1_0
public static IReadOnlyList<string> Flags => s_flags ?? (s_flags = new ReadOnlyCollection<string>(new List<string>()));
#else
public static IReadOnlyList<string> Flags => s_flags ?? (s_flags = new List<string>().AsReadOnly());
#endif


static bool MainPageSet { get; set; }


public Application()
{
var f = false;
Expand Down Expand Up @@ -120,6 +132,7 @@ public Page MainPage
}

_mainPage = value;
MainPageSet = true;

if (_mainPage != null)
{
Expand Down Expand Up @@ -206,6 +219,19 @@ public ResourceDictionary Resources

public event EventHandler<Page> PageDisappearing;

public static void SetFlags(params string[] flags)
{
if (MainPageSet)
{
throw new InvalidOperationException($"{nameof(SetFlags)} must be called before MainPage is set");
}

#if NETSTANDARD1_0
s_flags = new ReadOnlyCollection<string>(flags.ToList());
#else
s_flags = flags.ToList().AsReadOnly();
#endif
}

async void SaveProperties()
{
Expand Down
5 changes: 5 additions & 0 deletions Xamarin.Forms.Core/Items/CollectionView.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms.Platform;

Expand All @@ -9,5 +10,9 @@ namespace Xamarin.Forms
[RenderWith(typeof(_CollectionViewRenderer))]
public class CollectionView : ItemsView
{
public CollectionView()
{
Flags.VerifyCollectionView(constructorHint: nameof(CollectionView));
}
}
}
5 changes: 2 additions & 3 deletions Xamarin.Forms.Core/Items/ItemsControl.cs
Expand Up @@ -17,6 +17,7 @@ public abstract class ItemsLayout : BindableObject, IItemsLayout

protected ItemsLayout(ItemsLayoutOrientation orientation)
{
Flags.VerifyCollectionView(constructorHint: nameof(ItemsLayout));
Orientation = orientation;
}

Expand Down Expand Up @@ -96,9 +97,7 @@ public enum SnapPointsAlignment
public enum SnapPointsType
{
None,
Optional,
Mandatory,
OptionalSingle,
MandatorySingle,
MandatorySingle
}
}
8 changes: 8 additions & 0 deletions Xamarin.Forms.Core/Items/ItemsView.cs
Expand Up @@ -12,11 +12,13 @@ public static class PropertyChangedEventArgsExtensions
{
public static bool Is(this PropertyChangedEventArgs args, BindableProperty property)
{
Flags.VerifyCollectionView();
return args.PropertyName == property.PropertyName;
}

public static bool IsOneOf(this PropertyChangedEventArgs args, params BindableProperty[] properties)
{
Flags.VerifyCollectionView();
for (int n = 0; n < properties.Length; n++)
{
if (args.PropertyName == properties[n].PropertyName)
Expand All @@ -34,6 +36,7 @@ public class CarouselView : ItemsView
{
public CarouselView()
{
Flags.VerifyCollectionView(constructorHint: nameof(CarouselView));
ItemsLayout = new ListItemsLayout(ItemsLayoutOrientation.Horizontal)
{
SnapPointsType = SnapPointsType.MandatorySingle,
Expand All @@ -44,6 +47,11 @@ public CarouselView()

public class ItemsView : View
{
protected internal ItemsView()
{
Flags.VerifyCollectionView(constructorHint: nameof(ItemsView));
}

// TODO hartez 2018/06/24 11:37:00 Give DisplayMemberPath some thought

public static readonly BindableProperty EmptyViewProperty =
Expand Down
4 changes: 4 additions & 0 deletions Xamarin.Forms.Core/Items/ScrollToRequestEventArgs.cs
Expand Up @@ -18,6 +18,8 @@ public class ScrollToRequestEventArgs : EventArgs
public ScrollToRequestEventArgs(int index, int groupIndex,
ScrollToPosition scrollToPosition, bool isAnimated)
{
Flags.VerifyCollectionView(nameof(ScrollToRequestEventArgs));

Mode = ScrollToMode.Position;

Index = index;
Expand All @@ -29,6 +31,8 @@ public class ScrollToRequestEventArgs : EventArgs
public ScrollToRequestEventArgs(object item, object group,
ScrollToPosition scrollToPosition, bool isAnimated)
{
Flags.VerifyCollectionView(nameof(ScrollToRequestEventArgs));

Mode = ScrollToMode.Element;

Item = item;
Expand Down
Expand Up @@ -10,13 +10,6 @@ public class CarouselViewRenderer : ItemsViewRenderer

public CarouselViewRenderer(Context context) : base(context)
{
if (!Forms.Flags.Contains(Flags.CollectionViewExperimental))
{
var collectionViewFlagError =
$"To use CarouselView on this platform, you must opt-in by calling "
+ $"Forms.SetFlags(\"{Flags.CollectionViewExperimental}\") before Forms.Init().";
throw new InvalidOperationException(collectionViewFlagError);
}
}

protected override void UpdateItemsSource()
Expand Down
Expand Up @@ -32,14 +32,6 @@ public class ItemsViewRenderer : RecyclerView, IVisualElementRenderer, IEffectCo

public ItemsViewRenderer(Context context) : base(context)
{
if (!Forms.Flags.Contains(Flags.CollectionViewExperimental))
{
var collectionViewFlagError =
$"To use CollectionView on this platform, you must opt-in by calling "
+ $"Forms.SetFlags(\"{Flags.CollectionViewExperimental}\") before Forms.Init().";
throw new InvalidOperationException(collectionViewFlagError);
}

_automationPropertiesProvider = new AutomationPropertiesProvider(this);
_effectControlProvider = new EffectControlProvider(this);
}
Expand Down
1 change: 0 additions & 1 deletion Xamarin.Forms.Platform.Android/Flags.cs
Expand Up @@ -3,6 +3,5 @@ namespace Xamarin.Forms
internal static class Flags
{
internal const string FastRenderersExperimental = "FastRenderers_Experimental";
internal const string CollectionViewExperimental = "CollectionView_Experimental";
}
}
11 changes: 0 additions & 11 deletions Xamarin.Forms.Platform.UAP/CollectionViewRenderer.cs
Expand Up @@ -21,17 +21,6 @@ public class CollectionViewRenderer : ViewRenderer<CollectionView, ItemsControl>

protected ItemsControl ItemsControl { get; private set; }

public CollectionViewRenderer()
{
if (!Forms.Flags.Contains(Flags.CollectionViewExperimental))
{
var collectionViewFlagError =
$"To use CollectionView on this platform, you must opt-in by calling "
+ $"Forms.SetFlags(\"{Flags.CollectionViewExperimental}\") before Forms.Init().";
throw new InvalidOperationException(collectionViewFlagError);
}
}

protected override void OnElementChanged(ElementChangedEventArgs<CollectionView> args)
{
base.OnElementChanged(args);
Expand Down
1 change: 0 additions & 1 deletion Xamarin.Forms.Platform.UAP/Flags.cs
Expand Up @@ -2,6 +2,5 @@
{
internal static class Flags
{
internal const string CollectionViewExperimental = "CollectionView_Experimental";
}
}
Expand Up @@ -7,16 +7,6 @@ namespace Xamarin.Forms.Platform.iOS
{
public class CarouselViewRenderer
{
public CarouselViewRenderer()
{
if (!Forms.Flags.Contains(Flags.CollectionViewExperimental))
{
var collectionViewFlagError =
$"To use CarouselView on this platform, you must opt-in by calling "
+ $"Forms.SetFlags(\"{Flags.CollectionViewExperimental}\") before Forms.Init().";
throw new InvalidOperationException(collectionViewFlagError);
}
}
}

// TODO hartez 2018/05/30 08:58:42 This follows the same basic scheme as RecyclerView.Adapter; you should be able to reuse the same wrapper class for the IEnumerable
Expand All @@ -27,17 +17,6 @@ public class CollectionViewRenderer : ViewRenderer<CollectionView, UIView>
ItemsViewLayout _layout;
bool _disposed;

public CollectionViewRenderer()
{
if (!Forms.Flags.Contains(Flags.CollectionViewExperimental))
{
var collectionViewFlagError =
$"To use CollectionView on this platform, you must opt-in by calling "
+ $"Forms.SetFlags(\"{Flags.CollectionViewExperimental}\") before Forms.Init().";
throw new InvalidOperationException(collectionViewFlagError);
}
}

public override UIViewController ViewController => _collectionViewController;

public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
Expand Down
1 change: 0 additions & 1 deletion Xamarin.Forms.Platform.iOS/Flags.cs
Expand Up @@ -2,6 +2,5 @@
{
internal static class Flags
{
internal const string CollectionViewExperimental = "CollectionView_Experimental";
}
}

0 comments on commit d0c962b

Please sign in to comment.