Skip to content

Commit

Permalink
feat: improve design of the sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Sep 19, 2024
1 parent 2282c19 commit 80ea0a5
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 30 deletions.
1 change: 1 addition & 0 deletions sample/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<string name="xml_feature_title">Android XML Support</string>
<string name="undoredo_feature_title">Undo/Redo</string>
<string name="decompose_feature_title">Decompose | Essenty Integration</string>
<string name="platform_feature_unavailable_label">Run the app on another platform to experience this feature</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Card
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.childContext
Expand All @@ -42,13 +44,14 @@ import pro.respawn.flowmvi.sample.features.decompose.pages.PagesComponentState.D
import pro.respawn.flowmvi.sample.features.decompose.pages.PagesIntent.SelectedPage
import pro.respawn.flowmvi.sample.navigation.util.Navigator
import pro.respawn.flowmvi.sample.navigation.util.backNavigator
import pro.respawn.flowmvi.sample.ui.theme.Opacity
import pro.respawn.flowmvi.sample.ui.widgets.CodeText
import pro.respawn.flowmvi.sample.ui.widgets.RErrorView
import pro.respawn.flowmvi.sample.ui.widgets.RFilledButton
import pro.respawn.flowmvi.sample.ui.widgets.RScaffold
import pro.respawn.flowmvi.sample.ui.widgets.TypeCrossfade
import pro.respawn.flowmvi.sample.util.adaptiveWidth
import pro.respawn.flowmvi.sample.util.formatAsMultiline
import pro.respawn.kmmutils.compose.windowsize.isWideScreen

