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

Fix login detail pages loosing user changes on rotation / re-creation (closes #775) #778

Conversation

sunkup
Copy link
Member

@sunkup sunkup commented May 3, 2024

Purpose

Previously view models of the login details compose screens were initialized using LaunchedEffect, which had
LoginDetails screens loose user made changes on screen rotation/re-compose. This is because the LaunchedEffect was called on every re-composition, even when called with a constant like LaunchedEffect(true).

Injecting the view models with hilt allows to initialize the model directly when created by the hilt factory, thus circumventing the problem.

Short description

  • Add hilt assisted factories to the view models
  • Inject view models in composables using hilt with factories passing the initialLoginInfo along.
  • initialize the view models on creation

See also:
https://developer.android.com/develop/ui/compose/libraries#hilt
https://developer.android.com/develop/ui/compose/libraries#viewmodel

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@sunkup sunkup linked an issue May 3, 2024 that may be closed by this pull request
@sunkup sunkup marked this pull request as ready for review May 6, 2024 06:45
@sunkup sunkup requested a review from rfc2822 May 6, 2024 06:45
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

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

Looks good :)

@rfc2822 rfc2822 merged commit ad24dd5 into main-ose May 7, 2024
9 checks passed
@rfc2822 rfc2822 deleted the 775-re-creation-rotation-of-logindetails-page-looses-user-changes branch May 7, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-creation / rotation of LoginDetails page looses user changes
2 participants