Skip to content

Commit

Permalink
[windows] Fix Updating the initial position (dotnet#23709)
Browse files Browse the repository at this point in the history
[Windows] Fix CollectionView DisconnectHandler SelectionMode Crash (dotnet#23726)

* Reorder events to prevent disconnect issues

* Add test

---------

Co-authored-by: Mike Corsaro <mikecorsaro@microsoft.com>

Use UIView.Window instead of the global window (dotnet#23693)

[Windows] Subscribe pointer events only when needed (dotnet#23515)

Fix iOS log exports (dotnet#23334)

* Fix ios Device Logging

* - fix up device test logging a bit more

* Update ui-tests-steps.yml

* Update ui-tests-steps.yml

* Update ios.cake

* Update ui-tests-steps.yml

* Update maui-templates.yml

* Update maui-templates.yml

remove code from oldFragment

add new shiny DialogFragment

refactoring code to find and dismiss DialogFragment

code cleanup

delete ModalContainer to use only ModalFragment

handle animation and add a map between page and dialogFragment

We've back button enabled!

After dismissing several demons summoned using obscure Android APIs, I was able to deal with the BackButtonPressed event

add modal animations as anim.xml files

using cleanup

remowork PopModalPlatformAsync to work with dialogFragment

remove tag

final adjustments on DialogFragment

change the ShowNow for Show to fix the issue

Wait for animation to complete

change local functions order

fix build

create window hooks for android (like iOS)

clean up ModalFragment fields

change Dictionary to ConditionalWeakTable

clean up event animation

refactor on Null notation

remove comments

- adjust back button

- different back button

code style

remove unused prop.

fix DontPushModalPagesWhenWindowIsDeactivated DeviceTest

completes the task

return back the way how modalManager handles android modals

normilize animation duration

Co-authored-by: Shane Neuville <shane94@hotmail.com>

remove focusability code

change how fragments are looked-up

code style
  • Loading branch information
rmarinho authored and pictos committed Jul 22, 2024
1 parent 69fbd4f commit 10d9bdb
Show file tree
Hide file tree
Showing 14 changed files with 384 additions and 352 deletions.
50 changes: 47 additions & 3 deletions eng/devices/ios.cake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var dotnetToolPath = GetDotnetToolPath();
Setup(context =>
{
LogSetupInfo(dotnetToolPath);
PerformCleanupIfNeeded(deviceCleanupEnabled);
PerformCleanupIfNeeded(deviceCleanupEnabled, false);

// Device or simulator setup
if (testDevice.Contains("device"))
Expand All @@ -58,7 +58,7 @@ Setup(context =>
}
});

Teardown(context => PerformCleanupIfNeeded(deviceCleanupEnabled));
Teardown(context => PerformCleanupIfNeeded(deviceCleanupEnabled, true));

Task("Cleanup");

Expand Down Expand Up @@ -307,15 +307,59 @@ void ExecuteCGLegacyUITests(string project, string appProject, string device, st

// Helper methods

void PerformCleanupIfNeeded(bool cleanupEnabled)
void PerformCleanupIfNeeded(bool cleanupEnabled, bool createDeviceLogs)
{
if (cleanupEnabled)
{
var logDirectory = GetLogDirectory();
Information("Cleaning up...");
Information("Deleting XHarness simulator if exists...");
var sims = ListAppleSimulators().Where(s => s.Name.Contains("XHarness")).ToArray();
foreach (var sim in sims)
{
if(createDeviceLogs)
{
try
{
var homeDirectory = Environment.GetEnvironmentVariable("HOME");
Information("Diagnostics Reports");
StartProcess("zip", new ProcessSettings {
Arguments = new ProcessArgumentBuilder()
.Append("-9r")
.AppendQuoted($"{logDirectory}/DiagnosticReports_{sim.UDID}.zip")
.AppendQuoted($"{homeDirectory}/Library/Logs/DiagnosticReports/"),
RedirectStandardOutput = false
});

Information("CoreSimulator");
StartProcess("zip", new ProcessSettings {
Arguments = new ProcessArgumentBuilder()
.Append("-9r")
.AppendQuoted($"{logDirectory}/CoreSimulator_{sim.UDID}.zip")
.AppendQuoted($"{homeDirectory}/Library/Logs/CoreSimulator/{sim.UDID}"),
RedirectStandardOutput = false
});

StartProcess("xcrun", $"simctl spawn {sim.UDID} log collect --output {homeDirectory}/{sim.UDID}_log.logarchive");

StartProcess("zip", new ProcessSettings {
Arguments = new ProcessArgumentBuilder()
.Append("-9r")
.AppendQuoted($"{logDirectory}/{sim.UDID}_log.logarchive.zip")
.AppendQuoted($"{homeDirectory}/{sim.UDID}_log.logarchive"),
RedirectStandardOutput = false
});

var screenshotPath = $"{testResultsPath}/{sim.UDID}_screenshot.png";
StartProcess("xcrun", $"simctl io {sim.UDID} screenshot {screenshotPath}");
}
catch(Exception ex)
{
Information($"Failed to collect logs for simulator {sim.Name} ({sim.UDID}): {ex.Message}");
Information($"Command Executed: simctl spawn {sim.UDID} log collect --output {logDirectory}/{sim.UDID}_log.logarchive");
}
}

Information($"Deleting XHarness simulator {sim.Name} ({sim.UDID})...");
StartProcess("xcrun", $"simctl shutdown {sim.UDID}");
ExecuteWithRetries(() => StartProcess("xcrun", $"simctl delete {sim.UDID}"), 3);
Expand Down
14 changes: 2 additions & 12 deletions eng/pipelines/common/device-tests-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ steps:
Write-Host "##vso[task.setvariable variable=Platform.Name]${platformName}"
displayName: 'Set Platform.Name'
- ${{ if eq(parameters.platform, 'ios')}}:
- bash: |
if [ -f "$HOME/Library/Logs/CoreSimulator/*" ]; then rm -r $HOME/Library/Logs/CoreSimulator/*; fi
if [ -f "$HOME/Library/Logs/DiagnosticReports/*" ]; then rm -r $HOME/Library/Logs/DiagnosticReports/*; fi
displayName: Delete Old Simulator Logs
condition: always()
continueOnError: true
- ${{ if eq(parameters.platform, 'windows')}}:
- pwsh: |
$errorPath = "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps"
Expand All @@ -113,10 +105,8 @@ steps:
- ${{ if eq(parameters.platform, 'ios')}}:
- bash: |
suffix=$(date +%Y%m%d%H%M%S)
zip -9r "$(LogDirectory)/CoreSimulatorLog_${suffix}.zip" "$HOME/Library/Logs/CoreSimulator/"
zip -9r "$(LogDirectory)/DiagnosticReports_${suffix}.zip" "$HOME/Library/Logs/DiagnosticReports/"
displayName: Zip Simulator Logs
pwsh ./build.ps1 --target=Cleanup -Script eng/devices/${{ parameters.platform }}.cake ---results="$(TestResultsDirectory)" ${{ parameters.cakeArgs }}
displayName: Cleanup and Create Simulator Logs if Test Run Failed To
condition: always()
continueOnError: true
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/common/device-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ stages:
clean: all
displayName: "iOS tests"
pool: ${{ parameters.iosPool }}
timeoutInMinutes: 140
timeoutInMinutes: 45
strategy:
matrix:
# create all the variables used for the matrix
Expand Down
15 changes: 2 additions & 13 deletions eng/pipelines/common/maui-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,6 @@ jobs:
DOTNET_TOKEN: $(dotnetbuilds-internal-container-read-token)
PRIVATE_BUILD: $(PrivateBuild)

- ${{ if eq(RunPlatform.testName, 'RunOniOS') }}:
- bash: |
if [ -f "$HOME/Library/Logs/CoreSimulator/*" ]; then rm -r $HOME/Library/Logs/CoreSimulator/*; fi
if [ -f "$HOME/Library/Logs/DiagnosticReports/*" ]; then rm -r $HOME/Library/Logs/DiagnosticReports/*; fi
displayName: Delete Old Simulator Logs
condition: always()
continueOnError: true
# - script: dotnet tool update Microsoft.DotNet.XHarness.CLI --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json --version "9.0.0-prerelease*" -g
# displayName: install xharness

Expand All @@ -200,11 +192,8 @@ jobs:
IOS_TEST_DEVICE: ios-simulator-64_17.2

- ${{ if eq(RunPlatform.testName, 'RunOniOS') }}:
- bash: |
suffix=$(date +%Y%m%d%H%M%S)
zip -9r "$(LogDirectory)/CoreSimulatorLog_${suffix}.zip" "$HOME/Library/Logs/CoreSimulator/"
zip -9r "$(LogDirectory)/DiagnosticReports_${suffix}.zip" "$HOME/Library/Logs/DiagnosticReports/"
displayName: Zip Simulator Logs
- pwsh: ./build.ps1 --target=Cleanup -Script eng/devices/ios.cake ---results="$(TestResultsDirectory)" ${{ parameters.cakeArgs }}
displayName: Cleanup and Create Simulator Logs if Test Run Failed To
condition: always()
continueOnError: true

Expand Down
8 changes: 3 additions & 5 deletions eng/pipelines/common/ui-tests-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,16 @@ steps:
$command += " --test-filter ""$testFilter"""
}
Invoke-Expression $command
Invoke-Expression $command
displayName: $(Agent.JobName)
${{ if ne(parameters.platform, 'android')}}:
retryCountOnTaskFailure: 1
env:
APPIUM_HOME: $(APPIUM_HOME)
- bash: |
suffix=$(date +%Y%m%d%H%M%S)
zip -9r "$(LogDirectory)/CoreSimulatorLog_${suffix}.zip" "$HOME/Library/Logs/CoreSimulator/"
zip -9r "$(LogDirectory)/DiagnosticReports_${suffix}.zip" "$HOME/Library/Logs/DiagnosticReports/"
displayName: Zip Simulator Logs
pwsh ./build.ps1 --target=Cleanup -Script eng/devices/${{ parameters.platform }}.cake ---results="$(TestResultsDirectory)" ${{ parameters.cakeArgs }}
displayName: Cleanup and Create Simulator Logs if Test Run Failed To
condition: ${{ eq(parameters.platform, 'ios') }}
continueOnError: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using Microsoft.Maui.Controls.Platform;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -187,7 +188,13 @@ public static void MapCurrentItem(CarouselViewHandler handler, CarouselView caro

public static void MapPosition(CarouselViewHandler handler, CarouselView carouselView)
{
handler.UpdatePosition();
// If the initial position hasn't been set, we have a UpdateInitialPosition call on CarouselViewHandler
// that will handle this so we want to skip this mapper call. We need to wait for the LIstView to be ready
if (handler.InitialPositionSet)
{
handler.UpdatePosition();
}

}

public static void MapIsBounceEnabled(CarouselViewHandler handler, CarouselView carouselView)
Expand All @@ -210,6 +217,9 @@ public static void MapLoop(CarouselViewHandler handler, CarouselView carouselVie
handler.UpdateLoop();
}

internal bool InitialPositionSet { get; private set; }


void UpdateIsBounceEnabled()
{
if (_scrollViewer != null)
Expand Down Expand Up @@ -337,7 +347,7 @@ int GetItemPositionInCarousel(object item)
return -1;
}

void UpdateCarouselViewInitialPosition()
void UpdateInitialPosition()
{
if (ListViewBase == null)
{
Expand All @@ -348,7 +358,7 @@ void UpdateCarouselViewInitialPosition()
{
if (Element.Loop)
{
var item = ListViewBase.Items[0];
var item = ItemsView.CurrentItem ?? ListViewBase.Items.FirstOrDefault();
_loopableCollectionView.CenterMode = true;
ListViewBase.ScrollIntoView(item);
_loopableCollectionView.CenterMode = false;
Expand All @@ -358,6 +368,8 @@ void UpdateCarouselViewInitialPosition()
UpdateCurrentItem();
else
UpdatePosition();

InitialPositionSet = true;
}
}

Expand Down Expand Up @@ -563,7 +575,7 @@ void InitialSetup()
UpdateItemsSource();
UpdateSnapPointsType();
UpdateSnapPointsAlignment();
UpdateCarouselViewInitialPosition();
UpdateInitialPosition();
}

void InvalidateItemSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ protected override void DisconnectHandler(ListViewBase platformView)

if (oldListViewBase != null)
{
oldListViewBase.ClearValue(ListViewBase.SelectionModeProperty);
oldListViewBase.SelectionChanged -= PlatformSelectionChanged;
oldListViewBase.ClearValue(ListViewBase.SelectionModeProperty);
}

if (ItemsView != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,15 +730,7 @@ void PinchComplete(bool success)

void UpdateDragAndDropGestureRecognizers()
{
if (_container is null)
{
return;
}

var view = Element as View;
IList<IGestureRecognizer>? gestures = view?.GestureRecognizers;

if (gestures is null)
if (_container is null || Element is not View view || view.GestureRecognizers is not IList<IGestureRecognizer> gestures)
{
return;
}
Expand Down Expand Up @@ -812,16 +804,17 @@ void UpdatingGestureRecognizers()
}
}

_subscriptionFlags |= SubscriptionFlags.ContainerPgrPointerEventsSubscribed;
_container.PointerEntered += OnPgrPointerEntered;
_container.PointerExited += OnPgrPointerExited;
_container.PointerMoved += OnPgrPointerMoved;
_container.PointerPressed += OnPgrPointerPressed;
_container.PointerReleased += OnPgrPointerReleased;
bool hasPointerGesture = ElementGestureRecognizers.HasAnyGesturesFor<PointerGestureRecognizer>();

if (hasPointerGesture)
{
SubscribePointerEvents(_container);
}

bool hasSwipeGesture = gestures.HasAnyGesturesFor<SwipeGestureRecognizer>();
bool hasPinchGesture = gestures.HasAnyGesturesFor<PinchGestureRecognizer>();
bool hasPanGesture = gestures.HasAnyGesturesFor<PanGestureRecognizer>();

if (!hasSwipeGesture && !hasPinchGesture && !hasPanGesture)
{
return;
Expand All @@ -840,6 +833,12 @@ void UpdatingGestureRecognizers()
return;
}

// Pan, pinch, and swipe gestures need pointer events if not subscribed yet.
if (!hasPointerGesture)
{
SubscribePointerEvents(_container);
}

_subscriptionFlags |= SubscriptionFlags.ContainerManipulationAndPointerEventsSubscribed;
_container.ManipulationMode = ManipulationModes.Scale | ManipulationModes.TranslateX | ManipulationModes.TranslateY;
_container.ManipulationDelta += OnManipulationDelta;
Expand All @@ -848,6 +847,17 @@ void UpdatingGestureRecognizers()
_container.PointerCanceled += OnPointerCanceled;
}

void SubscribePointerEvents(FrameworkElement container)
{
_subscriptionFlags |= SubscriptionFlags.ContainerPgrPointerEventsSubscribed;

container.PointerEntered += OnPgrPointerEntered;
container.PointerExited += OnPgrPointerExited;
container.PointerMoved += OnPgrPointerMoved;
container.PointerPressed += OnPgrPointerPressed;
container.PointerReleased += OnPgrPointerReleased;
}

void HandleTapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs)
{
tappedRoutedEventArgs.Handled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ static void ProcessRecognizerHandlerTap(
if (weakRecognizer.Target is IPinchGestureController pinchGestureRecognizer &&
weakEventTracker.Target is GesturePlatformManager eventTracker &&
eventTracker._handler?.VirtualView is View view &&
UIApplication.SharedApplication.GetKeyWindow() is UIWindow window)
eventTracker.PlatformView is {} platformView)
{
var oldScale = eventTracker._previousScale;
var originPoint = r.LocationInView(null);
originPoint = window.ConvertPointToView(originPoint, eventTracker.PlatformView);
originPoint = platformView.Window.ConvertPointToView(originPoint, platformView);

var scaledPoint = new Point(originPoint.X / view.Width, originPoint.Y / view.Height);

Expand Down Expand Up @@ -412,8 +412,7 @@ UISwipeGestureRecognizer CreateSwipeRecognizer(SwipeDirection direction, Action<
{
if (weakRecognizer.Target is PointerGestureRecognizer pointerGestureRecognizer &&
weakEventTracker.Target is GesturePlatformManager eventTracker &&
eventTracker._handler?.VirtualView is View view &&
eventTracker._handler?.MauiContext?.GetPlatformWindow() is UIWindow window)
eventTracker._handler?.VirtualView is View view)
{
var originPoint = pointerGesture.LocationInView(eventTracker?.PlatformView);
var platformPointerArgs = new PlatformPointerEventArgs(pointerGesture.View, pointerGesture);
Expand Down
Loading

0 comments on commit 10d9bdb

Please sign in to comment.