Skip to content

Commit 73f95b4

Browse files
fix: explode transition issue by setting transitionGroup to false
1 parent 2e57c70 commit 73f95b4

26 files changed

+1492
-78
lines changed

External-Tutorial-GridToPager/src/main/res/transition/grid_exit_transition.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<fade>
2222
<targets android:targetId="@id/card_view" />
2323
</fade>
24-
<!-- <explode>-->
25-
<!-- <targets android:targetId="@id/recycler_view"/>-->
26-
<!-- </explode>-->
24+
<explode>
25+
<targets android:targetId="@id/recycler_view" />
26+
</explode>
2727
</transitionSet>

README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ of ***Transition*** start and end point to same value.
324324
#### Note:
325325
🔥🔥🔥 In tutorial 2-4 and 2-5, having same background color for both fragments causing second fragment's **ENTER TRANSITION(CircularReveal and Slide.BOTTOM)** to not work.
326326
So when using **Transitions** that extend ```Visiblity``` class such as Slide, or Fade be careful about background color.
327-
Either set callback and set start and end properties for starging and ending scenes with
327+
328+
To prevent this use one of the solutions below:
329+
330+
* Set ```android:transitionGroup="false"``` on layout with fragments
331+
* Set callback and set start and end properties for starting and ending scenes with
328332

329333
```
330334
setEnterSharedElementCallback(object : SharedElementCallback() {
@@ -357,7 +361,7 @@ Either set callback and set start and end properties for starging and ending sce
357361
}
358362
```
359363

360-
or use **custom transitions** that extend either ```Transition``` or ```Visibility``` and force value changes.
364+
* Use **custom transitions** that extend either ```Transition``` or ```Visibility``` and force value changes.
361365

362366
* ⚠️ Transitions that extend ```Visibility``` such as ```Slide```, ```Fade```, or ```Explode``` depends on ***visibility*** of the view. If
363367
visibility is changed from ```View.INVISIBLE``` to ```View.VISIBLE``` ```onAppear``` method of ```Visibility``` class is called, if visibility changes
@@ -367,6 +371,13 @@ from backwards.
367371
* ⚠️ When current transition is **EXIT** or **RETURN** transition ```captureEndValues``` is not called, because of this use a transition that extends ```Visibility``` for ```exitTransition``` and ```returnTransition``` to start,
368372
and be aware that Animator from ```onDisAppear``` is called while current transition is exit or return.
369373

374+
#### Note: Breaker of chains — Transition Groups
375+
376+
By default all views under a parent/ancestor with a background set (even transparent ones) will be automatically deemed a group. If you need to break them up like we here with a RecyclerView as the shared-root-white-backgrounded layout with transparent child Item views. You’ll need to set the **layout with the background** to **transitionGroup=false.**
377+
But on the other hand, since the Items are “background-less” themselves, to prevent an out-of-body experience you’ll need to do the opposite and set transitionGroup=true on the Item layouts for all the child views in that Item to move together.
378+
379+
380+
370381
### Resources and References
371382

372383
[CodeLab Property Animation](https://codelabs.developers.google.com/codelabs/advanced-android-kotlin-training-property-animation/#0)
@@ -391,6 +402,8 @@ and be aware that Animator from ```onDisAppear``` is called while current transi
391402
<br>
392403
[Reveal Transition](https://halfthought.wordpress.com/2014/11/07/reveal-transition/)
393404
<br>
405+
[Android — Inbox Material Transitions for RecyclerView](https://medium.com/workday-engineering/android-inbox-material-transitions-for-recyclerview-7ae3cb241aed)
406+
<br>
394407
[Plaid App](https://github.com/android/plaid)
395408

396409
### TODOs:

Tutorial3-1Transitions/src/main/AndroidManifest.xml

+4
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
<activity android:name=".chapter1_activity_transitions.Activity1_2Details" />
2424
<activity android:name=".chapter1_activity_transitions.Activity1_3RecyclerViewToViewPager2Transition" />
2525
<activity android:name=".chapter1_activity_transitions.Activity1_3Details" />
26+
<activity android:name=".chapter1_activity_transitions.Activity1_5Details" />
2627

28+
<!-- Fragment Tutorials -->
2729
<activity
2830
android:name=".chapter1_activity_transitions.Activity1_4RVtoVP2Transition"
2931
android:theme="@style/Theme.App.Home" />
3032
<activity
3133
android:name=".chapter1_activity_transitions.Activity1_4Details"
3234
android:theme="@style/Theme.App.Details" />
35+
<activity android:name=".chapter1_activity_transitions.Activity1_5RecyclerViewTransition2" />
36+
3337
<activity android:name=".chapter2_fragment_transitions.Activity2_1FragmentTransitionsBasics" />
3438
<activity android:name=".chapter2_fragment_transitions.Activity2_2FragmentTransitionLifeCycles" />
3539
<activity

Tutorial3-1Transitions/src/main/java/com/smarttoolfactory/tutorial3_1transitions/MainActivity.kt

+7
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ class MainActivity : AppCompatActivity(), BaseAdapter.OnRecyclerViewItemClickLis
9494
)
9595
)
9696

97+
activityClassModels.add(
98+
ActivityClassModel(
99+
Activity1_5RecyclerViewTransition2::class.java,
100+
getString(R.string.activity1_5)
101+
)
102+
)
103+
97104
activityClassModels.add(
98105
ActivityClassModel(
99106
Activity2_1FragmentTransitionsBasics::class.java,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.smarttoolfactory.tutorial3_1transitions.adapter.itemdecoration
2+
3+
import android.graphics.Rect
4+
import android.view.View
5+
import androidx.recyclerview.widget.RecyclerView
6+
7+
class GridSpacingItemDecoration(
8+
private val spanCount: Int,
9+
private val spacing: Int,
10+
) : RecyclerView.ItemDecoration() {
11+
12+
override fun getItemOffsets(
13+
outRect: Rect,
14+
view: View,
15+
parent: RecyclerView,
16+
state: RecyclerView.State
17+
) {
18+
val position = parent.getChildAdapterPosition(view)
19+
20+
val column = (position) % spanCount
21+
22+
if (column == 0) {
23+
outRect.left = spacing
24+
} else {
25+
outRect.left = 0
26+
}
27+
outRect.right = spacing
28+
outRect.bottom = 0
29+
outRect.top = spacing
30+
31+
}
32+
33+
}

0 commit comments

Comments
 (0)