Closed huan-nguyen closed 6 years ago
Thank you for the feedback. I'm really busy now so give me a few weeks to get back to you!
Remove pairWithDelay. Instead immediately emits a new state with false property.
The problem with that is we would want to show a snackbar on rotation; this above solution doesn't allow that.
I think the problem was that we had different fields rendering the same widget (the snackbar), I changed the code so now they all update the same new field uiNotification
. On the delayed event, they would turn that to null
only if the existing value match their type.
Another idea I had was to have all those snackbar rendered events go through the same stream with a switchMap
that would then cancel the to-be-delayed event. But didn't seem good.
The PR is a bit dirty with the formatting but the fix is in there.
Firstly thank you for this nice sample code.
When playing with the app I found a bug shown in this video: https://youtu.be/RG_m3_jO7SQ
It happens when you check and uncheck the 'complete' box of a task within 2 seconds. Basically what happens is when you check the box, the 'task completed'
Snackbar
is shown. Then within 2 seconds, you uncheck the box, the 'task completed' is shown again (which does not reflect the current state of the task - activated) and the 'task activated' snackbar is only shown after the second 'task completed'Snackbar
is auto-dismissed.This bug is caused by the way
Snackbar
show events are currently managed usingpairWithDelay
which emits a new view state after 2 seconds that clears the property (e.g.,taskComplete
ortaskActivated
) which invokesSnackbar
.What happens is:
showMessage
for 'task completed' calledshowMessage
for 'task activated' called immediately followed byshowMessage
for 'task completed'. Thats why you'll see only 'task complete' snackbarshowMessage
for 'task activated' calledSnackbar
's dismissal is handled bySnackbar
itself due toSnackbar.LENGTH_LONG
is used.I believe the root cause of this issue is the fact that
pairWithDelay
with 2 seconds is used. I understand from the conversation in issue #6 that it was an attempt to adopt Hannes's suggestion onSingleLiveEvent
alternative. IMHO the key idea from his blog post is to have the presenter/viewmodel responsible for both showing and dismissingSnackbar
s (by constructing view states). To do that, he setSnackbar
time toSnackbar.LENGTH_INDEFINITE
.However, in this app,
Snackbar
showing time is set toSnackbar.LENGTH_LONG
which means the dismissal ofSnackbar
is handled by theSnackbar
itself. This raises a question as to why you need the timer of 2 seconds to update the view state and then that updated state is not used for view rendering (false
values of properties liketaskComplete
ortaskActivated
are not used inrender
method). AlsoSnackbar.LENGTH_LONG
is normally not 2 seconds.IMHO there are 2 approaches to fix this issue:
pairWithDelay
. Instead immediately emits a new state with false property.Snackbar
's dismissal.Would be interested hearing your thoughts.