Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fix back button crash + Cleanup #14

Merged
merged 4 commits into from
Jul 13, 2022
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
41 changes: 39 additions & 2 deletions Mopups/Mopups.Maui/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ namespace Mopups.Hosting;
/// </summary>
public static class AppHostBuilderExtensions
{

/// <summary>
/// Configures the implemented handlers in Syncfusion.Maui.Core.
/// Automatically sets up lifecycle events and Maui Handlers
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static MauiAppBuilder ConfigureMopups(this MauiAppBuilder builder)
{
builder
Expand All @@ -19,7 +22,40 @@ public static MauiAppBuilder ConfigureMopups(this MauiAppBuilder builder)
#if ANDROID
lifecycle.AddAndroid(d =>
{
d.OnBackPressed(activity => Droid.Implementation.AndroidMopups.SendBackPressed(activity.OnBackPressed));

d.OnBackPressed(activity => Droid.Implementation.AndroidMopups.SendBackPressed());
});
#endif
})
.ConfigureMauiHandlers(handlers =>
{
#if ANDROID
handlers.AddHandler(typeof(PopupPage), typeof(PopupPageHandler));
#endif
#if IOS
handlers.AddHandler(typeof(PopupPage), typeof(Platforms.iOS.PopupPageHandler));
#endif
});
return builder;
}


/// <summary>
/// Automatically sets up lifecycle events and maui handlers, with the additional option to have additional back press logic
/// </summary>
/// <param name="builder"></param>
/// <param name="backPressHandler"></param>
/// <returns></returns>
public static MauiAppBuilder ConfigureMopups(this MauiAppBuilder builder, Action? backPressHandler)
{
builder
.ConfigureLifecycleEvents(lifecycle =>
{
#if ANDROID
lifecycle.AddAndroid(d =>
{

d.OnBackPressed(activity => Droid.Implementation.AndroidMopups.SendBackPressed(backPressHandler));
});
#endif
})
Expand All @@ -34,4 +70,5 @@ public static MauiAppBuilder ConfigureMopups(this MauiAppBuilder builder)
});
return builder;
}

}
7 changes: 3 additions & 4 deletions Mopups/Mopups.Maui/Mopups.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Authors>Tyson Hooker,Maksym Koshovyi,Aswin P G, Kirill Lyubimov, Martijn Van Dijk</Authors>
<Company>$(CompanyName)</Company>

<PackageTags>Popups;Maui;rg;</PackageTags>
<Version>1.0.0</Version>
<PackageTags>Popups;Maui;rg;Xamarin;ios;android;</PackageTags>
<Version>1.0.1</Version>
<Title>Mopups (Maui Popups)</Title>
<PackageReleaseNotes>First official release! This runs on iOS and Android. There is still much work to be done, and plenty of bugs to find.</PackageReleaseNotes>
<PackageReleaseNotes>Fixed bug surrounding the use of the back button, now provide an overload for configureMopups</PackageReleaseNotes>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-android|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
2 changes: 0 additions & 2 deletions Mopups/Mopups.Maui/Platforms/Android/Impl/AndroidMopups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public static bool SendBackPressed(Action? backPressedHandler = null)

return true;
}

backPressedHandler?.Invoke();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't backPressedHandler parameter be removed then, if it's never used? Why did we need it in the first place?

Copy link
Owner Author

Choose a reason for hiding this comment

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

And this is why i made a PR ahaha.

So as far as im aware, if i keep that invoke in it makes an endless loop which crashes the system.

I think the original intention is to provide extra functionality on top.

The apphostbuilder area seems to be the only place this is registered, so perhaps we instead need to move that custom functionality to there somehow?

I'm on mobile, but i'll give this another shakedown, i need to learn more about apphostbuilder instead of just throwing everything at it and seeing what sticks

Copy link
Collaborator

@maxkoshevoi maxkoshevoi Jul 5, 2022

Choose a reason for hiding this comment

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

If backPressedHandler is not passed, backPressedHandler?.Invoke(); won't do anything, right? So the problem might be in the value this is passed in backPressedHandler, and not in the parameter itself.


return false;
}

Expand Down
15 changes: 0 additions & 15 deletions MopupsEx/App.xaml

This file was deleted.

13 changes: 0 additions & 13 deletions MopupsEx/App.xaml.cs

This file was deleted.

107 changes: 0 additions & 107 deletions MopupsEx/CSharpMarkup/LoginPage.cs

This file was deleted.

16 changes: 0 additions & 16 deletions MopupsEx/CSharpMarkup/LoginPage.logic.cs

This file was deleted.

22 changes: 0 additions & 22 deletions MopupsEx/CSharpMarkup/MainPage.logic.cs

This file was deleted.

20 changes: 0 additions & 20 deletions MopupsEx/MauiProgram.cs

This file was deleted.

27 changes: 0 additions & 27 deletions MopupsEx/MopupsEx.App.sln

This file was deleted.

61 changes: 0 additions & 61 deletions MopupsEx/MopupsEx.csproj

This file was deleted.

6 changes: 0 additions & 6 deletions MopupsEx/Platforms/Android/AndroidManifest.xml

This file was deleted.

11 changes: 0 additions & 11 deletions MopupsEx/Platforms/Android/MainActivity.cs

This file was deleted.

Loading