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 blink favorite icon #945

Closed
wants to merge 14 commits into from
Closed

Conversation

kyanro
Copy link

@kyanro kyanro commented Sep 3, 2024

Issue

Overview (Required)

The probable causes are:

The value of collectAsRetainedState is not collected while navigating to another screen.
When returning to the original screen, the value is collected
but the update of the value likely occurs based on the execution timing of LaunchedEffect, so until the value is updated, the displayed value is not the latest.

  • Change getFavoriteSessionStream return type to StateFlow
    • To allow setting the initial value synchronously
  • Change safeCollectAsRetainedState to collectAsState
    • To collect the latest value when returning to the previous screen

Movie (Optional)

Before After
before_Screen_recording_20240904_002135.mp4
after_Screen_recording_20240906_002004.mp4

@github-actions github-actions bot temporarily deployed to deploygate-distribution September 4, 2024 09:27 Inactive
@github-actions github-actions bot temporarily deployed to deploygate-distribution September 4, 2024 09:39 Inactive
@takahirom
Copy link
Member

takahirom commented Sep 4, 2024

Thank you for your insights on the code. I think this PR introduces several changes. What do you think is the cause? If we use memory cache, is rememberRetained fine? It is a little difficult to manage if we add a source of information.

@DroidKaigi DroidKaigi deleted a comment from github-actions bot Sep 4, 2024
@kyanro
Copy link
Author

kyanro commented Sep 4, 2024

Thank you for your comment.

What do you think is the cause?

I did some further investigation.

The probable causes are:

  • The value of collectAsRetainedState is not collected while navigating to another screen.
  • When returning to the original screen, the value is collected
    • but the update of the value likely occurs based on the execution timing of LaunchedEffect, so until the value is updated, the displayed value is not the latest.

If we use memory cache, is rememberRetained fine?

The problem seems to be that the value during the transition to another screen cannot be reflected, so it doesn’t seem that rememberRetained can solve the issue.

It is a little difficult to manage if we add a source of information.

I agree with that.

How about changing getFavoriteSessionStream to return a StateFlow instead of exposing the memory cache, and using collectAsState so that the latest value is always reflected when returning to the original screen?

I believe there may be some issues with this approach as well, so once I push the code, I’d appreciate it if you could review it.

@kyanro kyanro marked this pull request as draft September 4, 2024 23:57
@kyanro kyanro marked this pull request as ready for review September 5, 2024 15:38
@kyanro
Copy link
Author

kyanro commented Sep 5, 2024

Updated the source code and the overview 😄

Copy link

github-actions bot commented Sep 5, 2024

Detekt check failed. Please run ./gradlew detekt --auto-correct to fix the issues.

@github-actions github-actions bot temporarily deployed to deploygate-distribution September 5, 2024 23:54 Inactive

public class UserDataStore(private val dataStore: DataStore<Preferences>) {

private val mutableIdToken = MutableStateFlow<String?>(null)
public val idToken: StateFlow<String?> = mutableIdToken

public fun getFavoriteSessionStream(): Flow<PersistentSet<TimetableItemId>> {
return dataStore.data
private val singletonCoroutineScope: CoroutineScope = CoroutineScope(Job())
Copy link
Member

Choose a reason for hiding this comment

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

This could be an unmanaged dispatcher in tests, which could result in flaky tests. I think we need to pass a dispatcher for this.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your comment.

I modified it so that testDispatcher can be used during testing.
Does this fix seem okay to you?

move coroutineScope field to constructor parameter
Add TestUserDataStoreModule

@takahirom
Copy link
Member

I'm not sure, but the tests don't show all the favorite sessions. 👀
I'm also uncertain if we should have a CoroutineScope in DataStore, as it might consume resources even when the app is in the background.

@kyanro
Copy link
Author

kyanro commented Sep 10, 2024

Thank you.
I will investigate the issue regarding all favorite sessions not being displayed.

I also share your concern about having a CoroutineScope in DataStore, so I will try exploring alternative approaches, though it may be quite challenging.

If I can’t resolve it, I may give up and close this pull request, so would it be possible to assign someone else?

@github-actions github-actions bot temporarily deployed to deploygate-distribution September 10, 2024 15:58 Inactive
@kyanro
Copy link
Author

kyanro commented Sep 11, 2024

I apologize. I tried various things, but I couldn't resolve the issue successfully.

I will continue to investigate, but I would like to unassign myself and close this pull request for now.

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.

When returning after performing a favorite operation on SearchScreen, the favorite icon blinks momentarily
2 participants