OSDN Git Service

View: fix setTransientState
authorDake Gu <dake@google.com>
Tue, 1 Aug 2017 20:42:42 +0000 (13:42 -0700)
committerDake Gu <dake@google.com>
Tue, 1 Aug 2017 21:17:39 +0000 (14:17 -0700)
commit43ad57e548b86daf50e0ebfde440fe431a41cb1e
tree2c09104bc88416e16b6326d437f40971f746aebc
parent0d7ff5328e15a1de752dcb483f9aca0e55a44118
View: fix setTransientState

Following four steps with RecyclerView - CardView - ImageView:
a. fade in imageview in onBind:
calling imageView.setTransientState(true)
b. RecyclerView animate the item: calling
cardView.setTransientState(true)
c. fade-in finishes, calling imageView.setTransientState(false)
d. RecyclerView animation finishes: calling
cardView.setTransientState(false)

After these four steps, RecyclerView unexpectedly has transient
state.

The problem is in step b, when calling cardView.setTransientState()
it incorrectly calls parent.childHasTransientStateChanged(this, true)
which causes RecyclerView's mChildCountWithTransientState increased
to 2. And it's decreased to 1 in step d and stay as 1 forever.

The child should only call childHasTransientStateChanged() when
actual hasTransientState() changed.

Bug: 64235615
Test: ViewTransientStateTest
Change-Id: I99ed35cc9c49e54d36590d8f1d206501fd3288f2
core/java/android/view/View.java
core/tests/coretests/AndroidManifest.xml
core/tests/coretests/res/layout/view_transient_state.xml [new file with mode: 0644]
core/tests/coretests/src/android/view/ViewTransientState.java [new file with mode: 0644]
core/tests/coretests/src/android/view/ViewTransientStateTest.java [new file with mode: 0644]