-
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.
[#254] Allow to customize dialog through a bottom sheet
- Loading branch information
Showing
5 changed files
with
103 additions
and
107 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
91 changes: 91 additions & 0 deletions
91
demo/src/main/java/com/orange/ods/demo/ui/components/dialogs/ComponentDialog.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,91 @@ | ||
/* | ||
* | ||
* 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.dialogs | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.rememberBottomSheetScaffoldState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
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.OdsButtonContainedStyle | ||
import com.orange.ods.compose.component.dialog.OdsAlertDialog | ||
import com.orange.ods.compose.text.OdsTextBody1 | ||
import com.orange.ods.demo.R | ||
import com.orange.ods.demo.ui.components.buttons.fullWidthButton | ||
import com.orange.ods.demo.ui.components.utilities.ComponentCustomizationBottomSheetScaffold | ||
import com.orange.ods.demo.ui.components.utilities.clickOnElement | ||
import com.orange.ods.demo.ui.utilities.composable.SwitchListItem | ||
|
||
@ExperimentalMaterialApi | ||
@Composable | ||
fun ComponentDialog() { | ||
val customizationState = rememberDialogCustomizationState() | ||
|
||
val closeDialogAction = { customizationState.openDialog.value = false } | ||
val context = LocalContext.current | ||
|
||
ComponentCustomizationBottomSheetScaffold( | ||
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(), | ||
bottomSheetContent = { | ||
SwitchListItem(labelRes = R.string.component_element_title, checked = customizationState.titleChecked) | ||
SwitchListItem(labelRes = R.string.component_dialog_element_dismiss_button, checked = customizationState.dismissButtonChecked) | ||
}) { | ||
Column( | ||
modifier = Modifier | ||
.verticalScroll(rememberScrollState()) | ||
.padding(top = dimensionResource(id = R.dimen.ods_screen_vertical_margin), bottom = dimensionResource(id = R.dimen.spacing_s)) | ||
) { | ||
|
||
OdsTextBody1( | ||
modifier = Modifier | ||
.padding(horizontal = dimensionResource(id = R.dimen.ods_screen_horizontal_margin)), | ||
text = stringResource(id = R.string.component_dialog_customize) | ||
) | ||
|
||
OdsButton( | ||
modifier = Modifier.fullWidthButton(), | ||
text = stringResource(id = R.string.component_dialog_open), | ||
style = OdsButtonContainedStyle.Primary, | ||
onClick = { | ||
customizationState.openDialog.value = true | ||
} | ||
) | ||
|
||
if (customizationState.shouldOpenDialog) { | ||
val confirmButtonText = | ||
stringResource(id = if (customizationState.isDismissButtonChecked) R.string.component_dialog_action_confirm else R.string.component_dialog_action_ok) | ||
val dismissButtonText = stringResource(id = R.string.component_dialog_action_dismiss) | ||
|
||
OdsAlertDialog( | ||
titleText = if (customizationState.isTitleChecked) stringResource(id = R.string.component_element_title) else null, | ||
text = stringResource(id = R.string.component_dialog_text), | ||
confirmButtonText = confirmButtonText, | ||
onConfirmButtonClick = { | ||
clickOnElement(context = context, clickedElement = confirmButtonText) | ||
closeDialogAction() | ||
}, | ||
dismissButtonText = if (customizationState.isDismissButtonChecked) dismissButtonText else null, | ||
onDismissButtonClick = { | ||
clickOnElement(context = context, clickedElement = dismissButtonText) | ||
closeDialogAction() | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
} |
100 changes: 0 additions & 100 deletions
100
demo/src/main/java/com/orange/ods/demo/ui/components/dialogs/ComponentDialogs.kt
This file was deleted.
Oops, something went wrong.
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