Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit a441a1d

Browse files
authored
Merge pull request #76 from android/yaraki/Motion-container
Motion: Use MaterialContainerTransform
2 parents 8b38e9f + 8ab6a76 commit a441a1d

File tree

14 files changed

+33
-69
lines changed

14 files changed

+33
-69
lines changed

Motion/.idea/misc.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Motion/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ package.
4545

4646
<img src="screenshots/sharedelement.gif" height="400" alt="sharedelement"/>
4747

48-
### [Navigation > Fade through](app/src/main/java/com/example/android/motion/demo/navfadethrough)
48+
### [Navigation > Container transform](app/src/main/java/com/example/android/motion/demo/containertransform)
4949

50-
<img src="screenshots/navigationfadethrough.gif" height="400" alt="navfadethrough"/>
50+
<img src="screenshots/containertransform.gif" height="400" alt="containertransform"/>

Motion/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@
174174
</activity>
175175

176176
<activity
177-
android:name=".demo.navfadethrough.NavFadeThroughActivity"
178-
android:label="@string/nav_fade_through_label"
177+
android:name=".demo.containertransform.ContainerTransformActivity"
178+
android:label="@string/container_transform_label"
179179
android:theme="@style/Theme.Motion.Translucent">
180180
<intent-filter>
181181
<action android:name="android.intent.action.MAIN" />
@@ -184,10 +184,10 @@
184184

185185
<meta-data
186186
android:name="com.example.android.motion.demo.DESCRIPTION"
187-
android:value="@string/nav_fade_through_description" />
187+
android:value="@string/container_transform_description" />
188188
<meta-data
189189
android:name="com.example.android.motion.demo.APIS"
190-
android:resource="@array/nav_fade_through_apis" />
190+
android:resource="@array/container_transform_apis" />
191191
</activity>
192192

193193
</application>

Motion/app/src/main/java/com/example/android/motion/demo/navfadethrough/CheeseArticleFragment.kt renamed to Motion/app/src/main/java/com/example/android/motion/demo/containertransform/CheeseArticleFragment.kt

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.example.android.motion.demo.navfadethrough
17+
package com.example.android.motion.demo.containertransform
1818

1919
import android.os.Bundle
2020
import android.view.LayoutInflater
@@ -24,7 +24,6 @@ import android.widget.FrameLayout
2424
import android.widget.ImageView
2525
import android.widget.LinearLayout
2626
import android.widget.TextView
27-
import androidx.annotation.IdRes
2827
import androidx.appcompat.widget.Toolbar
2928
import androidx.coordinatorlayout.widget.CoordinatorLayout
3029
import androidx.core.view.ViewCompat
@@ -36,25 +35,14 @@ import androidx.fragment.app.Fragment
3635
import androidx.fragment.app.viewModels
3736
import androidx.navigation.findNavController
3837
import androidx.navigation.fragment.navArgs
39-
import androidx.transition.ChangeBounds
40-
import androidx.transition.ChangeTransform
41-
import androidx.transition.Transition
4238
import com.example.android.motion.R
43-
import com.example.android.motion.demo.FAST_OUT_SLOW_IN
44-
import com.example.android.motion.demo.LARGE_COLLAPSE_DURATION
45-
import com.example.android.motion.demo.LARGE_EXPAND_DURATION
46-
import com.example.android.motion.demo.plusAssign
47-
import com.example.android.motion.demo.sharedelement.MirrorView
48-
import com.example.android.motion.demo.sharedelement.SharedFade
49-
import com.example.android.motion.demo.transitionTogether
5039
import com.google.android.material.appbar.CollapsingToolbarLayout
40+
import com.google.android.material.transition.MaterialContainerTransform
5141

