[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge branch 'github/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Automerger committed Mar 26, 2024
2 parents ea3bfe0 + f4e1982 commit f3858b0
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ androidxTestRunner = "1.5.2"
androidxUiAutomator = "2.2.0"
media3 = "1.2.1"
appcompat = "1.6.1"
material = "1.11.0"
material = "1.12.0-beta01"
constraintlayout = "2.1.4"

[libraries]
Expand Down
31 changes: 31 additions & 0 deletions samples/user-interface/predictiveback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Shows different types of predictive back animations, including:
+ Shared element cross-fragment animation
+ Custom Progress API animation
+ Custom AndroidX Transition
+ Cross-fragment animation with MaterialSharedAxis

## Custom cross-activity

Expand Down Expand Up @@ -207,3 +208,33 @@ class MyFragment : Fragment() {
}
```

## Cross-fragment animation with MaterialSharedAxis

MaterialSharedAxis is a Visibility transition. A Visibility transition is triggered when the target
Fragment's visibility is changed or when the Fragment is added or removed. This means MaterialSharedAxis
requires a View to be changing in visibility or to be added or removed to trigger its animation.

For more details see the
[developer documentation](https://m2.material.io/develop/android/theming/motion#shared-axis).

```kotlin
// FragmentA.kt

override fun onCreateView(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

exitTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ true)
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ false)
}

// FragmentB.kt

override fun onCreateView(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ true)
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ false)
}
```


Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ enum class PBAnimation {
CROSS_FRAGMENT,
SHARED_ELEMENT_CROSS_FRAGMENT,
PROGRESS_API,
TRANSITION
TRANSITION,
MATERIAL_SHARED_AXIS
}
data class PBAnimationText(val title: String, val description: String)

Expand Down Expand Up @@ -60,5 +61,9 @@ val animations = mapOf<PBAnimation, PBAnimationText>(
PBAnimation.TRANSITION to PBAnimationText(
"Transition",
"Click to see an animation created with AndroidX Transitions and the Predictive Back Progress API."
),
PBAnimation.MATERIAL_SHARED_AXIS to PBAnimationText(
"Material Shared Axis",
"Click to see an animation created with Material Shared Axis."
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.fragment.app.Fragment
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.navigation.fragment.findNavController
import com.example.platform.ui.predictiveback.databinding.FragmentAnimationListBinding
import com.google.android.material.transition.MaterialSharedAxis

class PBListFragment : Fragment() {

Expand All @@ -37,6 +38,10 @@ class PBListFragment : Fragment() {

setAnimationText()

exitTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ true)
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ false)


return binding.root
}

Expand All @@ -63,6 +68,9 @@ class PBListFragment : Fragment() {
binding.transitionsCard.setOnClickListener {
findNavController().navigate(R.id.show_PBTransition)
}
binding.materialSharedAxisCard.setOnClickListener {
findNavController().navigate(R.id.show_PBMaterialSharedAxisAnimations)
}
}

override fun onDestroyView() {
Expand All @@ -87,5 +95,7 @@ class PBListFragment : Fragment() {
binding.progressApiDescription.text = animations[PBAnimation.PROGRESS_API]?.description ?: ""
binding.transitionsTitle.text = animations[PBAnimation.TRANSITION]?.title ?: ""
binding.transitionsDescription.text = animations[PBAnimation.TRANSITION]?.description ?: ""
binding.materialSharedAxisTitle.text = animations[PBAnimation.MATERIAL_SHARED_AXIS]?.title ?: ""
binding.materialSharedAxisDescription.text = animations[PBAnimation.MATERIAL_SHARED_AXIS]?.description ?: ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.platform.ui.predictiveback

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.platform.ui.predictiveback.databinding.FragmentMaterialSharedAxisBinding
import com.google.android.material.transition.MaterialSharedAxis

class PBMaterialSharedAxisAnimations : Fragment() {

private var _binding: FragmentMaterialSharedAxisBinding? = null
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
_binding = FragmentMaterialSharedAxisBinding
.inflate(inflater, container, false)

enterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ true)
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ false)

return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,42 @@

</com.google.android.material.card.MaterialCardView>

<com.google.android.material.card.MaterialCardView
android:id="@+id/material_shared_axis_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
style="?attr/materialCardViewFilledStyle">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/material_shared_axis_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:textAppearance="?attr/textAppearanceTitleMedium"
android:textSize="16sp"/>

<TextView
android:id="@+id/material_shared_axis_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp" />

</LinearLayout>

</com.google.android.material.card.MaterialCardView>


</LinearLayout>

</ScrollView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2023 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
tools:context=".PBMaterialSharedAxisAnimations">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fragment_header"
android:textAppearance="?attr/textAppearanceTitleMedium"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/box"
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@drawable/box"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="300dp"
android:fontFamily="sans-serif"
android:text="@string/fragment_material_shared_axis_body"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/box"
app:layout_constraintStart_toStartOf="@+id/box"
app:layout_constraintTop_toBottomOf="@+id/box" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<action
android:id="@+id/show_PBSharedElementTransitionFragment"
app:destination="@id/PBSharedElementTransitionFragment" />
<action
android:id="@+id/show_PBMaterialSharedAxisAnimations"
app:destination="@id/PBMaterialSharedAxisAnimations" />
</fragment>
<fragment
android:id="@+id/PBNavigationComponentDefaultAnimations"
Expand All @@ -69,4 +72,9 @@
android:name="com.example.platform.ui.predictiveback.PBSharedElementTransitionFragment"
android:label="fragment_shared_element_transition"
tools:layout="@layout/fragment_shared_element_transition" />
<fragment
android:id="@+id/PBMaterialSharedAxisAnimations"
android:name="com.example.platform.ui.predictiveback.PBMaterialSharedAxisAnimations"
android:label="fragment_material_shared_axis"
tools:layout="@layout/fragment_material_shared_axis" />
</navigation>
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec luctus est at sollicitudin gravida. Donec nec augue consectetur, vulputate massa nec, aliquam tortor. Aliquam vestibulum enim gravida massa pretium, tristique blandit nisi sagittis. Nulla facilisi. Cras erat mi, ultrices ut vulputate eu, sagittis suscipit augue. Pellentesque varius elit sit amet nisl suscipit sollicitudin. Sed non tortor fermentum, iaculis erat vel, vestibulum elit. Integer hendrerit tortor eget urna vulputate hendrerit. Integer consequat cursus sem sed fringilla. Fusce ac sodales dolor. Phasellus eleifend lacus sed libero luctus, fringilla pharetra odio lobortis. Fusce quis sapien ac nulla venenatis congue mollis aliquet nulla. Nunc commodo ipsum in leo rutrum ultrices. Nunc tincidunt neque quam, a dictum nisl sagittis vel.
</string>
<string name="sharedElementTransitionText">Swipe back to see a shared element Predictive Back transition.</string>
<string name="fragment_material_shared_axis_body">Swipe back to see a Material Shared Axis transition.</string>
</resources>

0 comments on commit f3858b0

Please sign in to comment.