Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ class DrawingState {
fun resetCurrentPath() {
currentPath.value = Path()
}

fun clear() {
paths.clear()
resetCurrentPath()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import androidclient.feature.client.generated.resources.feature_client_signature
import androidclient.feature.client.generated.resources.feature_client_signature_uploaded_successfully
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -29,15 +32,13 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.boundsInRoot
Expand All @@ -46,12 +47,12 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.graphics.applyCanvas
import androidx.core.graphics.createBitmap
import com.mifos.core.designsystem.component.DrawingState
import com.mifos.core.designsystem.component.MifosCircularProgress
import com.mifos.core.designsystem.component.MifosDrawingCanvas
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.component.MifosSweetError
import com.mifos.core.designsystem.icon.MifosIcons
import com.mifos.core.designsystem.utility.PathState
import io.github.vinceglb.filekit.PlatformFile
import org.jetbrains.compose.resources.stringResource
import java.io.ByteArrayOutputStream
Expand All @@ -77,7 +78,7 @@ internal actual fun SignatureScreen(
val drawColor = Color.Black
val drawBrush = 5f

val paths = remember { mutableStateListOf<PathState>() }
val drawingState = remember { DrawingState() }

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! While rememberSaveable works great for primitive types (which it handles automatically), DrawingState uses non-serializable types like Path, so it would require a custom Saver. I explored that, but given users can easily re-sign if the screen rotates, the added complexity doesn’t offer much real value. Keeping it simple for now.

Reference: UI Logic with rememberSaveable

rememberSaveable stores UI element state in a Bundle through the saved instance state mechanism.

It is able to store primitive types to the bundle automatically. If your state is held in a type that is not primitive, like a data class, you can use different storing mechanisms, such as using the Parcelize annotation, using Compose APIs like listSaver and mapSaver, or implementing a custom saver class extending Compose runtime Saver class.


val galleryLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.GetContent(),
Expand Down Expand Up @@ -118,7 +119,7 @@ internal actual fun SignatureScreen(
onClick = {
navigationSelectedItem = index
when (index) {
0 -> paths.clear()
0 -> drawingState.clear()
1 -> galleryLauncher.launch("image/*")
}
},
Expand Down Expand Up @@ -149,8 +150,20 @@ internal actual fun SignatureScreen(
}

is SignatureUiState.Initial -> {
paths.add(PathState(Path(), drawColor, drawBrush))
MifosDrawingCanvas(drawColor = drawColor, drawBrush = drawBrush)
// Force white background here instead of relying on MaterialTheme
// Required to maintain consistent white canvas in both light and dark modes
// for legibility and official document compliance.
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.White),
) {
MifosDrawingCanvas(
drawColor = drawColor,
drawBrush = drawBrush,
drawingState = drawingState,
)
}
}
}
}
Expand Down