5242
class CheeseArticleFragment : Fragment() {
5343

5444
companion object {
5545
const val TRANSITION_NAME_BACKGROUND = "background"
56-
const val TRANSITION_NAME_CARD_CONTENT = "card_content"
57-
const val TRANSITION_NAME_ARTICLE_CONTENT = "article_content"
5846
}
5947

6048
private val args: CheeseArticleFragmentArgs by navArgs()
@@ -65,26 +53,12 @@ class CheeseArticleFragment : Fragment() {
6553
super.onCreate(savedInstanceState)
6654

6755
// These are the shared element transitions.
68-
sharedElementEnterTransition =
69-
createSharedElementTransition(LARGE_EXPAND_DURATION, R.id.article_mirror)
70-
sharedElementReturnTransition =
71-
createSharedElementTransition(LARGE_COLLAPSE_DURATION, R.id.card_mirror)
56+
sharedElementEnterTransition = MaterialContainerTransform(requireContext(), true)
57+
sharedElementReturnTransition = MaterialContainerTransform(requireContext(), false)
7258

7359
viewModel.cheeseId = args.cheeseId
7460
}
7561

76-
private fun createSharedElementTransition(duration: Long, @IdRes noTransform: Int): Transition {
77-
return transitionTogether {
78-
this.duration = duration
79-
interpolator = FAST_OUT_SLOW_IN
80-
this += SharedFade()
81-
this += ChangeBounds()
82-
this += ChangeTransform()
83-
// The content is already transformed along with the parent. Exclude it.
84-
.excludeTarget(noTransform, true)
85-
}
86-
}
87-
8862
override fun onCreateView(
8963
inflater: LayoutInflater,
9064
container: ViewGroup?,
@@ -102,11 +76,8 @@ class CheeseArticleFragment : Fragment() {
10276

10377
val background: FrameLayout = view.findViewById(R.id.background)
10478
val coordinator: CoordinatorLayout = view.findViewById(R.id.coordinator)
105-
val mirror: MirrorView = view.findViewById(R.id.card_mirror)
10679

10780
ViewCompat.setTransitionName(background, TRANSITION_NAME_BACKGROUND)
108-
ViewCompat.setTransitionName(coordinator, TRANSITION_NAME_ARTICLE_CONTENT)
109-
ViewCompat.setTransitionName(mirror, TRANSITION_NAME_CARD_CONTENT)
11081
ViewGroupCompat.setTransitionGroup(coordinator, true)
11182

11283
// Adjust the edge-to-edge display.

Motion/app/src/main/java/com/example/android/motion/demo/navfadethrough/CheeseArticleViewModel.kt renamed to Motion/app/src/main/java/com/example/android/motion/demo/containertransform/CheeseArticleViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.example.android.motion.demo.navfadethrough
17+
package com.example.android.motion.demo.containertransform
1818

1919
import androidx.lifecycle.LiveData
2020
import androidx.lifecycle.MutableLiveData

Motion/app/src/main/java/com/example/android/motion/demo/navfadethrough/CheeseCardFragment.kt renamed to Motion/app/src/main/java/com/example/android/motion/demo/containertransform/CheeseCardFragment.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.example.android.motion.demo.navfadethrough
17+
package com.example.android.motion.demo.containertransform
1818

1919
import android.os.Bundle
2020
import android.view.LayoutInflater
@@ -39,7 +39,6 @@ import com.example.android.motion.demo.FAST_OUT_LINEAR_IN
3939
import com.example.android.motion.demo.LARGE_COLLAPSE_DURATION
4040
import com.example.android.motion.demo.LARGE_EXPAND_DURATION
4141
import com.example.android.motion.demo.LINEAR_OUT_SLOW_IN
42-
import com.example.android.motion.demo.sharedelement.MirrorView
4342
import com.google.android.material.appbar.AppBarLayout
4443
import com.google.android.material.card.MaterialCardView
4544

@@ -75,7 +74,6 @@ class CheeseCardFragment : Fragment() {
7574
val cardContent: ConstraintLayout = view.findViewById(R.id.card_content)
7675
val image: ImageView = view.findViewById(R.id.image)
7776
val name: TextView = view.findViewById(R.id.name)
78-
val mirror: MirrorView = view.findViewById(R.id.article_mirror)
7977

8078
ViewCompat.setOnApplyWindowInsetsListener(view.parent as View) { _, insets ->
8179
toolbar.updateLayoutParams<AppBarLayout.LayoutParams> {
@@ -90,8 +88,6 @@ class CheeseCardFragment : Fragment() {
9088
}
9189

9290
ViewCompat.setTransitionName(card, "card")
93-
ViewCompat.setTransitionName(cardContent, "card_content")
94-
ViewCompat.setTransitionName(mirror, "article")
9591
ViewGroupCompat.setTransitionGroup(cardContent, true)
9692

9793
viewModel.cheese.observe(viewLifecycleOwner) { cheese ->
@@ -105,8 +101,6 @@ class CheeseCardFragment : Fragment() {
105101
CheeseCardFragmentDirections.actionArticle(cheese.id),
106102
FragmentNavigatorExtras(
107103
card to CheeseArticleFragment.TRANSITION_NAME_BACKGROUND,
108-
cardContent to CheeseArticleFragment.TRANSITION_NAME_CARD_CONTENT,
109-
mirror to CheeseArticleFragment.TRANSITION_NAME_ARTICLE_CONTENT
110104
)
111105
)
112106
}

Motion/app/src/main/java/com/example/android/motion/demo/navfadethrough/CheeseCardViewModel.kt renamed to Motion/app/src/main/java/com/example/android/motion/demo/containertransform/CheeseCardViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.example.android.motion.demo.navfadethrough
17+
package com.example.android.motion.demo.containertransform
1818

1919
import androidx.lifecycle.LiveData
2020
import androidx.lifecycle.MutableLiveData

Motion/app/src/main/java/com/example/android/motion/demo/navfadethrough/NavFadeThroughActivity.kt renamed to Motion/app/src/main/java/com/example/android/motion/demo/containertransform/ContainerTransformActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.example.android.motion.demo.navfadethrough
17+
package com.example.android.motion.demo.containertransform
1818

1919
import android.os.Bundle
2020
import androidx.appcompat.app.AppCompatActivity
2121
import com.example.android.motion.R
2222
import com.example.android.motion.ui.EdgeToEdge
2323

24-
class NavFadeThroughActivity : AppCompatActivity() {
24+
class ContainerTransformActivity : AppCompatActivity() {
2525

2626
override fun onCreate(savedInstanceState: Bundle?) {
2727
super.onCreate(savedInstanceState)
28-
setContentView(R.layout.nav_fade_through_activity)
28+
setContentView(R.layout.container_transform_activity)
2929
EdgeToEdge.setUpRoot(findViewById(R.id.nav_host))
3030
}
3131
}

Motion/app/src/main/res/layout/cheese_article_fragment.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
android:elevation="1dp"
2626
tools:targetApi="21">
2727

28-
<com.example.android.motion.demo.sharedelement.MirrorView
29-
android:id="@+id/card_mirror"
30-
android:layout_width="match_parent"
31-
android:layout_height="match_parent" />
32-
3328
<androidx.coordinatorlayout.widget.CoordinatorLayout
3429
android:id="@+id/coordinator"
3530
android:layout_width="match_parent"

Motion/app/src/main/res/layout/cheese_card_fragment.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
android:id="@+id/toolbar"
3333
android:layout_width="match_parent"
3434
android:layout_height="?attr/actionBarSize"
35-
app:title="@string/nav_fade_through_label" />
35+
app:title="@string/container_transform_label" />
3636

3737
</com.google.android.material.appbar.AppBarLayout>
3838

@@ -49,11 +49,6 @@
4949
android:layout_gravity="center"
5050
android:layout_margin="@dimen/spacing_small">
5151

52-
<com.example.android.motion.demo.sharedelement.MirrorView
53-
android:id="@+id/article_mirror"
54-
android:layout_width="match_parent"
55-
android:layout_height="match_parent" />
56-
5752
<androidx.constraintlayout.widget.ConstraintLayout
5853
android:id="@+id/card_content"
5954
android:layout_width="match_parent"

0 commit comments

Comments
 (0)