Skip to content

Commit

Permalink
[#254] Allow to customize switches through bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinea committed Sep 2, 2022
1 parent 871eb9d commit 87f5944
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,37 @@ 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.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import com.orange.ods.demo.R
import com.orange.ods.demo.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.demo.ui.utilities.composable.SwitchListItem
import com.orange.ods.demo.ui.utilities.composable.Title

@ExperimentalMaterialApi
@Composable
fun ComponentSwitches() {
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(bottom = dimensionResource(id = R.dimen.spacing_m))
) {
Title(textRes = R.string.component_switches_enabled, withHorizontalPadding = true)
SwitchListItem(
labelRes = R.string.component_element_item1,
checked = remember { mutableStateOf(true) }
)
val checked = rememberSaveable { mutableStateOf(false) }
val enabled = rememberSaveable { mutableStateOf(true) }

Title(textRes = R.string.component_switches_disabled, withHorizontalPadding = true)
SwitchListItem(
labelRes = R.string.component_element_item1,
checked = remember { mutableStateOf(true) },
enabled = false
)
SwitchListItem(
labelRes = R.string.component_element_item2,
checked = remember { mutableStateOf(false) },
enabled = false
)
ComponentCustomizationBottomSheetScaffold(
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
bottomSheetContent = {
SwitchListItem(labelRes = R.string.component_state_enabled, checked = enabled)
}) {
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(bottom = dimensionResource(id = R.dimen.spacing_m))
) {
SwitchListItem(
labelRes = R.string.component_element_label,
checked = checked,
enabled = enabled.value
)
}
}
}
4 changes: 1 addition & 3 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@
<!-- Component Switches -->
<string name="component_switches">Switches</string>
<string name="component_switches_description">On/off switches toggle the state of a single settings option. The function of the switch should be made clear by the inline label.</string>
<string name="component_switches_enabled">Enabled switches</string>
<string name="component_switches_disabled">Disabled switches</string>


<!-- Component Sliders -->
<string name="component_sliders">Sliders</string>
<string name="component_sliders_description">Sliders enable the user to set a value by moving the slider thumb. The lowest value is always on the left. Sliders can be either continuous or discrete, where the slider thumb snaps to evenly spaced tick marks along the slider rail.</string>
Expand Down

0 comments on commit 87f5944

Please sign in to comment.