From 68bbf5b2d35c25000b4ab2ea998f6696423e4160 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 20 Jan 2023 16:36:52 +0100 Subject: [PATCH] Animate swipe down to close images --- .../android/fragments/ImageFragment.kt | 26 +++++++++--- .../src/main/res/layout/fragment_image.xml | 14 +++---- .../src/main/res/xml/image_close_scene.xml | 41 +++++++++++++++++++ 3 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 androidApp/src/main/res/xml/image_close_scene.xml diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt index 09cecd0..1060167 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.constraintlayout.motion.widget.MotionLayout import androidx.fragment.app.Fragment import bou.amine.apps.readerforselfossv2.android.databinding.FragmentImageBinding import com.bumptech.glide.Glide @@ -27,11 +28,6 @@ class ImageFragment : Fragment() { _binding = FragmentImageBinding.inflate(inflater, container, false) val view = binding?.root - binding?.swipeRefreshLayout?.setProgressViewEndTarget(false, 0) - binding?.swipeRefreshLayout?.setOnRefreshListener { - activity?.finish() - } - binding!!.photoView.visibility = View.VISIBLE Glide.with(requireActivity()) .asBitmap() @@ -39,6 +35,26 @@ class ImageFragment : Fragment() { .load(imageUrl) .into(binding!!.photoView) + val transitionListener = object : MotionLayout.TransitionListener { + override fun onTransitionStarted(motionLayout: MotionLayout?, startId: Int, endId: Int) { + // Nothing + } + + override fun onTransitionChange(motionLayout: MotionLayout?, startId: Int, endId: Int, progress: Float + ) { + // Nothing + } + + override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) { + activity?.finish() + } + + override fun onTransitionTrigger(motionLayout: MotionLayout?, triggerId: Int, positive: Boolean, progress: Float) { + // Nothing + } + } + binding!!.root.setTransitionListener(transitionListener) + return view } diff --git a/androidApp/src/main/res/layout/fragment_image.xml b/androidApp/src/main/res/layout/fragment_image.xml index da5fc86..907501c 100644 --- a/androidApp/src/main/res/layout/fragment_image.xml +++ b/androidApp/src/main/res/layout/fragment_image.xml @@ -1,13 +1,10 @@ - - - + android:layout_height="match_parent" + app:layoutDescription="@xml/image_close_scene"> - - \ No newline at end of file + \ No newline at end of file diff --git a/androidApp/src/main/res/xml/image_close_scene.xml b/androidApp/src/main/res/xml/image_close_scene.xml new file mode 100644 index 0000000..77fbc6b --- /dev/null +++ b/androidApp/src/main/res/xml/image_close_scene.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file