Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2ce285c
Fix InputTransparent and CascadeInputTransparent
mattleibow Apr 29, 2023
1895907
Adding some tests for the baseline
mattleibow Apr 29, 2023
86bf05d
Merge branch 'dev/input-transparent' into dev/input-transparency
mattleibow Apr 29, 2023
802dc6e
This works better
mattleibow Apr 30, 2023
063147c
Fix this
mattleibow May 1, 2023
77de113
Also these platforms
mattleibow May 1, 2023
1224014
Support compatibility
mattleibow May 1, 2023
36691d5
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 1, 2023
172a95e
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 2, 2023
61fa09f
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 2, 2023
36aca2b
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 2, 2023
c69dabd
Improved the sample for testing
mattleibow May 2, 2023
454de2f
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 3, 2023
f83b9f8
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 4, 2023
9609697
See what this does
mattleibow May 4, 2023
38213d6
Revert "See what this does"
mattleibow May 4, 2023
d695531
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 5, 2023
e5ac916
comment out new tests
mattleibow May 5, 2023
27366b9
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 9, 2023
31bfb34
Try reverting these
mattleibow May 9, 2023
c7887a7
Revert "Try reverting these"
mattleibow May 9, 2023
5a6b8f0
Revert the bad code hacks
mattleibow May 9, 2023
944f048
This should work!
mattleibow May 10, 2023
c1705c6
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 10, 2023
8572262
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 12, 2023
bb9adac
Skip the failing test for now
mattleibow May 12, 2023
572a2a4
this is no longer needed
mattleibow May 12, 2023
2ed88fe
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow May 30, 2023
5cdd77f
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow Jun 13, 2023
19eb385
Merge branch 'random' into dev/input-transparency
mattleibow Jun 27, 2023
9db3e96
Merge branch 'random3' into dev/input-transparency
mattleibow Jun 27, 2023
2fde244
Merge branch 'rand4' into dev/input-transparency
mattleibow Jun 27, 2023
41226bb
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow Jun 27, 2023
5634de3
removed as it is not needed
mattleibow Jun 27, 2023
6f66935
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow Jun 27, 2023
b3c4cf6
Merge remote-tracking branch 'origin/main' into dev/input-transparency
mattleibow Jun 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,100 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.InputTransparentPage">
<ContentPage.Resources>
<ResourceDictionary>

<ContentPage.Resources>
<ResourceDictionary>
<Style TargetType="Label">
</Style>

<Style TargetType="Button">
<!-- <Setter Property="Padding" Value="14,10" /> -->
<!-- <Setter Property="WidthRequest" Value="200"/> -->
<!-- <Setter Property="WidthRequest" Value="200"/> -->
</Style>
</ResourceDictionary>
</ContentPage.Resources>

<ContentPage.Content>
<ScrollView>
<VerticalStackLayout>
<Label Text="This Button has InputTransparent=false; it should be clickable."/>
<Button Text="Clickable" Clicked="ClickSuccess" HorizontalOptions="Center" />

<Label Margin="0,10,0,0" Text="This Button has InputTransparent=true; it should not be clickable."/>
<Button InputTransparent="True" Text="Not Clickable" Clicked="ClickFail" HorizontalOptions="Center" />

<Grid Margin="0,10,0,0" RowDefinitions="Auto, Auto">

<Label Text="This Button has InputTransparent=true; it should not be clickable. But the button hidden under it should be."/>

<Button Grid.Row="1" Margin="2,2,0,0" InputTransparent="False" Text="Clickable" Clicked="ClickSuccess"
HorizontalOptions="Center" />

<Button BackgroundColor="LightBlue" Grid.Row="1" InputTransparent="True" Text="Not Clickable" Clicked="ClickFail"
HorizontalOptions="Center"/>

</Grid>

<Label Margin="0,10,0,0" Text="The Grid below has controls and an overlay layer with more controls."/>

<Grid>

<Grid Margin="10" HeightRequest="100" BackgroundColor="LightBlue">
<Button Text="Bottom Layer" Clicked="ClickSuccess" HorizontalOptions="Center" VerticalOptions="Center" />
</Grid>

<Grid HorizontalOptions="Fill" VerticalOptions="Fill" InputTransparent="True" CascadeInputTransparent="False">
<Button Text="Overlay BR" Clicked="ClickSuccess" HorizontalOptions="End" VerticalOptions="End" Margin="5" />
<Button Text="Overlay TL" Clicked="ClickSuccess" HorizontalOptions="Start" VerticalOptions="Start" Margin="5" />
</Grid>

