-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331 from Orange-OpenSource/114-ods-component-toas…
…t-snackbar 114 - ods component - snackbar
- Loading branch information
Showing
27 changed files
with
386 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
demo/src/main/java/com/orange/ods/demo/ui/components/snackbars/ComponentSnackbars.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* | ||
* Copyright 2021 Orange | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
* / | ||
*/ | ||
|
||
package com.orange.ods.demo.ui.components.snackbars | ||
|
||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.rememberBottomSheetScaffoldState | ||
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() | ||
|
||
val actionButtonChecked = rememberSaveable { mutableStateOf(false) } | ||
val actionOnNewLineChecked = rememberSaveable { mutableStateOf(false) } | ||
if (!actionButtonChecked.value) { | ||
actionOnNewLineChecked.value = false | ||
} | ||
|
||
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, onActionClick = { | ||
clickOnElement(context = context, clickedElement = snackbarActionButton) | ||
}) | ||
} | ||
}, | ||
bottomSheetContent = { | ||
SwitchListItem(labelRes = R.string.component_snackbar_action_button, checked = actionButtonChecked) | ||
SwitchListItem(labelRes = R.string.component_snackbar_action_on_new_line, checked = actionOnNewLineChecked, enabled = actionButtonChecked.value) | ||
}) { | ||
ComponentLaunchContentColumn(textRes = R.string.component_snackbar_customize, buttonLabelRes = R.string.component_snackbar_show) { | ||
coroutineScope.launch { | ||
bottomSheetScaffoldState.snackbarHostState.showSnackbar( | ||
message = snackbarMessage, | ||
actionLabel = if (actionButtonChecked.value) snackbarActionLabel else null, | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...src/main/java/com/orange/ods/demo/ui/components/utilities/ComponentLaunchContentColumn.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* | ||
* Copyright 2021 Orange | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
* / | ||
*/ | ||
|
||
package com.orange.ods.demo.ui.components.utilities | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.res.stringResource | ||
import com.orange.ods.compose.component.button.OdsButton | ||
import com.orange.ods.compose.component.button.OdsButtonStyle | ||
import com.orange.ods.compose.text.OdsTextBody1 | ||
import com.orange.ods.demo.R | ||
|
||
@Composable | ||
fun ComponentLaunchContentColumn(@StringRes textRes: Int, @StringRes buttonLabelRes: Int, onButtonClick: () -> Unit) { | ||
Column( | ||
modifier = Modifier | ||
.verticalScroll(rememberScrollState()) | ||
.padding(top = dimensionResource(id = R.dimen.screen_vertical_margin), bottom = dimensionResource(id = R.dimen.spacing_s)) | ||
) { | ||
|
||
OdsTextBody1( | ||
modifier = Modifier | ||
.padding(horizontal = dimensionResource(id = R.dimen.screen_horizontal_margin)), | ||
text = stringResource(id = textRes) | ||
) | ||
|
||
OdsButton( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = dimensionResource(R.dimen.screen_horizontal_margin)) | ||
.padding(top = dimensionResource(R.dimen.spacing_m)), | ||
text = stringResource(id = buttonLabelRes), | ||
style = OdsButtonStyle.Primary, | ||
onClick = onButtonClick | ||
) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.