Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
326 changes: 298 additions & 28 deletions src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public event EventHandler<DisplayInfoChangedEventArgs> MainDisplayInfoChanged
{
add
{
if (value is null)
return;

if (MainDisplayInfoChangedInternal is null)
{
SetCurrent(MainDisplayInfo);
Expand Down
17 changes: 17 additions & 0 deletions src/Essentials/test/DeviceTests/Platforms/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>__MAUI_DEFAULT_SCENE_CONFIGURATION__</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Access to your location is required for cool things to happen!</string>
<key>NSContactsUsageDescription</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Foundation;
using Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner;

namespace Microsoft.Maui.Essentials.DeviceTests.iOS;

[Register("SceneDelegate")]
public class SceneDelegate : MauiTestSceneDelegate
{
}
595 changes: 595 additions & 0 deletions src/Essentials/test/DeviceTests/Tests/iOS/DeviceDisplay_Tests.cs

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/Essentials/test/UnitTests/DeviceDisplay_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,31 @@ void OnChanged(object sender, DisplayInfoChangedEventArgs e)
}
}

[Fact]
public void Null_MainDisplayInfoChanged_Does_Not_Start_Or_Stop_Listeners()
{
var display = new MyDisplay();

display.MainDisplayInfoChanged += null;
display.MainDisplayInfoChanged -= null;
Assert.Equal(0, display.StartedCount);
Assert.Equal(0, display.StoppedCount);

display.MainDisplayInfoChanged += OnChanged;
display.MainDisplayInfoChanged += null;
display.MainDisplayInfoChanged -= null;
Assert.Equal(1, display.StartedCount);
Assert.Equal(0, display.StoppedCount);

display.MainDisplayInfoChanged -= OnChanged;
Assert.Equal(1, display.StartedCount);
Assert.Equal(1, display.StoppedCount);

void OnChanged(object sender, DisplayInfoChangedEventArgs e)
{
}
}

[Fact]
public void Adding_Second_MainDisplayInfoChanged_Invokes_Correct_Members()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,16 @@ public override bool FinishedLaunching(UIApplication application, NSDictionary?

Window = window;

#if MACCATALYST
if (HasSceneManifest())
return true;
#endif

window.MakeKeyAndVisible();
SetWindowReady();

return true;
}

#if MACCATALYST
static bool HasSceneManifest() =>
NSBundle.MainBundle.InfoDictionary?.ContainsKey(new NSString("UIApplicationSceneManifest")) == true;
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner;

/// <summary>
/// Attaches the headless runner's window to its Mac Catalyst scene before starting tests.
/// Attaches the headless runner's window to its scene before starting tests.
/// </summary>
public class MauiTestSceneDelegate : MauiUISceneDelegate
{
Expand Down
Loading