[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predictive back MaterialSharedAxis sample #156

Merged
merged 7 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions samples/user-interface/predictiveback/.idea/migrations.xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this file from the commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions samples/user-interface/predictiveback/.idea/misc.xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this file from the commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions samples/user-interface/predictiveback/.idea/vcs.xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this file from the commit

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions samples/user-interface/predictiveback/.idea/workspace.xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this file from the commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -63,6 +63,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 +90,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,67 @@
/*
* 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.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.FragmentNavigatorExtras
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this import as it is unused

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import androidx.navigation.fragment.findNavController
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)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Log.d("material", "Inside material shared axis fragment")

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

val predictiveBackCallback = object : OnBackPressedCallback(true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the callback, a callback is not needed to run cross-fragment animations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}

requireActivity().onBackPressedDispatcher.addCallback(
this.viewLifecycleOwner,
predictiveBackCallback
)
}

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>
Loading