</Grid>

<Label Margin="0,10,0,0" Text="The Grid below has controls an overlay with CascadeInputTransparent set to true; the overlay buttons should not be usable."/>

<Grid>

<Grid Margin="10" HeightRequest="100" BackgroundColor="LightBlue">
<Button Text="Bottom Layer" Clicked="ClickSuccess" HorizontalOptions="Center" VerticalOptions="Center" />
</Grid>

<Grid HorizontalOptions="Fill" VerticalOptions="Fill" InputTransparent="True" CascadeInputTransparent="True">
<Button Text="Overlay BR" Clicked="ClickFail" HorizontalOptions="End" VerticalOptions="End" Margin="5" />
<Button Text="Overlay TL" Clicked="ClickFail" HorizontalOptions="Start" VerticalOptions="Start" Margin="5" />
</Grid>

</Grid>

</VerticalStackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage.Resources>

<ScrollView>
<VerticalStackLayout>
<Label Text="This Button has InputTransparent=false; it should be clickable."/>
<Button Text="Clickable" Clicked="ClickSuccess" HorizontalOptions="Center" />

<Label Margin="0,10,0,0" Text="This Button has InputTransparent=true; it should not be clickable."/>
<Button InputTransparent="True" Text="Not Clickable" Clicked="ClickFail" HorizontalOptions="Center" />

<Label Margin="0,10,0,0" Text="This Button has InputTransparent=true; it should not be clickable. But the button hidden under it should be."/>
<Grid RowDefinitions="Auto" ColumnDefinitions="Auto">

<Button InputTransparent="False" Text="Clickable" Clicked="ClickSuccess" Grid.Row="1" Margin="2,2,0,0" HorizontalOptions="Center" />

<Button InputTransparent="True" Text="Not Clickable" Clicked="ClickFail" BackgroundColor="LightBlue" Grid.Row="1" HorizontalOptions="Center" />

</Grid>

<Label Margin="0,10,0,0" Text="The Grid below has controls and an overlay layer with more controls."/>
<Grid>

<Grid Margin="10" HeightRequest="100" BackgroundColor="LightBlue">
<Button Text="Bottom Layer" Clicked="ClickSuccess" HorizontalOptions="Center" VerticalOptions="Center" />
</Grid>

<Grid InputTransparent="True" CascadeInputTransparent="False" HorizontalOptions="Fill" VerticalOptions="Fill">
<Button Text="Overlay BR" Clicked="ClickSuccess" HorizontalOptions="End" VerticalOptions="End" Margin="5" />
<Button Text="Overlay TL" Clicked="ClickSuccess" HorizontalOptions="Start" VerticalOptions="Start" Margin="5" />
</Grid>

</Grid>

<Label Margin="0,10,0,0" Text="The Grid below has controls an overlay with CascadeInputTransparent set to true; the overlay buttons should not be usable."/>
<Grid>

<Grid Margin="10" HeightRequest="100" BackgroundColor="LightBlue">
<Button Text="Bottom Layer" Clicked="ClickSuccess" HorizontalOptions="Center" VerticalOptions="Center" />
</Grid>

<Grid HorizontalOptions="Fill" VerticalOptions="Fill" InputTransparent="True" CascadeInputTransparent="True">
<Button Text="Overlay BR" Clicked="ClickFail" HorizontalOptions="End" VerticalOptions="End" Margin="5" />
<Button Text="Overlay TL" Clicked="ClickFail" HorizontalOptions="Start" VerticalOptions="Start" Margin="5" />
</Grid>

</Grid>

<Label Margin="0,10,0,0" Text="The Grid below has a 'Test Button' that is controlled by the switches."/>
<VerticalStackLayout>

<Grid Margin="10" HeightRequest="100" BackgroundColor="LightBlue">

<Grid x:Name="rootLayout">
<Grid x:Name="nestedLayout">
<Button x:Name="testButton" Text="Test Button" Clicked="ClickSuccess" HorizontalOptions="Center" VerticalOptions="Center" />
</Grid>
</Grid>
</Grid>

