Skip to content

Commit

Permalink
ANDROAPP-5692-mobile-ui-Add-onImageClick-callback-to-ImageBlock-compo…
Browse files Browse the repository at this point in the history
…nent (#128)

* [ANDROAPP-5692] add clickable event and parameter to Input Image and Input Signature

* Fix tests

* add focus request on click events

* ktlint fix
  • Loading branch information
xavimolloy authored Oct 31, 2023
1 parent 389381a commit 0d44146
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fun ImageBlockScreen() {
load = { sampleImage },
painterFor = { remember { it } },
onClick = {},
onImageClick = {},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fun InputImageScreen() {
uploadState = UploadState.LOADED
}
},
onImageClick = {},
)
Spacer(Modifier.size(Spacing.Spacing18))

Expand All @@ -60,6 +61,7 @@ fun InputImageScreen() {
onDownloadButtonClick = {},
onResetButtonClicked = {},
onAddButtonClicked = {},
onImageClick = {},
)
Spacer(Modifier.size(Spacing.Spacing18))

Expand All @@ -75,6 +77,7 @@ fun InputImageScreen() {
onDownloadButtonClick = {},
onResetButtonClicked = { },
onAddButtonClicked = {},
onImageClick = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fun InputSignatureScreen() {
uploadState = UploadState.LOADED
}
},
onImageClick = {},
)
Spacer(Modifier.size(Spacing.Spacing18))

Expand All @@ -60,6 +61,7 @@ fun InputSignatureScreen() {
onDownloadButtonClick = {},
onResetButtonClicked = {},
onAddButtonClicked = {},
onImageClick = {},
)
Spacer(Modifier.size(Spacing.Spacing18))

Expand All @@ -75,6 +77,7 @@ fun InputSignatureScreen() {
onDownloadButtonClick = {},
onResetButtonClicked = { },
onAddButtonClicked = {},
onImageClick = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Cancel
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.testTag
Expand Down Expand Up @@ -56,11 +59,14 @@ internal fun <T> BasicInputImage(
addButtonIcon: ImageVector,
modifier: Modifier = Modifier,
onDownloadButtonClick: () -> Unit,
onImageClick: () -> Unit,
onResetButtonClicked: () -> Unit,
onAddButtonClicked: () -> Unit,
) {
val focusRequester = remember { FocusRequester() }

InputShell(
modifier = modifier.testTag("INPUT_$testTag"),
modifier = modifier.testTag("INPUT_$testTag").focusRequester(focusRequester),
title = title,
state = state,
isRequiredField = isRequired,
Expand Down Expand Up @@ -100,6 +106,7 @@ internal fun <T> BasicInputImage(
.testTag("INPUT_" + testTag + "_ADD_BUTTON"),
) {
onAddButtonClicked.invoke()
focusRequester.requestFocus()
}
},
)
Expand Down Expand Up @@ -127,7 +134,10 @@ internal fun <T> BasicInputImage(
ImageBlock(
load = load,
painterFor = painterFor,
onClick = onDownloadButtonClick,
onClick = {
onDownloadButtonClick.invoke()
focusRequester.requestFocus()
},
downloadButtonVisible = downloadButtonVisible,
modifier = Modifier.padding(
end = if (state == InputShellState.DISABLED) {
Expand All @@ -136,6 +146,10 @@ internal fun <T> BasicInputImage(
Spacing.Spacing0
},
),
onImageClick = {
onImageClick.invoke()
focusRequester.requestFocus()
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hisp.dhis.mobile.ui.designsystem.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand Down Expand Up @@ -40,6 +41,7 @@ fun <T> ImageBlock(
painterFor: @Composable (T) -> Painter,
modifier: Modifier = Modifier,
downloadButtonVisible: Boolean = true,
onImageClick: () -> Unit,
onClick: () -> Unit,
) {
val image: T? by produceState<T?>(null) {
Expand All @@ -65,7 +67,8 @@ fun <T> ImageBlock(
modifier = Modifier
.fillMaxWidth()
.clip(shape = RoundedCornerShape(Radius.S))
.height(160.dp),
.height(160.dp)
.clickable { onImageClick.invoke() },
)
if (downloadButtonVisible) {
SquareIconButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fun <T> InputImage(
onDownloadButtonClick: () -> Unit,
onResetButtonClicked: () -> Unit,
onAddButtonClicked: () -> Unit,
onImageClick: () -> Unit,
) {
BasicInputImage(
title = title,
Expand All @@ -60,5 +61,6 @@ fun <T> InputImage(
onDownloadButtonClick = onDownloadButtonClick,
onResetButtonClicked = onResetButtonClicked,
onAddButtonClicked = onAddButtonClicked,
onImageClick = onImageClick,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fun <T> InputSignature(
onDownloadButtonClick: () -> Unit,
onResetButtonClicked: () -> Unit,
onAddButtonClicked: () -> Unit,
onImageClick: () -> Unit,
) {
BasicInputImage(
title = title,
Expand All @@ -60,5 +61,6 @@ fun <T> InputSignature(
onDownloadButtonClick = onDownloadButtonClick,
onResetButtonClicked = onResetButtonClicked,
onAddButtonClicked = onAddButtonClicked,
onImageClick = onImageClick,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class BasicInputImageTest {
},
onAddButtonClicked = {
},
onImageClick = {},
)
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
Expand All @@ -58,6 +59,7 @@ class BasicInputImageTest {
},
onAddButtonClicked = {
},
onImageClick = {},
)
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
Expand All @@ -80,6 +82,7 @@ class BasicInputImageTest {
},
onAddButtonClicked = {
},
onImageClick = {},
)
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
Expand All @@ -101,6 +104,7 @@ class BasicInputImageTest {
},
onAddButtonClicked = {
},
onImageClick = {},
)
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
Expand All @@ -123,6 +127,8 @@ class BasicInputImageTest {
},
onAddButtonClicked = {
},
onImageClick = {},

)
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
Expand All @@ -148,6 +154,8 @@ class BasicInputImageTest {
},
onAddButtonClicked = {
},
onImageClick = {},

)
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
Expand All @@ -174,6 +182,8 @@ class BasicInputImageTest {
},
onAddButtonClicked = {
},
onImageClick = {},

)
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
Expand All @@ -197,6 +207,7 @@ class BasicInputImageTest {
},
onAddButtonClicked = {
},
onImageClick = {},
)
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
Expand All @@ -220,6 +231,7 @@ class BasicInputImageTest {
},
onAddButtonClicked = {
},
onImageClick = {},
)
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ImageBlockTest {
load = { provideImage(File("")) },
painterFor = { BitmapPainter(it!!) },
onClick = {},
onImageClick = {},
)
}

Expand Down

0 comments on commit 0d44146

Please sign in to comment.