Skip to content

Commit

Permalink
Move New Navigation Handler to Core and make it internal (#1800)
Browse files Browse the repository at this point in the history
* Move navhost bits to core

* - windows

* - fix IEnumerable calls

* - fix up ios

* - revert to renderer
  • Loading branch information
PureWeen committed Jul 26, 2021
1 parent c248bda commit 84e84c8
Show file tree
Hide file tree
Showing 32 changed files with 1,635 additions and 1,391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public ListViewViewModel()
new Employee ("Andrew 3", TimeSpan.FromDays (1000), 60),
};

Enumerable.Range(0, 9000).Select(e => new Employee(e.ToString(), TimeSpan.FromDays(1), 60)).ForEach(e => Employees.Add(e));
Enumerable.Range(0, 9000).Select(e => new Employee(e.ToString(), TimeSpan.FromDays(1), 60)).ToList().ForEach(e => Employees.Add(e));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ void OnPropertyChanged([CallerMemberName] string propertyName = null)
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}

public int IndexOf(Func<GroupAction, bool> selector)
{
for (int i = 0; i < this.Count; i++)
{
if (selector(this[i]))
return i;
}

return -1;
}
}

class GroupAction
Expand Down Expand Up @@ -139,11 +150,25 @@ public Group Parent
})
};

readonly ObservableList<Group> _groups;
readonly GroupObservableList _groups;

class GroupObservableList : ObservableList<Group>
{
public int IndexOf(Func<Group, bool> selector)
{
for (int i = 0; i < this.Count; i++)
{
if (selector(this[i]))
return i;
}

return -1;
}
}

