Skip to content

Commit

Permalink
Merge branch 'main' into shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz committed Aug 12, 2021
2 parents 139350c + 02efc91 commit 12cc554
Show file tree
Hide file tree
Showing 46 changed files with 639 additions and 220 deletions.
28 changes: 12 additions & 16 deletions eng/AndroidX.targets
Original file line number Diff line number Diff line change
@@ -1,60 +1,56 @@
<Project>
<PropertyGroup>
<!-- Uncomment to use preview packages -->
<!-- <_AndroidXVersion>-net6preview03.4680155</_AndroidXVersion> -->
</PropertyGroup>
<ItemGroup>
<PackageReference
Update="Xamarin.AndroidX.AppCompat.AppCompatResources"
Version="1.2.0.7$(_AndroidXVersion)"
Version="1.3.1.1"
/>
<PackageReference
Update="Xamarin.AndroidX.Browser"
Version="1.3.0.5$(_AndroidXVersion)"
Version="1.3.0.6"
/>
<PackageReference
Update="Xamarin.AndroidX.Legacy.Support.V4"
Version="1.0.0.7$(_AndroidXVersion)"
Version="1.0.0.8"
/>
<PackageReference
Update="Xamarin.AndroidX.Lifecycle.LiveData"
Version="2.3.1$(_AndroidXVersion)"
Version="2.3.1.1"
/>
<PackageReference
Update="Xamarin.AndroidX.Navigation.UI"
Version="2.3.5$(_AndroidXVersion)"
Version="2.3.5.1"
/>
<PackageReference
Update="Xamarin.AndroidX.Navigation.Fragment"
Version="2.3.5$(_AndroidXVersion)"
Version="2.3.5.1"
/>
<PackageReference
Update="Xamarin.AndroidX.Navigation.Runtime"
Version="2.3.5$(_AndroidXVersion)"
Version="2.3.5.1"
/>
<PackageReference
Update="Xamarin.AndroidX.Navigation.Common"
Version="2.3.5$(_AndroidXVersion)"
Version="2.3.5.1"
/>
<PackageReference
Update="Xamarin.AndroidX.MediaRouter"
Version="1.2.2.1$(_AndroidXVersion)"
Version="1.2.4.1"
/>
<PackageReference
Update="Xamarin.AndroidX.Palette"
Version="1.0.0.7$(_AndroidXVersion)"
Version="1.0.0.8"
/>
<PackageReference
Update="Xamarin.AndroidX.RecyclerView"
Version="1.2.0$(_AndroidXVersion)"
Version="1.2.1.1"
/>
<PackageReference
Update="Xamarin.Build.Download"
Version="0.10.0"
/>
<PackageReference
Update="Xamarin.Google.Android.Material"
Version="1.3.0.1$(_AndroidXVersion)"
Version="1.4.0.1"
/>
<PackageReference
Update="Xamarin.AndroidX.Migration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using AndroidX.ViewPager.Widget;
using Google.Android.Material.BottomNavigation;
using Google.Android.Material.BottomSheet;
using Google.Android.Material.Navigation;
using Google.Android.Material.Tabs;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Platform;
Expand All @@ -29,7 +30,7 @@ public class TabbedPageRenderer : VisualElementRenderer<TabbedPage>,
#pragma warning disable CS0618 // Type or member is obsolete
TabLayout.IOnTabSelectedListener,
#pragma warning restore CS0618 // Type or member is obsolete
ViewPager.IOnPageChangeListener, IManageFragments, BottomNavigationView.IOnNavigationItemSelectedListener
ViewPager.IOnPageChangeListener, IManageFragments, NavigationBarView.IOnItemSelectedListener
{
Drawable _backgroundDrawable;
Drawable _wrappedBackgroundDrawable;
Expand Down Expand Up @@ -193,7 +194,7 @@ protected override void Dispose(bool disposing)

if (_bottomNavigationView != null)
{
_bottomNavigationView.SetOnNavigationItemSelectedListener(null);
_bottomNavigationView.SetOnItemSelectedListener(null);
_bottomNavigationView.Dispose();
_bottomNavigationView = null;
}
Expand Down Expand Up @@ -262,7 +263,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
if (_bottomNavigationView != null)
{
_relativeLayout.RemoveView(_bottomNavigationView);
_bottomNavigationView.SetOnNavigationItemSelectedListener(null);
_bottomNavigationView.SetOnItemSelectedListener(null);
}

var bottomNavigationViewLayoutParams = new AWidget.RelativeLayout.LayoutParams(
Expand Down Expand Up @@ -462,7 +463,7 @@ void OnChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs
else
{
SetupBottomNavigationView(e);
bottomNavigationView.SetOnNavigationItemSelectedListener(this);
bottomNavigationView.SetOnItemSelectedListener(this);
}

UpdateIgnoreContainerAreas();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal void MarkNativeSelection(object selectedItem)

for (int i = 0; i < _currentViewHolders.Count; i++)
{
if (_currentViewHolders[i].AdapterPosition == position)
if (_currentViewHolders[i].BindingAdapterPosition == position)
{
_currentViewHolders[i].IsSelected = true;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void OnClick(global::Android.Views.View view)
{
if (_isSelectionEnabled)
{
OnViewHolderClicked(AdapterPosition);
OnViewHolderClicked(BindingAdapterPosition);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Android.Widget;
using Google.Android.Material.BottomNavigation;
using Google.Android.Material.BottomSheet;
using Google.Android.Material.Navigation;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using AColor = Android.Graphics.Color;
Expand All @@ -19,16 +20,16 @@

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
{
public class ShellItemRenderer : ShellItemRendererBase, BottomNavigationView.IOnNavigationItemSelectedListener, IAppearanceObserver
public class ShellItemRenderer : ShellItemRendererBase, NavigationBarView.IOnItemSelectedListener, IAppearanceObserver
{
#region IOnNavigationItemSelectedListener
#region IOnItemSelectedListener

bool BottomNavigationView.IOnNavigationItemSelectedListener.OnNavigationItemSelected(IMenuItem item)
bool NavigationBarView.IOnItemSelectedListener.OnNavigationItemSelected(IMenuItem item)
{
return OnItemSelected(item);
}

#endregion IOnNavigationItemSelectedListener
#endregion IOnItemSelectedListener

#region IAppearanceObserver

Expand Down Expand Up @@ -65,7 +66,7 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container,
_navigationArea = _outerLayout.FindViewById<FrameLayout>(Resource.Id.bottomtab_navarea);

_bottomView.SetBackgroundColor(Colors.White.ToAndroid());
_bottomView.SetOnNavigationItemSelectedListener(this);
_bottomView.SetOnItemSelectedListener(this);

if (ShellItem == null)
throw new InvalidOperationException("Active Shell Item not set. Have you added any Shell Items to your Shell?");
Expand Down Expand Up @@ -104,7 +105,7 @@ void Destroy()

if (_bottomView != null)
{
_bottomView?.SetOnNavigationItemSelectedListener(null);
_bottomView?.SetOnItemSelectedListener(null);
_bottomView?.Background?.Dispose();
_bottomView?.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using Shapes = Microsoft.Maui.Controls.Shapes;

namespace Maui.Controls.Sample.Pages
{
public class LayoutUpdatesPage : Base.BasePage
{
public LayoutUpdatesPage()
{
var root = new GridLayout() { Margin = 40, BackgroundColor = Colors.Beige };

root.RowDefinitions = new RowDefinitionCollection()
{
new RowDefinition(){ Height = GridLength.Auto },
new RowDefinition(){ Height = GridLength.Auto },
new RowDefinition(){ Height = GridLength.Auto },
new RowDefinition(){ Height = GridLength.Auto }
};

root.ColumnDefinitions = new ColumnDefinitionCollection()
{
new ColumnDefinition(){ Width = GridLength.Star },
new ColumnDefinition(){ Width = GridLength.Star },
};

var addButton = new Button { Text = "Add" };
root.Add(addButton);

var removeButton = new Button { Text = "Remove" };
root.Add(removeButton);
root.SetColumn(removeButton, 1);

var insertButton = new Button { Text = "Insert" };
root.Add(insertButton);
root.SetRow(insertButton, 1);

var clearButton = new Button { Text = "Clear" };
root.Add(clearButton);
root.SetColumn(clearButton, 1);
root.SetRow(clearButton, 1);

var updateButton = new Button { Text = "Update" };
root.Add(updateButton);
root.SetRow(updateButton, 2);

var stack = new VerticalStackLayout();

double shapeWidth = 200;
double shapeHeight = 80;
double overlap = -20;
double leftMarginIncrement = 20;

var r1 = new Shapes.Rectangle() { WidthRequest = shapeWidth, HeightRequest = shapeHeight, Fill = new SolidColorBrush(NextColor()), Margin = new Thickness(0, 0, 0, 0) };
var r2 = new Shapes.Rectangle() { WidthRequest = shapeWidth, HeightRequest = shapeHeight, Fill = new SolidColorBrush(NextColor()), Margin = new Thickness(leftMarginIncrement, overlap, 0, 0) };

stack.Add(r1);
stack.Add(r2);

root.Add(stack);
root.SetRow(stack, 3);
root.SetColumnSpan(stack, 2);

addButton.Clicked += (sender, args) => {
var left = leftMarginIncrement * stack.Count;
var rect = new Shapes.Rectangle() { WidthRequest = shapeWidth, HeightRequest = shapeHeight, Fill = new SolidColorBrush(NextColor()), Margin = new Thickness(left, overlap, 0, 0) };
stack.Add(rect);
};

insertButton.Clicked += (sender, args) => {
if (stack.Count < 2)
{
return;
}
var left = leftMarginIncrement * stack.Count;
var rect = new Shapes.Rectangle() { WidthRequest = shapeWidth, HeightRequest = shapeHeight, Fill = new SolidColorBrush(NextColor()), Margin = new Thickness(left, overlap, 0, 0) };
stack.Insert(1, rect);
};

clearButton.Clicked += (sender, args) => {
stack.Clear();
};

removeButton.Clicked += (sender, args) => {
if (stack.Count > 0)
{
stack.RemoveAt(stack.Count - 1);
}
};

updateButton.Clicked += (sender, args) => {
if (stack.Count > 0)
{
var left = leftMarginIncrement * stack.Count;
var rect = new Shapes.Rectangle() { WidthRequest = shapeWidth, HeightRequest = shapeHeight, Fill = new SolidColorBrush(NextColor()), Margin = new Thickness(left, overlap, 0, 0) };
stack[0] = rect;
}
};

Content = root;
}

int _colorIndex;

Color[] _colors = new Color[]
{
Colors.Red, Colors.Blue, Colors.Green, Colors.Yellow, Colors.Orange, Colors.Purple
};

Color NextColor()
{
var color = _colors[_colorIndex];

_colorIndex += 1;
if (_colorIndex >= _colors.Length)
{
_colorIndex = 0;
}

return color;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]

new SectionModel(typeof(VerticalStackLayoutPage), "VerticalStackLayout",
"A VerticalStackLayout organizes child views in a one-dimensional vertical stack."),

new SectionModel(typeof(LayoutUpdatesPage), "Layout Updates",
"Demonstrations of updating layouts"),
};
}
}
33 changes: 5 additions & 28 deletions src/Controls/src/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,56 +63,33 @@ public IAppLinks AppLinks

public static Application Current { get; set; }

Page _pendingMainPage;

public Page MainPage
{
get
{
if (Windows.Count == 0)
return null;
return _pendingMainPage;

return Windows[0].Page;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));

if (MainPage == value)
return;

OnPropertyChanging();

var previousPage = MainPage;

if (previousPage != null)
previousPage.Parent = null;

if (Windows.Count == 0)
{
// there are no windows, so add a new window

AddWindow(new Window(value));
_pendingMainPage = value;
}
else
{
// find the best window and replace the page

var theWindow = Windows[0];
foreach (var window in Windows)
{
if (window.Page == previousPage)
{
theWindow = window;
break;
}
}

theWindow.Page = value;
Windows[0].Page = value;
}

if (previousPage != null)
previousPage.NavigationProxy.Inner = NavigationProxy;

OnPropertyChanged();
}
}
Expand Down
Loading

0 comments on commit 12cc554

Please sign in to comment.