-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdds-acore/uikit): Cell was implemented for compose (#274)
- Loading branch information
1 parent
006e531
commit 186f153
Showing
35 changed files
with
1,944 additions
and
27 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
111 changes: 111 additions & 0 deletions
111
...nd/sandbox-compose/src/main/kotlin/com/sdds/playground/sandbox/cell/compose/CellScreen.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,111 @@ | ||
package com.sdds.playground.sandbox.cell.compose | ||
|
||
import androidx.compose.foundation.focusable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.interaction.collectIsFocusedAsState | ||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import com.sdds.compose.uikit.Avatar | ||
import com.sdds.compose.uikit.Cell | ||
import com.sdds.compose.uikit.CheckBox | ||
import com.sdds.compose.uikit.Icon | ||
import com.sdds.compose.uikit.RadioBox | ||
import com.sdds.compose.uikit.Switch | ||
import com.sdds.compose.uikit.internal.focusselector.LocalFocusSelectorMode | ||
import com.sdds.compose.uikit.internal.focusselector.applyFocusSelector | ||
import com.sdds.playground.sandbox.SandboxTheme | ||
import com.sdds.playground.sandbox.Theme | ||
import com.sdds.playground.sandbox.core.compose.ComponentScaffold | ||
|
||
@Composable | ||
internal fun CellScreen(theme: Theme.ThemeInfoCompose = Theme.composeDefault) { | ||
val cellViewModel: CellViewModel = | ||
viewModel( | ||
factory = CellViewModelFactory(CellUiState(), theme), | ||
key = theme.toString(), | ||
) | ||
val uiState by cellViewModel.uiState.collectAsState() | ||
|
||
ComponentScaffold( | ||
component = { | ||
theme.themeWrapper { | ||
val interactionSource = remember { MutableInteractionSource() } | ||
val isFocused = interactionSource.collectIsFocusedAsState() | ||
Cell( | ||
modifier = Modifier | ||
.focusable(interactionSource = interactionSource) | ||
.applyFocusSelector( | ||
focusSelectorMode = LocalFocusSelectorMode.current, | ||
) { isFocused.value }, | ||
style = cellViewModel | ||
.getStyleProvider() | ||
.style(uiState.variant), | ||
title = AnnotatedString(uiState.title), | ||
subtitle = AnnotatedString(uiState.subtitle), | ||
label = AnnotatedString(uiState.label), | ||
disclosureEnabled = uiState.hasDisclosure, | ||
disclosureText = AnnotatedString(uiState.disclosureText), | ||
startContent = cellContent(contentType = uiState.startContent), | ||
endContent = cellContent(contentType = uiState.endContent), | ||
interactionSource = interactionSource, | ||
) | ||
} | ||
}, | ||
propertiesOwner = cellViewModel, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun cellContent(contentType: CellContent): (@Composable RowScope.() -> Unit)? { | ||
return if (contentType != CellContent.NONE) { | ||
{ | ||
when (contentType) { | ||
CellContent.AVATAR -> Avatar( | ||
painter = painterResource(id = com.sdds.icons.R.drawable.ic_scribble_diagonal_24), | ||
) | ||
|
||
CellContent.ICON -> Icon( | ||
painter = painterResource(id = com.sdds.icons.R.drawable.ic_scribble_diagonal_24), | ||
contentDescription = "", | ||
) | ||
|
||
CellContent.SWITCH -> @Composable { | ||
var active by remember { mutableStateOf(false) } | ||
Switch(active = active, onActiveChanged = { active = it }) | ||
} | ||
|
||
CellContent.CHECKBOX -> @Composable { | ||
var checked by remember { mutableStateOf(false) } | ||
CheckBox(checked = checked, onCheckedChange = { checked = it }) | ||
} | ||
|
||
CellContent.RADIOBOX -> @Composable { | ||
var checked by remember { mutableStateOf(false) } | ||
RadioBox(checked = checked, onClick = { checked = true }) | ||
} | ||
|
||
CellContent.NONE -> {} | ||
} | ||
} | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
internal fun CellScreenPreview() { | ||
SandboxTheme { | ||
CellScreen() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...d/sandbox-compose/src/main/kotlin/com/sdds/playground/sandbox/cell/compose/CellUiState.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,27 @@ | ||
package com.sdds.playground.sandbox.cell.compose | ||
|
||
import com.sdds.playground.sandbox.core.compose.UiState | ||
|
||
internal data class CellUiState( | ||
override val variant: String = "", | ||
val label: String = "Label", | ||
val title: String = "Title", | ||
val subtitle: String = "Subtitle", | ||
val hasDisclosure: Boolean = true, | ||
val disclosureText: String = "", | ||
val startContent: CellContent = CellContent.AVATAR, | ||
val endContent: CellContent = CellContent.NONE, | ||
) : UiState { | ||
override fun updateVariant(variant: String): UiState { | ||
return copy(variant = variant) | ||
} | ||
} | ||
|
||
internal enum class CellContent { | ||
NONE, | ||
AVATAR, | ||
ICON, | ||
SWITCH, | ||
CHECKBOX, | ||
RADIOBOX, | ||
} |
85 changes: 85 additions & 0 deletions
85
...sandbox-compose/src/main/kotlin/com/sdds/playground/sandbox/cell/compose/CellViewModel.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,85 @@ | ||
package com.sdds.playground.sandbox.cell.compose | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.sdds.compose.uikit.CellStyle | ||
import com.sdds.playground.sandbox.Theme | ||
import com.sdds.playground.sandbox.core.compose.ComponentViewModel | ||
import com.sdds.playground.sandbox.core.compose.Property | ||
import com.sdds.playground.sandbox.core.compose.enumProperty | ||
import com.sdds.playground.sandbox.core.integration.ComposeStyleProvider | ||
|
||
internal class CellViewModel( | ||
defaultState: CellUiState, | ||
private val theme: Theme.ThemeInfoCompose, | ||
) : ComponentViewModel<CellUiState, CellStyle>(defaultState) { | ||
|
||
override fun getStyleProvider(): ComposeStyleProvider<String, CellStyle> { | ||
return theme.stylesProvider.cell | ||
} | ||
|
||
override fun CellUiState.toProps(): List<Property<*>> { | ||
return listOfNotNull( | ||
Property.StringProperty( | ||
name = "label", | ||
value = label, | ||
onApply = { | ||
internalUiState.value = internalUiState.value.copy(label = it) | ||
}, | ||
), | ||
Property.StringProperty( | ||
name = "title", | ||
value = title, | ||
onApply = { | ||
internalUiState.value = internalUiState.value.copy(title = it) | ||
}, | ||
), | ||
Property.StringProperty( | ||
name = "subtitle", | ||
value = subtitle, | ||
onApply = { | ||
internalUiState.value = internalUiState.value.copy(subtitle = it) | ||
}, | ||
), | ||
Property.StringProperty( | ||
name = "disclosureText", | ||
value = disclosureText, | ||
onApply = { | ||
internalUiState.value = internalUiState.value.copy(disclosureText = it) | ||
}, | ||
), | ||
Property.BooleanProperty( | ||
name = "hasDisclosure", | ||
value = hasDisclosure, | ||
onApply = { | ||
internalUiState.value = internalUiState.value.copy(hasDisclosure = it) | ||
}, | ||
), | ||
enumProperty( | ||
name = "startContent", | ||
value = startContent, | ||
onApply = { | ||
internalUiState.value = internalUiState.value.copy(startContent = it) | ||
}, | ||
), | ||
enumProperty( | ||
name = "endContent", | ||
value = endContent, | ||
onApply = { | ||
internalUiState.value = internalUiState.value.copy(endContent = it) | ||
}, | ||
), | ||
) | ||
} | ||
} | ||
|
||
internal class CellViewModelFactory( | ||
private val defaultState: CellUiState, | ||
private val theme: Theme.ThemeInfoCompose, | ||
) : ViewModelProvider.Factory { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
return CellViewModel(defaultState, theme) as T | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...andbox/plasma/sd/service/integration/cell/compose/PlasmaSdServiceCellVariationsCompose.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,21 @@ | ||
package com.sdds.playground.sandbox.plasma.sd.service.integration.cell.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.sdds.compose.uikit.Cell | ||
import com.sdds.compose.uikit.CellStyle | ||
import com.sdds.compose.uikit.style.style | ||
import com.sdds.plasma.sd.service.styles.cell.L | ||
import com.sdds.plasma.sd.service.styles.cell.M | ||
import com.sdds.plasma.sd.service.styles.cell.S | ||
import com.sdds.plasma.sd.service.styles.cell.Xs | ||
import com.sdds.playground.sandbox.core.integration.ComposeStyleProvider | ||
|
||
internal object PlasmaSdServiceCellVariationsCompose : ComposeStyleProvider<String, CellStyle>() { | ||
override val variations: Map<String, @Composable () -> CellStyle> = | ||
mapOf( | ||
"L" to { Cell.L.style() }, | ||
"M" to { Cell.M.style() }, | ||
"S" to { Cell.S.style() }, | ||
"Xs" to { Cell.Xs.style() }, | ||
) | ||
} |
2 changes: 1 addition & 1 deletion
2
...cell/PlasmaSdServiceCellVariationsView.kt → ...l/vs/PlasmaSdServiceCellVariationsView.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
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
Oops, something went wrong.