ObservableList<Group> CreateItemSource()
GroupObservableList CreateItemSource()
{
return new ObservableList<Group> {
return new GroupObservableList {
new Group ("General") {
new GroupAction ("Change group name", ga => ga.Parent.Name += " (changed)"),
new GroupAction ("Change group short name", ga => ga.Parent.ShortName = ga.Parent.Name[1].ToString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MapGallery()
InitializeComponent();

Map = MakeMap();
Map.Pins.ForEach(pin =>
Map.Pins.ToList().ForEach(pin =>
{
pin.MarkerClicked += MarkerClicked;
pin.InfoWindowClicked += InfoWindowClicked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static Layout CreateChanger(Type enumType, string defaultOption, Action<P
picker.Items.Add(option);
}

picker.SelectedIndex = options.IndexOf(defaultOption);
picker.SelectedIndex = options.ToList().IndexOf(defaultOption);

picker.SelectedIndexChanged += (sender, args) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override void Init()
AutomationId = FirstItemMark
});
Enumerable.Range(2, 50).Select(i => new Label { Text = $"Test label {i}" })
.ForEach(label => longStackLayout.Children.Add(label));
.ToList().ForEach(label => longStackLayout.Children.Add(label));

scrollView = new ScrollView
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Microsoft.Maui.Controls.CustomAttributes;
using Microsoft.Maui.Controls.Internals;
using System.Linq;

#if UITEST
using Xamarin.UITest;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void NotifyItemSelected(object item)
{

if (ItemSelected != null)
ItemSelected(this, new SelectedItemChangedEventArgs(item, Items?.IndexOf(item) ?? -1));
ItemSelected(this, new SelectedItemChangedEventArgs(item, Items?.ToList().IndexOf($"{item}") ?? -1));
}

public NativeListView()
Expand Down Expand Up @@ -337,7 +338,7 @@ public void NotifyItemSelected(object item)
{

if (ItemSelected != null)
ItemSelected(this, new SelectedItemChangedEventArgs(item, Items?.IndexOf(item) ?? -1));
ItemSelected(this, new SelectedItemChangedEventArgs(item, Items?.ToList().IndexOf((DataSource)item) ?? -1));
}

public NativeListView2()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void Init()
{
var oc = new ObservableCollection<string>(new[] { $"Click {reload}", "and this text should go away" });

Enumerable.Range(0, 100).ForEach(x => oc.Add(x.ToString()));
Enumerable.Range(0, 100).ToList().ForEach(x => oc.Add(x.ToString()));

PushAsync(new MainPageCode
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected override void Init()
Command = new Command(() =>
{
var activeImage = layout.Children.Last();
int nextIndex = imageControls.IndexOf(activeImage) + 1;
int nextIndex = imageControls.ToList().IndexOf(activeImage) + 1;
if(nextIndex >= imageControls.Length)
nextIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected override void Init()
Enumerable
.Range(0, 10)
.Select(_ => new Label() { HeightRequest = 200, Text = "Pull me down to refresh me" })
.ToList()
.ForEach(x => scrollViewContent.Children.Add(x));


Expand Down
39 changes: 0 additions & 39 deletions src/Compatibility/Core/src/iOS/Extensions/ArrayExtensions.cs

This file was deleted.

55 changes: 0 additions & 55 deletions src/Controls/src/Core/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,60 +59,5 @@ static class EnumerableExtensions
}
}
}

public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)
{
foreach (T item in enumeration)
{
action(item);
}
}

public static IDictionary<TKey, List<TSource>> GroupToDictionary<TSource, TKey>(this IEnumerable<TSource> enumeration, Func<TSource, TKey> func)
{
var result = new Dictionary<TKey, List<TSource>>();
foreach (TSource item in enumeration)
{
var group = func(item);
if (!result.ContainsKey(group))
result.Add(group, new List<TSource> { item });
else
result[group].Add(item);
}
return result;
}

public static int IndexOf<T>(this IEnumerable<T> enumerable, T item)
{
if (enumerable == null)
throw new ArgumentNullException("enumerable");

var i = 0;
foreach (T element in enumerable)
{
if (Equals(element, item))
return i;

i++;
}

return -1;
}

public static int IndexOf<T>(this IEnumerable<T> enumerable, Func<T, bool> predicate)
{
var i = 0;
foreach (T element in enumerable)
{
if (predicate(element))
return i;

i++;
}

return -1;
}

public static T Last<T>(this IList<T> self) => self[self.Count - 1];
}
}
71 changes: 70 additions & 1 deletion src/Controls/src/Core/HandlerImpl/NavigationPage.Impl.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Layouts;

namespace Microsoft.Maui.Controls
{
public partial class NavigationPage : IView
public partial class NavigationPage : INavigationView
{
Thickness IView.Margin => Thickness.Zero;

partial void Init()
{
PushRequested += (_, args) =>
{
var request = new MauiNavigationRequestedEventArgs(args.Page, args.BeforePage, args.Animated);
Handler?.Invoke(nameof(INavigationView.PushAsync), request);
};

PopRequested += (_, args) =>
{
var request = new MauiNavigationRequestedEventArgs(args.Page, args.BeforePage, args.Animated);
Handler?.Invoke(nameof(INavigationView.PopAsync), request);
};
}

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
if (Content is IFrameworkElement frameworkElement)
Expand All @@ -35,8 +52,60 @@ protected override Size ArrangeOverride(Rectangle bounds)
return Frame.Size;
}

void INavigationView.InsertPageBefore(IView page, IView before)
{
throw new NotImplementedException();
}

Task<IView> INavigationView.PopAsync() =>
(this as INavigationView).PopAsync(true);

async Task<IView> INavigationView.PopAsync(bool animated)
{
var thing = await this.PopAsync(animated);
return thing;
}

Task<IView> INavigationView.PopModalAsync()
{
throw new NotImplementedException();
}

Task<IView> INavigationView.PopModalAsync(bool animated)
{
throw new NotImplementedException();
}

Task INavigationView.PushAsync(IView page) =>
(this as INavigationView).PushAsync(page, true);

Task INavigationView.PushAsync(IView page, bool animated)
{
return this.PushAsync((Page)page, animated);
}

Task INavigationView.PushModalAsync(IView page)
{
throw new NotImplementedException();
}

Task INavigationView.PushModalAsync(IView page, bool animated)
{
throw new NotImplementedException();
}

void INavigationView.RemovePage(IView page)
{
throw new NotImplementedException();
}

IFrameworkElement Content =>
this.CurrentPage;

IReadOnlyList<IView> INavigationView.ModalStack => throw new NotImplementedException();

IReadOnlyList<IView> INavigationView.NavigationStack =>
this.Navigation.NavigationStack;
}

}
Loading

0 comments on commit 84e84c8

Please sign in to comment.