<Grid ColumnDefinitions="Auto,Auto,Auto,Auto,Auto,2" RowDefinitions="Auto,Auto,Auto" ColumnSpacing="12" RowSpacing="6" Margin="10,0,10,0">
<!-- root -->
<Label Grid.Row="0" Grid.Column="0" Text="Root" VerticalOptions="Center" FontAttributes="Bold" />
<Label Grid.Row="0" Grid.Column="1" Text="Transparent" VerticalOptions="Center" />
<Switch Grid.Row="0" Grid.Column="2" IsToggled="{Binding InputTransparent, Source={Reference rootLayout}, Mode=OneWayToSource}" VerticalOptions="Center" />
<Label Grid.Row="0" Grid.Column="3" Text="Cascade" VerticalOptions="Center" />
<Switch Grid.Row="0" Grid.Column="4" IsToggled="{Binding CascadeInputTransparent, Source={Reference rootLayout}, Mode=OneWayToSource}" VerticalOptions="Center" />
<BoxView Grid.Row="0" Grid.Column="5" Color="Green" WidthRequest="2" HorizontalOptions="End" IsVisible="{Binding InputTransparent, Source={Reference rootLayout}, Mode=OneWay}" />
<!-- nested -->
<Label Grid.Row="1" Grid.Column="0" Text="Nested" VerticalOptions="Center" FontAttributes="Bold" />
<Label Grid.Row="1" Grid.Column="1" Text="Transparent" VerticalOptions="Center" />
<Switch Grid.Row="1" Grid.Column="2" IsToggled="{Binding InputTransparent, Source={Reference nestedLayout}, Mode=OneWayToSource}" VerticalOptions="Center" />
<Label Grid.Row="1" Grid.Column="3" Text="Cascade" VerticalOptions="Center" />
<Switch Grid.Row="1" Grid.Column="4" IsToggled="{Binding CascadeInputTransparent, Source={Reference nestedLayout}, Mode=OneWayToSource}" VerticalOptions="Center" />
<BoxView Grid.Row="1" Grid.Column="5" Color="Green" WidthRequest="2" HorizontalOptions="End" IsVisible="{Binding InputTransparent, Source={Reference nestedLayout}, Mode=OneWay}" />
<!-- button -->
<Label Grid.Row="2" Grid.Column="0" Text="Button" VerticalOptions="Center" FontAttributes="Bold" />
<Label Grid.Row="2" Grid.Column="1" Text="Transparent" VerticalOptions="Center" />
<Switch Grid.Row="2" Grid.Column="2" IsToggled="{Binding InputTransparent, Source={Reference testButton}, Mode=OneWayToSource}" VerticalOptions="Center" />
<BoxView Grid.Row="2" Grid.Column="5" Color="Green" WidthRequest="2" HorizontalOptions="End" IsVisible="{Binding InputTransparent, Source={Reference testButton}, Mode=OneWay}" />
</Grid>

</VerticalStackLayout>

</VerticalStackLayout>
</ScrollView>

</ContentPage>
14 changes: 14 additions & 0 deletions src/Controls/src/Core/IInputTransparentContainerElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#nullable disable

namespace Microsoft.Maui.Controls
{
// There are 2 Layout types: Controls and Compatibility
interface IInputTransparentContainerElement
{
bool InputTransparent { get; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you include inline comments here?


bool CascadeInputTransparent { get; }

Element Parent { get; }
}
}
15 changes: 13 additions & 2 deletions src/Controls/src/Core/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Size ILayoutManager.ArrangeChildren(Rect bounds)
}
}

public abstract class Layout : View, ILayout, ILayoutController, IPaddingElement, IView, IVisualTreeElement
public abstract class Layout : View, ILayout, ILayoutController, IPaddingElement, IView, IVisualTreeElement, IInputTransparentContainerElement
{
/// <summary>Bindable property for <see cref="IsClippedToBounds"/>.</summary>
public static readonly BindableProperty IsClippedToBoundsProperty =
Expand All @@ -72,7 +72,8 @@ public abstract class Layout : View, ILayout, ILayoutController, IPaddingElement

/// <summary>Bindable property for <see cref="CascadeInputTransparent"/>.</summary>
public static readonly BindableProperty CascadeInputTransparentProperty =
BindableProperty.Create(nameof(CascadeInputTransparent), typeof(bool), typeof(Layout), true);
BindableProperty.Create(nameof(CascadeInputTransparent), typeof(bool), typeof(Layout), true,
propertyChanged: OnCascadeInputTransparentPropertyChanged);

/// <summary>Bindable property for <see cref="Padding"/>.</summary>
public static readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty;
Expand Down Expand Up @@ -518,5 +519,15 @@ public Size CrossPlatformArrange(Rect bounds)

return Frame.Size;
}

static void OnCascadeInputTransparentPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
// We only need to update if the cascade changes anything, namely when InputTransparent=true.
// When InputTransparent=false, then the cascade property has no effect.
if (bindable is Layout layout && layout.InputTransparent)
{
layout.RefreshInputTransparentProperty();
}
}
}
}
27 changes: 2 additions & 25 deletions src/Controls/src/Core/Layout/Layout.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,8 @@ namespace Microsoft.Maui.Controls
{
public partial class Layout
{
public static void MapInputTransparent(LayoutHandler handler, Layout layout) =>
UpdateInputTransparent(handler, layout);
public static void MapInputTransparent(LayoutHandler handler, Layout layout) { }

public static void MapInputTransparent(ILayoutHandler handler, Layout layout) =>
UpdateInputTransparent(handler, layout);

static void MapInputTransparent(IViewHandler handler, IView layout) =>
UpdateInputTransparent(handler, layout);

static void UpdateInputTransparent(IViewHandler handler, IView layout)
{
if (handler is ILayoutHandler layoutHandler && layout is Layout controlsLayout)
{
if (layoutHandler.PlatformView is LayoutViewGroup layoutViewGroup)
{
// Handle input transparent for this view
layoutViewGroup.InputTransparent = layout.InputTransparent;
}

controlsLayout.UpdateDescendantInputTransparent();
}
else
{
ControlsVisualElementMapper.UpdateProperty(handler, layout, nameof(IView.InputTransparent));
}
}
public static void MapInputTransparent(ILayoutHandler handler, Layout layout) { }
}
}
2 changes: 0 additions & 2 deletions src/Controls/src/Core/Layout/Layout.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public abstract partial class Layout

public static IPropertyMapper<IView, IViewHandler> ControlsLayoutMapper = new PropertyMapper<IView, IViewHandler>(ControlsVisualElementMapper)
{
[nameof(CascadeInputTransparent)] = MapInputTransparent,
[nameof(IView.InputTransparent)] = MapInputTransparent,
};
}
}
32 changes: 2 additions & 30 deletions src/Controls/src/Core/Layout/Layout.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,8 @@ namespace Microsoft.Maui.Controls
{
public partial class Layout
{
public static void MapInputTransparent(LayoutHandler handler, Layout layout) =>
UpdateInputTransparent(handler, layout);
public static void MapInputTransparent(LayoutHandler handler, Layout layout) { }

public static void MapInputTransparent(ILayoutHandler handler, Layout layout) =>
UpdateInputTransparent(handler, layout);

static void MapInputTransparent(IViewHandler handler, IView layout) =>
UpdateInputTransparent(handler, layout);

static void UpdateInputTransparent(IViewHandler handler, IView view)
{
if (handler.PlatformView is not Microsoft.Maui.Platform.LayoutViewGroup platformView ||
view is not Layout layout)
{
return;
}

if (layout.CascadeInputTransparent)
{
// Sensitive property on NUI View was false, disabled all touch event including children
platformView.Sensitive = !layout.InputTransparent;
platformView.InputTransparent = false;
}
else
{
// InputTransparent property on LayoutViewGroup was false,
// Only LayoutViewGroup event was disabled but children are allowed
platformView.InputTransparent = layout.InputTransparent;
platformView.Sensitive = true;
}
}
public static void MapInputTransparent(ILayoutHandler handler, Layout layout) { }
}
}
22 changes: 2 additions & 20 deletions src/Controls/src/Core/Layout/Layout.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,8 @@ namespace Microsoft.Maui.Controls
{
public partial class Layout
{
public static void MapInputTransparent(LayoutHandler handler, Layout layout) =>
UpdateInputTransparent(handler, layout);
public static void MapInputTransparent(LayoutHandler handler, Layout layout) { }

public static void MapInputTransparent(ILayoutHandler handler, Layout layout) =>
UpdateInputTransparent(handler, layout);

static void MapInputTransparent(IViewHandler handler, IView layout) =>
UpdateInputTransparent(handler, layout);

static void UpdateInputTransparent(IViewHandler handler, IView layout)
{
if (handler is ILayoutHandler layoutHandler && layout is Layout controlsLayout)
{
layoutHandler.PlatformView?.UpdateInputTransparent(layoutHandler, controlsLayout);
controlsLayout.UpdateDescendantInputTransparent();
}
else
{
ControlsVisualElementMapper.UpdateProperty(handler, layout, nameof(IView.InputTransparent));
}
}
public static void MapInputTransparent(ILayoutHandler handler, Layout layout) { }
}
}
Loading