-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from muak/fix/DisconnectHandler
Fix DisconnectHandler
- Loading branch information
Showing
8 changed files
with
141 additions
and
28 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using Microsoft.Maui.Handlers; | ||
|
||
namespace AiForms.Settings.Extensions; | ||
|
||
public static class HandlerCleanUpHelper | ||
{ | ||
public static void AddCleanUpEvent(this View view) | ||
{ | ||
if (view is not Element element) | ||
{ | ||
return; | ||
} | ||
|
||
Page parentPage; | ||
|
||
void PageUnloaded(object sender, EventArgs e) | ||
{ | ||
view.Handler?.DisconnectHandler(); | ||
if (parentPage is not null) | ||
{ | ||
parentPage.Unloaded -= PageUnloaded; | ||
parentPage = null; | ||
} | ||
} | ||
|
||
foreach (var el in element.GetParentsPath()) | ||
{ | ||
if (el is Page page) | ||
{ | ||
parentPage = page; | ||
page.Unloaded += PageUnloaded; | ||
} | ||
} | ||
} | ||
} | ||
|
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,18 @@ | ||
using System; | ||
namespace AiForms.Settings; | ||
|
||
public static class MauiAppBuilderExtension | ||
{ | ||
public static MauiAppBuilder UseSettingsView(this MauiAppBuilder builder, bool shouldCallDisconnectHandlerWhenPageUnloaded = false) | ||
{ | ||
builder.ConfigureMauiHandlers(handler => | ||
{ | ||
handler.AddSettingsViewHandler(); | ||
}); | ||
|
||
SettingsViewConfiguration.ShouldAutoDisconnect = shouldCallDisconnectHandlerWhenPageUnloaded; | ||
|
||
return builder; | ||
} | ||
} | ||
|
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,8 @@ | ||
using System; | ||
namespace AiForms.Settings; | ||
|
||
internal static class SettingsViewConfiguration | ||
{ | ||
internal static bool ShouldAutoDisconnect { get; set; } | ||
} | ||
|