igreenwood / loupe

Twitter-like Android image viewer library
https://medium.com/@issei_greenwood/introducing-loupe-10-minutes-to-implement-twitter-like-image-viewer-19c522db3c68
296 stars 33 forks source link

View state is not cleared on dismiss #8

Closed edenman closed 4 years ago

edenman commented 4 years ago

Describe the bug I use a single-activity architecture with no fragments. I want to show an image viewer inside one of my screen views, dismiss it, and then show it again using the same ImageView. If I do that with the sample code provided, the imageview is not shown the second time you launch it.

Workaround

  private fun showImageViewer(destination: ViewImage) {
    binding.imageViewer.visibility = VISIBLE
    binding.imageViewer.load(destination.url) {
      listener(onSuccess = { _, _ ->
        binding.imageViewerContainer.visibility = VISIBLE
        val loupe = Loupe(binding.imageViewer, binding.imageViewer.parent as ViewGroup)
        loupe.onViewTranslateListener = object : Loupe.OnViewTranslateListener {
          override fun onDismiss(view: ImageView) {
            binding.imageViewerContainer.visibility = INVISIBLE
            binding.imageViewerContainer.removeOnLayoutChangeListener(loupe)
            binding.imageViewerContainer.setOnTouchListener(null)
            binding.imageViewer.imageMatrix = null
            binding.imageViewer.y = 0f
            binding.imageViewer.animate().cancel()
            loupe.onViewTranslateListener = null
          }

          override fun onRestore(view: ImageView) {
          }

          override fun onStart(view: ImageView) {
          }

          override fun onViewTranslate(view: ImageView, amount: Float) {
          }
        }
      })
    }
  }

Expected behavior It would be much nicer if Loupe cleaned up after itself after onDismiss is called.

Environment

igreenwood commented 4 years ago

Thank you for reporting ! I will investigate it this weekend 💪

edenman commented 4 years ago

Thanks for the quick turnaround, new version works great :)