-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Handlers] Add IndicatorView handler for iOS and Android #2038
Merged
Merged
Changes from 18 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
5e602e9
Initial work Indicator
rmarinho de036ce
Make it build
rmarinho 6756094
Try again
rmarinho 6dc75ff
Update to a working version
rmarinho 03f7bf7
Remove commented code
rmarinho 0ddeed0
Move native control measure into OnMeasure override
hartez fee1de1
Fix IndicatorView measure without changing old method
hartez f38883a
Add spacing to new Layout
rmarinho 9934eb9
Add more examples to IndicatorView
rmarinho a607b0f
Fix IndicatorView shapes
rmarinho 166f653
Cleanup
rmarinho 6fc4cbb
Update IIndicatorView
rmarinho 6b14647
Cleanup
rmarinho 6c1141a
refactor MauiPageControl
rmarinho b935f86
Fix comments
rmarinho 327a17e
Fix sizing
rmarinho 4c60b6b
Add carouselview example cleanup startup page
rmarinho d38a6e9
Fix extra padding
rmarinho b922b20
Fix net6 sln null
rmarinho d8f7332
Fix WINUI indicator
rmarinho fb70992
Merge branch 'main' into indicator-handler
rmarinho b60150d
Merge branch 'main' into indicator-handler
rmarinho 44a4f47
Merge branch 'main' into indicator-handler
rmarinho 4f0889a
Merge branch 'main' into indicator-handler
rmarinho 946a1b6
Use IShape
rmarinho 2c61e72
Fix namespace
rmarinho 6e964fa
Add comments to IIndicatorVIew interface
rmarinho 2aa3048
Merge branch 'main' into indicator-handler
rmarinho 67c5e8b
Merge branch 'main' into indicator-handler
rmarinho 46a1d2e
Add Default size
rmarinho abf8087
[iOS] Some refactor indicatorview iOS
rmarinho 5cc03ea
Remove shapes interfaces
rmarinho 601890f
Use extensions methods for Maximum visible and IsCirceShape
rmarinho 2425196
Use extension method.
rmarinho 786d9f9
try fix extra sizing code
rmarinho 876893b
Remove comment code
rmarinho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
38 changes: 0 additions & 38 deletions
38
src/Controls/samples/Controls.Sample/Pages/Compatibility/IndicatorViewPage.xaml
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/Controls/samples/Controls.Sample/Pages/Compatibility/IndicatorViewPage.xaml.cs
This file was deleted.
Oops, something went wrong.
128 changes: 128 additions & 0 deletions
128
src/Controls/samples/Controls.Sample/Pages/Controls/IndicatorPage.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,128 @@ | ||
<views:BasePage | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Pages.IndicatorPage" | ||
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base" | ||
Title="IndicatorView"> | ||
<views:BasePage.Resources> | ||
<Style x:Key="IndicatorLabelStyle" | ||
TargetType="Label"> | ||
<Setter Property="VisualStateManager.VisualStateGroups"> | ||
<VisualStateGroupList> | ||
<VisualStateGroup x:Name="CommonStates"> | ||
<VisualState x:Name="Normal"> | ||
<VisualState.Setters> | ||
<Setter Property="TextColor" | ||
Value="LightGray" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
<VisualState x:Name="Selected"> | ||
<VisualState.Setters> | ||
<Setter Property="TextColor" | ||
Value="Black" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
</VisualStateGroupList> | ||
</Setter> | ||
</Style> | ||
</views:BasePage.Resources> | ||
<views:BasePage.Content> | ||
<Grid Margin="12"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition/> | ||
<ColumnDefinition/> | ||
</Grid.ColumnDefinitions> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="50"/> | ||
<RowDefinition Height="50"/> | ||
<RowDefinition Height="50"/> | ||
<RowDefinition Height="50"/> | ||
<RowDefinition Height="50"/> | ||
<RowDefinition Height="50"/> | ||
<RowDefinition Height="50"/> | ||
<RowDefinition Height="*"/> | ||
</Grid.RowDefinitions> | ||
<Label | ||
Text="Basic" | ||
Style="{StaticResource Headline}"/> | ||
<IndicatorView Grid.Column="1" | ||
Count="5" | ||
Position="2" | ||
HorizontalOptions="Center" /> | ||
<Label | ||
Grid.Row="1" | ||
Text="Colors" | ||
Style="{StaticResource Headline}"/> | ||
<IndicatorView Grid.Row="1" GridLayout.Column="1" Count="5" Position="2" HorizontalOptions="Center" SelectedIndicatorColor="Red" IndicatorColor="Blue" Background="Yellow" /> | ||
<Label | ||
Grid.Row="2" | ||
Text="Indicator Shape" | ||
Style="{StaticResource Headline}"/> | ||
<IndicatorView Grid.Row="2" GridLayout.Column="1" Count="5" Position="2" HorizontalOptions="Center" IndicatorsShape="Square"/> | ||
<Label | ||
Grid.Row="3" | ||
Text="Indicator Size" | ||
Style="{StaticResource Headline}"/> | ||
<IndicatorView Grid.Row="3" GridLayout.Column="1" Count="5" Position="2" HorizontalOptions="Center" IndicatorSize="15"/> | ||
<Label | ||
Grid.Row="4" | ||
Text="Indicator HideSingle" | ||
Style="{StaticResource Headline}"/> | ||
<IndicatorView Grid.Row="4" GridLayout.Column="1" Count="1" HorizontalOptions="Center" HideSingle="True"/> | ||
<Label | ||
Grid.Row="5" | ||
Text="Indicator MaximumVisible - 7 of 10" | ||
Style="{StaticResource Headline}"/> | ||
<IndicatorView Grid.Row="5" GridLayout.Column="1" Count="10" Position="3" MaximumVisible="7" HorizontalOptions="Center"/> | ||
<Label | ||
Grid.Row="6" | ||
Text="Indicator Template" | ||
Style="{StaticResource Headline}"/> | ||
<IndicatorView Grid.Row="6" GridLayout.Column="1" | ||
Count="5" | ||
Position="2" | ||
IndicatorColor="Transparent" | ||
SelectedIndicatorColor="Transparent" | ||
HorizontalOptions="Center"> | ||
<IndicatorView.IndicatorTemplate> | ||
<DataTemplate> | ||
<Label Text="" FontFamily="Ionicons" Style="{StaticResource IndicatorLabelStyle}" /> | ||
</DataTemplate> | ||
</IndicatorView.IndicatorTemplate> | ||
</IndicatorView> | ||
<Label | ||
Grid.Row="7" | ||
Text="Using with CarouselView" | ||
Style="{StaticResource Headline}" VerticalOptions="Start" /> | ||
<StackLayout Grid.Row="7" Grid.Column="1" VerticalOptions="Start" > | ||
<CarouselView IndicatorView="indicatorView" VerticalOptions="Start" HeightRequest="100" Loop="False"> | ||
<CarouselView.ItemsSource> | ||
<x:Array Type="{x:Type x:String}"> | ||
<x:String>Item 1</x:String> | ||
<x:String>Item 2</x:String> | ||
<x:String>Item 3</x:String> | ||
</x:Array> | ||
</CarouselView.ItemsSource> | ||
<CarouselView.ItemTemplate> | ||
<DataTemplate> | ||
<Grid Background="Pink"> | ||
<Label | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center" | ||
FontSize="Large" | ||
Text="{Binding}"/> | ||
</Grid> | ||
</DataTemplate> | ||
</CarouselView.ItemTemplate> | ||
</CarouselView> | ||
<IndicatorView | ||
Margin="0,20,0,0" | ||
x:Name="indicatorView" | ||
IndicatorColor="LightGray" | ||
SelectedIndicatorColor="DarkGray" | ||
HorizontalOptions="Center" /> | ||
</StackLayout> | ||
</Grid> | ||
</views:BasePage.Content> | ||
</views:BasePage> |
14 changes: 14 additions & 0 deletions
14
src/Controls/samples/Controls.Sample/Pages/Controls/IndicatorPage.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,14 @@ | ||
using System; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Graphics; | ||
|
||
namespace Maui.Controls.Sample.Pages | ||
{ | ||
public partial class IndicatorPage | ||
{ | ||
public IndicatorPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
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
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
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,13 @@ | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.Maui.Graphics; | ||
|
||
namespace Microsoft.Maui.Controls | ||
{ | ||
public partial class IndicatorView : ITemplatedIndicatorView | ||
{ | ||
Paint IIndicatorView.IndicatorColor => IndicatorColor?.AsPaint(); | ||
Paint IIndicatorView.SelectedIndicatorColor => SelectedIndicatorColor?.AsPaint(); | ||
IShapeView IIndicatorView.IndicatorsShape => IndicatorsShape == Controls.IndicatorShape.Square ? new Shapes.Rectangle() : new Shapes.Ellipse(); | ||
Maui.ILayout ITemplatedIndicatorView.IndicatorsLayoutOverride => (IndicatorTemplate != null) ? IndicatorLayout as Maui.ILayout : null; | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -2,15 +2,16 @@ | |
using System.Collections; | ||
using System.Collections.Specialized; | ||
using Microsoft.Maui.Graphics; | ||
using Microsoft.Maui.Layouts; | ||
|
||
namespace Microsoft.Maui.Controls | ||
{ | ||
[ContentProperty(nameof(IndicatorLayout))] | ||
public class IndicatorView : TemplatedView | ||
public partial class IndicatorView : TemplatedView | ||
{ | ||
const int DefaultPadding = 4; | ||
|
||
public static readonly BindableProperty IndicatorsShapeProperty = BindableProperty.Create(nameof(IndicatorsShape), typeof(IndicatorShape), typeof(IndicatorView), IndicatorShape.Circle); | ||
public static readonly BindableProperty IndicatorsShapeProperty = BindableProperty.Create(nameof(IndicatorsShape), typeof(IndicatorShape), typeof(IndicatorView), Controls.IndicatorShape.Circle); | ||
|
||
public static readonly BindableProperty PositionProperty = BindableProperty.Create(nameof(Position), typeof(int), typeof(IndicatorView), default(int), BindingMode.TwoWay); | ||
|
||
|
@@ -25,9 +26,9 @@ public class IndicatorView : TemplatedView | |
|
||
public static readonly BindableProperty HideSingleProperty = BindableProperty.Create(nameof(HideSingle), typeof(bool), typeof(IndicatorView), true); | ||
|
||
public static readonly BindableProperty IndicatorColorProperty = BindableProperty.Create(nameof(IndicatorColor), typeof(Color), typeof(IndicatorView), null); | ||
public static readonly BindableProperty IndicatorColorProperty = BindableProperty.Create(nameof(IndicatorColor), typeof(Color), typeof(IndicatorView), Colors.LightGrey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding default colors |
||
|
||
public static readonly BindableProperty SelectedIndicatorColorProperty = BindableProperty.Create(nameof(SelectedIndicatorColor), typeof(Color), typeof(IndicatorView), null); | ||
public static readonly BindableProperty SelectedIndicatorColorProperty = BindableProperty.Create(nameof(SelectedIndicatorColor), typeof(Color), typeof(IndicatorView), Colors.Black); | ||
|
||
public static readonly BindableProperty IndicatorSizeProperty = BindableProperty.Create(nameof(IndicatorSize), typeof(double), typeof(IndicatorView), 6.0); | ||
|
||
|
@@ -107,25 +108,51 @@ public IEnumerable ItemsSource | |
set => SetValue(ItemsSourceProperty, value); | ||
} | ||
|
||
|
||
protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint) | ||
{ | ||
var baseRequest = base.OnMeasure(widthConstraint, heightConstraint); | ||
|
||
if (IndicatorTemplate != null) | ||
return baseRequest; | ||
|
||
var defaultSize = IndicatorSize + DefaultPadding + DefaultPadding + 1; | ||
var items = Count; | ||
var padding = DefaultPadding; | ||
#if __IOS__ | ||
padding += 7; | ||
mattleibow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#endif | ||
var defaultSize = IndicatorSize + padding + padding; | ||
var items = GetMaximumVisible(); | ||
|
||
var sizeRequest = new SizeRequest(new Size(items * defaultSize, IndicatorSize), new Size(10, 10)); | ||
rmarinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return sizeRequest; | ||
} | ||
|
||
protected override Size MeasureOverride(double widthConstraint, double heightConstraint) | ||
{ | ||
var margin = Margin; | ||
|
||
// Adjust the constraints to account for the margins | ||
widthConstraint -= margin.HorizontalThickness; | ||
heightConstraint -= margin.VerticalThickness; | ||
|
||
// Use the old measurement override to figure out the xplat size | ||
var measure = OnMeasure(widthConstraint, heightConstraint).Request; | ||
rmarinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Make sure the native control gets measured | ||
var nativeMeasure = Handler?.GetDesiredSize(measure.Width, measure.Height); | ||
|
||
// Account for the margins when reporting the desired size value | ||
DesiredSize = new Size(measure.Width + margin.HorizontalThickness, | ||
measure.Height + margin.VerticalThickness); | ||
|
||
return DesiredSize; | ||
} | ||
|
||
static void UpdateIndicatorLayout(IndicatorView indicatorView, object newValue) | ||
{ | ||
if (newValue != null) | ||
{ | ||
indicatorView.IndicatorLayout = new IndicatorStackLayout(indicatorView); | ||
indicatorView.IndicatorLayout = new IndicatorStackLayout(indicatorView) { Spacing = DefaultPadding }; | ||
} | ||
else if (indicatorView.IndicatorLayout == null) | ||
{ | ||
|
@@ -162,5 +189,17 @@ void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) | |
} | ||
Count = count; | ||
} | ||
|
||
int GetMaximumVisible() | ||
rmarinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var minValue = Math.Min(MaximumVisible, Count); | ||
var maximumVisible = minValue <= 0 ? 0 : minValue; | ||
bool hideSingle = HideSingle; | ||
|
||
if (maximumVisible == 1 && hideSingle) | ||
maximumVisible = 0; | ||
|
||
return maximumVisible; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CarouselVIew crashes if Loop =true on Android, and doesn't show when Loop=False