private const val Description = """
This feature showcases FlowMVI <> Essenty integration.
Expand Down Expand Up @@ -148,21 +151,30 @@ private fun DecomposeScreenContent(
is DisplayingPages -> Column(
modifier = Modifier
.fillMaxHeight()
.adaptiveWidth()
.fillMaxWidth()
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = Description.formatAsMultiline(),
modifier = Modifier.padding(horizontal = 12.dp)
)

ChildPages(
pages = pagesComponent.pages,
onPageSelected = { pagesComponent.intent(SelectedPage(it)) },
modifier = Modifier.fillMaxSize(),
scrollAnimation = PagesScrollAnimation.Default,
pageContent = { _, page -> PageContent(page) },
)
if (isWideScreen) {
Text(
text = "On desktop, scroll while holding Shift or using a horizontal scroll wheel",
style = MaterialTheme.typography.labelLarge,
modifier = Modifier.padding(horizontal = 12.dp).alpha(Opacity.secondary)
)
Spacer(Modifier.height(12.dp))
}
CodeText(Code, modifier = Modifier.padding(horizontal = 12.dp))
Spacer(Modifier.navigationBarsPadding())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
Expand All @@ -27,7 +28,6 @@ import pro.respawn.flowmvi.sample.navigation.util.Navigator
import pro.respawn.flowmvi.sample.navigation.util.backNavigator
import pro.respawn.flowmvi.sample.ui.widgets.CodeText
import pro.respawn.flowmvi.sample.ui.widgets.RScaffold
import pro.respawn.flowmvi.sample.util.adaptiveWidth
import pro.respawn.flowmvi.sample.util.formatAsMultiline

private const val Description = """
Expand Down Expand Up @@ -94,7 +94,7 @@ fun DiConfigScreen(
private fun DiConfigScreenContent(state: PersistedCounterState) = Column(
modifier = Modifier
.fillMaxHeight()
.adaptiveWidth()
.fillMaxWidth()
.padding(horizontal = 12.dp)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -57,6 +58,7 @@ import pro.respawn.flowmvi.sample.lce_feature_title
import pro.respawn.flowmvi.sample.logging_feature_title
import pro.respawn.flowmvi.sample.navigation.AppNavigator
import pro.respawn.flowmvi.sample.navigation.util.backNavigator
import pro.respawn.flowmvi.sample.platform_feature_unavailable_label
import pro.respawn.flowmvi.sample.savedstate_feature_title
import pro.respawn.flowmvi.sample.simple_feature_title
import pro.respawn.flowmvi.sample.ui.theme.rainbow
Expand All @@ -65,9 +67,9 @@ import pro.respawn.flowmvi.sample.ui.widgets.RMenuItem
import pro.respawn.flowmvi.sample.ui.widgets.RScaffold
import pro.respawn.flowmvi.sample.ui.widgets.TypeCrossfade
import pro.respawn.flowmvi.sample.undoredo_feature_title
import pro.respawn.flowmvi.sample.util.adaptiveWidth
import pro.respawn.flowmvi.sample.util.platform
import pro.respawn.flowmvi.sample.xml_feature_title
import pro.respawn.kmmutils.compose.resources.string

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -104,7 +106,7 @@ private fun IntentReceiver<HomeIntent>.HomeScreenContent(
is DisplayingHome -> Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxHeight()
.adaptiveWidth()
.fillMaxWidth()
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.Top,
) {
Expand All @@ -126,6 +128,7 @@ private fun IntentReceiver<HomeIntent>.HomeScreenContent(
title = stringResource(item.title),
color = rainbow[i % rainbow.size],
icon = item.icon,
subtitle = item.subtitle?.string(),
onClick = { intent(ClickedFeature(item)) }
)
}
Expand Down Expand Up @@ -159,3 +162,5 @@ private val HomeFeature.icon
}

private val HomeFeature.enabled get() = platform == null || BuildFlags.platform == platform

private val HomeFeature.subtitle get() = Res.string.platform_feature_unavailable_label.takeIf { !enabled }
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
Expand Down Expand Up @@ -34,7 +35,6 @@ import pro.respawn.flowmvi.sample.ui.widgets.RFilledButton
import pro.respawn.flowmvi.sample.ui.widgets.RMenuItem
import pro.respawn.flowmvi.sample.ui.widgets.RScaffold
import pro.respawn.flowmvi.sample.ui.widgets.TypeCrossfade
import pro.respawn.flowmvi.sample.util.adaptiveWidth
import pro.respawn.flowmvi.sample.util.formatAsMultiline
import pro.respawn.flowmvi.sample.util.verticalListPaddings

Expand Down Expand Up @@ -112,7 +112,7 @@ private fun IntentReceiver<LCEIntent>.LCEScreenContent(
contentPadding = WindowInsets.verticalListPaddings(),
modifier = Modifier
.padding(horizontal = 12.dp)
.adaptiveWidth()
.fillMaxWidth()
) {
item {
Column(modifier = Modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import pro.respawn.flowmvi.sample.ui.widgets.RErrorView
import pro.respawn.flowmvi.sample.ui.widgets.RFilledButton
import pro.respawn.flowmvi.sample.ui.widgets.RScaffold
import pro.respawn.flowmvi.sample.ui.widgets.TypeCrossfade
import pro.respawn.flowmvi.sample.util.adaptiveWidth
import pro.respawn.flowmvi.sample.util.formatAsMultiline
import pro.respawn.flowmvi.sample.util.verticalListPaddings

Expand Down Expand Up @@ -111,7 +110,7 @@ private fun IntentReceiver<LoggingIntent>.LoggingScreenContent(
is LoggingState.Loading -> CircularProgressIndicator()
is LoggingState.Error -> RErrorView(e)
is DisplayingLogs -> LazyColumn(
modifier = Modifier.fillMaxHeight().adaptiveWidth(),
modifier = Modifier.fillMaxHeight().fillMaxWidth(),
contentPadding = WindowInsets.verticalListPaddings(),
state = listState,
horizontalAlignment = Alignment.CenterHorizontally,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -33,7 +34,6 @@ import pro.respawn.flowmvi.sample.ui.widgets.CodeText
import pro.respawn.flowmvi.sample.ui.widgets.RScaffold
import pro.respawn.flowmvi.sample.ui.widgets.RTextInput
import pro.respawn.flowmvi.sample.ui.widgets.TypeCrossfade
import pro.respawn.flowmvi.sample.util.adaptiveWidth
import pro.respawn.flowmvi.sample.util.formatAsMultiline

private const val Description = """
Expand Down Expand Up @@ -96,7 +96,7 @@ private fun IntentReceiver<SavedStateIntent>.SavedStateScreenContent(
.fillMaxHeight()
.padding(horizontal = 12.dp)
.verticalScroll(rememberScrollState())
.adaptiveWidth(),
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
Expand All @@ -28,7 +29,6 @@ import pro.respawn.flowmvi.sample.simple_feature_title
import pro.respawn.flowmvi.sample.ui.widgets.CodeText
import pro.respawn.flowmvi.sample.ui.widgets.ROutlinedButton
import pro.respawn.flowmvi.sample.ui.widgets.RScaffold
import pro.respawn.flowmvi.sample.util.adaptiveWidth
import pro.respawn.flowmvi.sample.util.formatAsMultiline

//language=kotlin
Expand Down Expand Up @@ -84,7 +84,7 @@ private fun IntentReceiver<SimpleIntent>.SimpleScreenContent(
) = Column(
modifier = Modifier
.fillMaxHeight()
.adaptiveWidth()
.fillMaxWidth()
.padding(horizontal = 12.dp)
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.Center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import pro.respawn.flowmvi.sample.ui.widgets.RIcon
import pro.respawn.flowmvi.sample.ui.widgets.RScaffold
import pro.respawn.flowmvi.sample.ui.widgets.RTextInput
import pro.respawn.flowmvi.sample.undoredo_feature_title
import pro.respawn.flowmvi.sample.util.adaptiveWidth
import pro.respawn.flowmvi.sample.util.formatAsMultiline

private const val Description = """
Expand Down Expand Up @@ -115,7 +114,7 @@ private fun IntentReceiver<UndoRedoIntent>.UndoRedoScreenContent(
state: UndoRedoState,
) = Column(
modifier = Modifier.fillMaxHeight()
.adaptiveWidth()
.fillMaxWidth()
.padding(horizontal = 12.dp)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,25 @@ val Highlights.annotatedString
get() = buildAnnotatedString {
append(getCode())

getHighlights().forEach {
when (it) {
is BoldHighlight -> addStyle(
SpanStyle(fontWeight = FontWeight.Bold),
getHighlights()
.filterIsInstance<ColorHighlight>()
.forEach {
addStyle(
SpanStyle(color = Color(it.rgb).copy(alpha = 1f)),
start = it.location.start,
end = it.location.end,
)
is ColorHighlight -> addStyle(
SpanStyle(color = Color(it.rgb).copy(alpha = 1f)),
}

getHighlights()
.filterIsInstance<BoldHighlight>()
.forEach {
addStyle(
SpanStyle(fontWeight = FontWeight.Bold),
start = it.location.start,
end = it.location.end,
)
}
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -23,7 +24,6 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import pro.respawn.flowmvi.sample.ui.theme.Opacity
import pro.respawn.flowmvi.sample.ui.theme.rememberRandomColor
import pro.respawn.flowmvi.sample.util.adaptiveWidth
import pro.respawn.flowmvi.sample.util.noIndicationClickable
import pro.respawn.kmmutils.common.takeIfValid
import kotlin.contracts.contract
Expand All @@ -50,7 +50,7 @@ fun RMenuItem(
modifier = modifier
.padding(horizontal = 4.dp, vertical = 4.dp)
.animateContentSize()
.adaptiveWidth()
.widthIn(max = 600.dp)
.then(if (onClick != null) Modifier.noIndicationClickable(onClick = onClick) else Modifier),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -83,6 +84,7 @@ fun RTextInput(
var isFocused by remember { mutableStateOf(false) }
Column(
modifier = modifier
.widthIn(max = 600.dp)
.bringIntoViewOnFocus()
.focusRequester(focusRequester)
.onFocusChanged { isFocused = it.isFocused }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.relocation.BringIntoViewRequester
import androidx.compose.foundation.relocation.bringIntoViewRequester
import androidx.compose.foundation.text.KeyboardActionScope
Expand Down Expand Up @@ -45,7 +43,6 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import pro.respawn.flowmvi.sample.ui.theme.Size
Expand Down Expand Up @@ -84,8 +81,6 @@ fun rememberSnackbarHostState() = remember { SnackbarHostState() }

fun Modifier.minTouchTarget() = defaultMinSize(Size.touchTarget, Size.touchTarget)

fun Modifier.adaptiveWidth(maxWidth: Dp = 600.dp) = widthIn(max = maxWidth).fillMaxWidth()

@Suppress("ComposableParametersOrdering")
@Composable
fun Modifier.noIndicationClickable(
Expand Down

0 comments on commit 80ea0a5

Please sign in to comment.