Skip to content

Conversation

@HadiHabibza
Copy link

No description provided.

@premacck
Copy link

For people still waiting on this PR to be merged, I created a workaround, Which involves creating a class extending UCropActivity and foloowing code:

  • Add private var isReadyToFinish = true property
  • Add private lateinit var loader: MenuItem property to reference the top right loader and initialize it in onCreateOptionsMenu()
  override fun onCreateOptionsMenu(menu: Menu?): Boolean {
    val result = super.onCreateOptionsMenu(menu)
    loader = menu.findItem(R.id.menu_loader)!!
    return result
  }
  • Also, there's a blocking view set, to get a reference:
  private lateinit var blockingView: View
  //...

  override fun onStart() {
  //...
  blockingView = ucrop_photobox.getChildAt(ucrop_photobox.childCount - 1)  // Last view in the layout
  // ucrop_photobox is a kotlin extension reference to the R.id.ucrop_photobox ViewGroup in the ucrop_activity_photobox.xml file
  // You can override that file if you can't find the reference.
  }
  • Override setResultUri() function like this
  override fun setResultUri(uri: Uri?, resultAspectRatio: Float, offsetX: Int, offsetY: Int, imageWidth: Int, imageHeight: Int) {
    if (imageWidth in MIN_WIDTH .. MAX_WIDTH && imageHeight in MIN_HEIGHT .. MAX_HEIGHT) {
      isReadyToFinish = true
      super.setResultUri(uri, resultAspectRatio, offsetX, offsetY, imageWidth, imageHeight)
    } else {
      isReadyToFinish = false
      loader.isVisible = false
      blockingView.isClickable = false
      
      // Do whatever you want here, when the image dimensions are out of bounds
    }
  }

  override fun finish() {
    if (isReadyToFinish) {
      super.finish()
    }
  }```

I know it looks a little hack-ey but hey, it works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants