Skip to content

Commit

Permalink
Merge pull request #18539 from ramezgerges/navview_android_tapped
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund authored Nov 5, 2024
2 parents 9bf4050 + 7b05674 commit 809d7fa
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -3570,6 +3570,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\NavigationViewTests\NavigationView_Tapped.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Pivot\PivotSimpleTest.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -9150,6 +9154,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\NavigationViewTests\NavigationView_TopNavigation.xaml.cs">
<DependentUpon>NavigationView_TopNavigation.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\NavigationViewTests\NavigationView_Tapped.xaml.cs">
<DependentUpon>NavigationView_Tapped.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_DataContext_Propagation.xaml.cs">
<DependentUpon>ListView_DataContext_Propagation.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<UserControl
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.NavigationViewTests.NavigationView_Tapped"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxcontrols="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<muxcontrols:NavigationView PaneDisplayMode="LeftCompact">
<muxcontrols:NavigationView.MenuItems>
<muxcontrols:NavigationViewItem Content="Item 1">
<muxcontrols:NavigationViewItem.MenuItems>
<muxcontrols:NavigationViewItem Content="Item 1.1" />
</muxcontrols:NavigationViewItem.MenuItems>
</muxcontrols:NavigationViewItem>
</muxcontrols:NavigationView.MenuItems>
<TextBlock>
Manual test for <Hyperlink>https://github.com/unoplatform/uno/issues/18024</Hyperlink>
<LineBreak/>
Test steps:
<LineBreak/>
1. Press the hamburger menu on the left. A pane is supposed to open up (or expand).
<LineBreak/>
2. Press the "Item 1" item in the pane. A new "Item 1.1" item should appear.
<LineBreak/>
3. Press the "Item 1.1" item in the pane. The pane is supposed to collapse. (IMPORTANT) No popups or tooltips should be visible.
</TextBlock>
</muxcontrols:NavigationView>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Uno.UI.Samples.Controls;
using Microsoft.UI.Xaml.Controls;

namespace UITests.Shared.Windows_UI_Xaml_Controls.NavigationViewTests
{
[SampleControlInfo("NavigationView", nameof(NavigationView_Tapped), IsManualTest = true)]
public sealed partial class NavigationView_Tapped : UserControl
{
public NavigationView_Tapped()
{
this.InitializeComponent();
}
}
}
18 changes: 18 additions & 0 deletions src/Uno.UI/UI/Xaml/Input/PointerRoutedEventArgs.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ partial class PointerRoutedEventArgs
private const int _pointerIdsCount = (int)MotionEventActions.PointerIndexMask >> (int)MotionEventActions.PointerIndexShift; // 0xff
private const int _pointerIdsShift = 31 - (int)MotionEventActions.PointerIndexShift; // 23

// _lastNativeEvent.lastArgs is not necessary equal to LastPointerEvent. _lastNativeEvent.lastArgs is
// the last PointerRoutedEventArgs that was created as part of the native bubbling of _lastNativeEvent.nativeEvent.
// In other words, if a PointerRoutedEventArgs was created in managed (using the parameterless constructor),
// then _lastNativeEvent.lastArgs and LastPointerEvent will diverge.
private static (MotionEvent nativeEvent, PointerRoutedEventArgs lastArgs)? _lastNativeEvent;

private readonly MotionEvent _nativeEvent;
private readonly int _pointerIndex;
private readonly UIElement _receiver;
Expand Down Expand Up @@ -72,6 +78,18 @@ internal PointerRoutedEventArgs(MotionEvent nativeEvent, int pointerIndex, UIEle
KeyModifiers = keys;
OriginalSource = originalSource;

// On platforms with managed pointers, we reuse the same PointerRoutedEventArgs instance
// as we bubble up the event in the visual tree. On Android, the event bubbling is done
// natively and we create a corresponding (new) managed PointerRoutedEventArgs instance
// for each element up the tree. This means that parents won't see modifications in the
// PointerRoutedEventArgs instance that were done by the children. We have to detect
// this and copy the relevant fields ourselves.
if (_lastNativeEvent?.nativeEvent == nativeEvent)
{
GestureEventsAlreadyRaised = _lastNativeEvent.Value.lastArgs.GestureEventsAlreadyRaised;
}
_lastNativeEvent = (nativeEvent, this);

var inputManager = VisualTree.GetContentRootForElement(originalSource)?.InputManager;
if (inputManager is not null)
{
Expand Down

0 comments on commit 809d7fa

Please sign in to comment.