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

Add AutoSuspendHelper to ReactiveUI.XamForms #2523

Merged
merged 2 commits into from
Sep 8, 2020

Conversation

worldbeater
Copy link
Contributor

@worldbeater worldbeater commented Sep 8, 2020

What kind of change does this PR introduce?

This PR adds a new AutoSuspendHelper utility class to the ReactiveUI.XamForms package. In the proposed implementation we rely on Xamarin.Forms app lifecycle events https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/app-lifecycle

What is the current behavior?

Currently, AutoSuspendHelper implementations exist for iOS and Android as separate classes. An implementation targeting Xamarin.Forms could help to reduce the amount of platform-specific code as stated in #1429 and also this way we can support other platforms supported by XF.

What is the new behavior?

Now, there is an implementation of AutoSuspendHelper that works with Xamarin.Forms. Expected usage:

public partial class App : Application
{
    private readonly AutoSuspendHelper _autoSuspendHelper;

    public App()
    {
        _autoSuspendHelper = new AutoSuspendHelper();
        RxApp.SuspensionHost.CreateNewAppState = () => new MainState();
        RxApp.SuspensionHost.SetupDefaultSuspendResume(new CustomSuspensionDriver());
        _autoSuspendHelper.OnCreate();
    
        InitializeComponent();
        var state = RxApp.SuspensionHost.GetAppState<AppState>();
        MainPage = new MainView(new MainViewModel(state));
    }
    
    protected override void OnStart() => _autoSuspendHelper.OnStart();
    
    protected override void OnResume() => _autoSuspendHelper.OnResume();
    
    protected override void OnSleep() => _autoSuspendHelper.OnSleep();
}

What might this PR break?

Nothing.

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

@codecov
Copy link

codecov bot commented Sep 8, 2020

Codecov Report

Merging #2523 into main will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2523   +/-   ##
=======================================
  Coverage   52.82%   52.82%           
=======================================
  Files         116      116           
  Lines        4572     4572           
  Branches      802      802           
=======================================
  Hits         2415     2415           
  Misses       1913     1913           
  Partials      244      244           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5477fa3...8a45255. Read the comment docs.

@worldbeater worldbeater marked this pull request as ready for review September 8, 2020 21:15
@worldbeater worldbeater requested a review from a team September 8, 2020 21:15
@glennawatson
Copy link
Contributor

Last time I checked this was held up by #1133. Is it fixed now?

@worldbeater
Copy link
Contributor Author

worldbeater commented Sep 8, 2020

@glennawatson curious how data persistence may relate to XF view activation? Always thought ReactiveUI data persistence is a separate feature which only depends on lifecycle events of an application, according to AutoSuspendHelper implementation used in ReactiveUI.AndroidSupport, and also according to AutoSuspendHelper implementation used in iOS. Tested the implementation in a separate XF project and so far it worked (but probably I was a bit naive and didn't test some edge cases).

@glennawatson glennawatson merged commit c36fd6e into main Sep 8, 2020
@glennawatson glennawatson deleted the xam-forms-auto-suspension branch September 8, 2020 23:01
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants