Skip to content

Commit

Permalink
Fix: show toast when the signature is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Kariuki committed Oct 30, 2023
1 parent 6180961 commit afd5e75
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.joelkanyi.composesignature

import android.graphics.Bitmap
import android.view.MotionEvent
import android.widget.Toast
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -98,7 +99,7 @@ fun ComposeSignature(
) {
Column {
viewModel.setPathState(PathState(Path(), drawColor.value, drawBrush.value))

val context = LocalContext.current
val signatureBitmap = captureBitmap {
DrawingCanvas(
drawColor = drawColor,
Expand All @@ -119,12 +120,23 @@ fun ComposeSignature(
onClear()
viewModel.clearPathState()
}

completeComponent {
onComplete(
signatureBitmap.invoke().apply {
setHasAlpha(hasAlpha)
},
)
val isEmpty = path.value.last().path.isEmpty
if (isEmpty) {
Toast.makeText(
context,
"Signature is empty",
Toast.LENGTH_SHORT,
).show()
return@completeComponent
} else {
onComplete(
signatureBitmap.invoke().apply {
setHasAlpha(hasAlpha)
},
)
}
}
}
}
Expand Down

0 comments on commit afd5e75

Please sign in to comment.