Commit b5b5721
Joe Hansche
Fix race condition caused by delayed hiding of previous state.
The fix for #1 (race condition) also introduces a second race condition
when `setState()` is called a second time before the 1st call's previous
state view was hidden by the `Runnable`. For example:
msv.setState(ContentState.LOADING); // (1)
msv.setState(ContentState.CONTENT); // (2)
This is the simplest way to reproduce the problem. The default state is
`ContentState.CONTENT`. The (1) call shows the `LOADING` view and posts
a runnable that intends to hide the `CONTENT` view. Then the (2) call
does the opposite: shows the `CONTENT` view and posts a runnable
to hide the `LOADING` view. The (2) show happens before the (1)
runnable has a chance to hide the `CONTENT` view, so when the runnable
finally does get run, it hides the `CONTENT` view, superceding the work
done by the (2) call.
This change converts the `postRunnable()` behavior into an inner
`Handler` subclass that will take a `ContentState` obj that is meant
to be hidden. That way when `setState()` is called, we can remove any
pending messages that are meant to hide the state that is currently
requested to be shown. If however, you are switching states to a different
state, then the pending hide will still be executed properly, such as:
msv.setState(ContentState.LOADING);
msv.setState(ContentState.GENERAL_ERROR);
// will still hide CONTENT *and* will hide LOADING
This manifests easily when you set up your view to have an initial state
of `LOADING` in `onViewCreated()`, and in `onViewStateRestored()`, you
set the state back to `CONTENT`.1 parent 790f66f commit b5b5721
1 file changed
Lines changed: 51 additions & 13 deletions
Lines changed: 51 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
8 | | - | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | | - | |
29 | | - | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | | - | |
34 | | - | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| 179 | + | |
| 180 | + | |
178 | 181 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 182 | + | |
187 | 183 | | |
188 | 184 | | |
189 | 185 | | |
| |||
363 | 359 | | |
364 | 360 | | |
365 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
366 | 375 | | |
367 | 376 | | |
368 | 377 | | |
| |||
538 | 547 | | |
539 | 548 | | |
540 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
541 | 579 | | |
0 commit comments