Skip to content

Commit

Permalink
[#114] Review: Add parameter to set onActionClick
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinea authored and florentmaitre committed Nov 23, 2022
1 parent 7923bb7 commit abd17b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.orange.ods.compose.component.snackbar.OdsSnackbar
import com.orange.ods.compose.component.snackbar.OdsSnackbarHost
import com.orange.ods.demo.R
import com.orange.ods.demo.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.demo.ui.components.utilities.ComponentLaunchContentColumn
import com.orange.ods.demo.ui.components.utilities.clickOnElement
import com.orange.ods.demo.ui.utilities.composable.SwitchListItem
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun ComponentSnackbars() {
val context = LocalContext.current
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState()
val coroutineScope: CoroutineScope = rememberCoroutineScope()

Expand All @@ -40,12 +43,15 @@ fun ComponentSnackbars() {

val snackbarMessage = stringResource(id = R.string.component_snackbar_message)
val snackbarActionLabel = stringResource(id = R.string.component_snackbar_action_label)
val snackbarActionButton = stringResource(id = R.string.component_snackbar_action_button)

ComponentCustomizationBottomSheetScaffold(
bottomSheetScaffoldState = bottomSheetScaffoldState,
snackbarHost = {
OdsSnackbarHost(hostState = it) { data ->
OdsSnackbar(snackbarData = data, actionOnNewLine = actionOnNewLineChecked.value)
OdsSnackbar(snackbarData = data, actionOnNewLine = actionOnNewLineChecked.value, onActionClick = {
clickOnElement(context = context, clickedElement = snackbarActionButton)
})
}
},
bottomSheetContent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ import com.orange.ods.compose.theme.OdsTheme
*
* @param message text displayed in the snackbar
* @param modifier modifiers for the Snackbar layout
* @param actionLabel If set, it displays an [OdsTextButton] with the given [actionLabel] as an action of the snackbar.
* @param actionLabel if set, it displays an [OdsTextButton] with the given [actionLabel] as an action of the snackbar.
* @param actionOnNewLine whether or not action should be put on the separate line. Recommended
* for action with long action text
* @param onActionClick executed on action button click.
*/
@Composable
@OdsComponentApi
fun OdsSnackbar(
message: String,
modifier: Modifier = Modifier,
actionLabel: String? = null,
actionOnNewLine: Boolean = false
actionOnNewLine: Boolean = false,
onActionClick: () -> Unit = {}
) {
Snackbar(
modifier = modifier,
Expand All @@ -62,7 +64,8 @@ fun OdsSnackbar(
style = OdsTextButtonStyle.Primary,
displaySurface = OdsSnackbarDefaults.actionButtonDisplaySurface,
text = it,
onClick = {})
onClick = onActionClick
)
}
},
actionOnNewLine = actionOnNewLine,
Expand All @@ -80,18 +83,21 @@ fun OdsSnackbar(
* @param modifier modifiers for the Snackbar layout
* @param actionOnNewLine whether or not action should be put on the separate line. Recommended
* for action with long action text
* @param onActionClick executed on action button click.
*/
@Composable
fun OdsSnackbar(
snackbarData: SnackbarData,
modifier: Modifier = Modifier,
actionOnNewLine: Boolean = false
actionOnNewLine: Boolean = false,
onActionClick: () -> Unit = {}
) {
OdsSnackbar(
modifier = modifier,
message = snackbarData.message,
actionLabel = snackbarData.actionLabel,
actionOnNewLine = actionOnNewLine
actionOnNewLine = actionOnNewLine,
onActionClick = onActionClick
)
}

Expand Down

0 comments on commit abd17b3

Please sign in to comment.