Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ff64a77
[Jetcaster] Update to SNAPSHOT 6891475 (#216)
chrisbanes Oct 8, 2020
f2eb002
[Crane] Update to SNAPSHOT 6891475 (#217)
manuelvicnt Oct 9, 2020
48b8213
[Jetchat] Update to SNAPSHOT 6891475
JoseAlcerreca Oct 9, 2020
2c47c1a
Spotless
JoseAlcerreca Oct 9, 2020
38eff0b
[Rally] Update to SNAPSHOT 6891475
JoseAlcerreca Oct 12, 2020
3ef25ab
[Jetsurvey] Bump to alpha05
florina-muntenescu Oct 13, 2020
1a0e2cd
[Jetsurvey] Using onSizeChanged to set the branding height
florina-muntenescu Oct 13, 2020
cd6cc13
Merge pull request #223 from android/fm/jetsurvey_alpha05
florina-muntenescu Oct 13, 2020
7285d77
[Jetsurvey] Bump to alpha05
florina-muntenescu Oct 13, 2020
94c4e96
[Jetsurvey] Using onSizeChanged to set the branding height
florina-muntenescu Oct 13, 2020
4f1f177
[Rally] Removes maven central snapshot repo
JoseAlcerreca Oct 13, 2020
abc776f
Merge branch 'dev_alpha05' of github.com:android/compose-samples into…
JoseAlcerreca Oct 13, 2020
eb1fde4
[Rally] Update to SNAPSHOT 6891475
JoseAlcerreca Oct 13, 2020
edf370e
[Jetchat] Removes maven central snapshot repo
JoseAlcerreca Oct 13, 2020
49af7f4
Merge remote-tracking branch 'github/dev_alpha05' into dev_jetchat_al…
JoseAlcerreca Oct 13, 2020
f7a193c
Merge pull request #218 from JoseAlcerreca/dev_jetchat_alpha05
JoseAlcerreca Oct 13, 2020
2a5305f
[Jetsnack] Update to snapshot 6901934.
nickbutcher Oct 13, 2020
6d1f8bd
[Jetsnack] Remove unused import.
nickbutcher Oct 13, 2020
e09d997
[Owl] Accept modifiers in search suggestion items.
nickbutcher Oct 13, 2020
64e0508
Merge pull request #224 from android/nb/jetsnack_alpha05
nickbutcher Oct 13, 2020
0e3edfc
[Owl] Update to snapshot 6901934.
nickbutcher Oct 13, 2020
40b99f8
Bump JetNews to alpha05 (#221)
objcode Oct 14, 2020
f59851e
Merge branch 'dev_alpha05' into nb/owl_alpha05
nickbutcher Oct 14, 2020
a3bfd5d
Merge pull request #225 from android/nb/owl_alpha05
nickbutcher Oct 14, 2020
a50a961
[Readme] Removes known issues (#222)
manuelvicnt Oct 14, 2020
5fe42bd
[All] Updates to alpha05 (#227)
manuelvicnt Oct 14, 2020
7143bfa
Merge branch 'main' into dev_alpha05
manuelvicnt Oct 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import androidx.compose.ui.graphics.HorizontalGradient
import androidx.compose.ui.graphics.LinearGradient
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.onPositioned
import androidx.compose.ui.onSizeChanged
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -138,7 +138,7 @@ fun Modifier.gradientBorder(
) = composed {
var size by remember { mutableStateOf(IntSize.Zero) }
val gradient = remember(colors, size) { brushProvider(colors, size) }
val sizeProvider = onPositioned { size = it.size }
val sizeProvider = onSizeChanged { size = it }
sizeProvider then border(
width = borderSize,
brush = gradient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.material.SnackbarHost
import androidx.compose.material.SnackbarHostState
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.emptyContent
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
Expand All @@ -42,10 +43,10 @@ import com.example.jetsnack.ui.theme.JetsnackTheme
fun JetsnackScaffold(
modifier: Modifier = Modifier,
scaffoldState: ScaffoldState = rememberScaffoldState(),
topBar: @Composable (() -> Unit)? = null,
bottomBar: @Composable (() -> Unit)? = null,
topBar: @Composable (() -> Unit) = emptyContent(),
bottomBar: @Composable (() -> Unit) = emptyContent(),
snackbarHost: @Composable (SnackbarHostState) -> Unit = { SnackbarHost(it) },
floatingActionButton: @Composable (() -> Unit)? = null,
floatingActionButton: @Composable (() -> Unit) = emptyContent(),
floatingActionButtonPosition: FabPosition = FabPosition.End,
isFloatingActionButtonDocked: Boolean = false,
drawerContent: @Composable (ColumnScope.() -> Unit)? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredHeightIn
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyRowFor
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
Expand Down Expand Up @@ -87,7 +88,9 @@ fun SnackCollection(
color = JetsnackTheme.colors.brand,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f)
modifier = Modifier
.weight(1f)
.wrapContentWidth(Alignment.Start)
)
IconButton(
onClick = { /* todo */ },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.example.jetsnack.ui.components

import androidx.compose.foundation.AmbientContentColor
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ContentColorAmbient
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
Expand All @@ -38,7 +38,7 @@ import kotlin.math.ln

/**
* An alternative to [androidx.compose.material.Surface] utilizing
* [com.example.jetsnack.ui.theme.JetsnackColorPalette]
* [com.example.jetsnack.ui.theme.JetsnackColors]
*/
@Composable
fun JetsnackSurface(
Expand All @@ -60,7 +60,7 @@ fun JetsnackSurface(
)
.clip(shape)
) {
Providers(ContentColorAmbient provides contentColor, children = content)
Providers(AmbientContentColor provides contentColor, children = content)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.ChainStyle
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ConstraintLayout
import androidx.compose.foundation.layout.Dimension
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -110,7 +109,7 @@ private fun SearchResult(
bottom = parent.bottom,
bottomMargin = 16.dp
)
linkTo(start = parent.start, end = name.start)
start.linkTo(parent.start)
}
)
Text(
Expand All @@ -122,18 +121,23 @@ private fun SearchResult(
start = image.end,
startMargin = 16.dp,
end = add.start,
endMargin = 16.dp
endMargin = 16.dp,
bias = 0f
)
width = Dimension.fillToConstraints
}
)
Text(
text = snack.tagline,
style = MaterialTheme.typography.body1,
color = JetsnackTheme.colors.textHelp,
modifier = Modifier.constrainAs(tag) {
linkTo(start = name.start, end = name.end)
width = Dimension.fillToConstraints
linkTo(
start = image.end,
startMargin = 16.dp,
end = add.start,
endMargin = 16.dp,
bias = 0f
)
}
)
Spacer(
Expand All @@ -148,8 +152,13 @@ private fun SearchResult(
style = MaterialTheme.typography.subtitle1,
color = JetsnackTheme.colors.textPrimary,
modifier = Modifier.constrainAs(price) {
linkTo(start = name.start, end = name.end)
width = Dimension.fillToConstraints
linkTo(
start = image.end,
startMargin = 16.dp,
end = add.start,
endMargin = 16.dp,
bias = 0f
)
}
)
JetsnackButton(
Expand All @@ -160,7 +169,7 @@ private fun SearchResult(
.preferredSize(36.dp)
.constrainAs(add) {
linkTo(top = parent.top, bottom = parent.bottom)
linkTo(start = name.end, end = parent.end)
end.linkTo(parent.end)
}
) {
Icon(Icons.Outlined.Add)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Icon
import androidx.compose.foundation.Text
import androidx.compose.foundation.contentColor
import androidx.compose.foundation.currentTextStyle
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -41,9 +40,9 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowBack
import androidx.compose.material.icons.outlined.Search
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedTask
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.launchInComposition
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -88,7 +87,7 @@ fun Search(
)
JetsnackDivider()

launchInComposition(state.query.text) {
LaunchedTask(state.query.text) {
state.searching = true
state.searchResults = SearchRepo.search(state.query.text)
state.searching = false
Expand Down Expand Up @@ -204,7 +203,6 @@ private fun SearchBar(
BaseTextField(
value = query,
onValueChange = onQueryChange,
textStyle = currentTextStyle().copy(color = contentColor()),
imeAction = ImeAction.Search,
onImeActionPerformed = { /* todo */ },
cursorColor = JetsnackTheme.colors.textPrimary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,87 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredHeightIn
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumnFor
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.ExperimentalLazyDsl
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.ui.tooling.preview.Preview
import com.example.jetsnack.model.SearchRepo
import com.example.jetsnack.model.SearchSuggestionGroup
import com.example.jetsnack.ui.components.JetsnackSurface
import com.example.jetsnack.ui.theme.JetsnackTheme

@OptIn(ExperimentalLazyDsl::class)
@Composable
fun SearchSuggestions(
suggestions: List<SearchSuggestionGroup>,
onSuggestionSelect: (String) -> Unit
) {
LazyColumnFor(suggestions) { suggestionGroup ->
Text(
text = suggestionGroup.name,
style = MaterialTheme.typography.h6,
color = JetsnackTheme.colors.textPrimary,
modifier = Modifier
.preferredHeightIn(min = 56.dp)
.padding(horizontal = 24.dp, vertical = 4.dp)
.wrapContentHeight()
)
suggestionGroup.suggestions.forEach { suggestion ->
Text(
text = suggestion,
style = MaterialTheme.typography.subtitle1,
modifier = Modifier
.fillParentMaxWidth()
.preferredHeightIn(min = 48.dp)
.clickable { onSuggestionSelect(suggestion) }
.padding(start = 24.dp)
.wrapContentHeight()
LazyColumn {
suggestions.forEach { suggestionGroup ->
item {
SuggestionHeader(suggestionGroup.name)
}
items(suggestionGroup.suggestions) { suggestion ->
Suggestion(
suggestion = suggestion,
onSuggestionSelect = onSuggestionSelect,
modifier = Modifier.fillParentMaxWidth()
)
}
item {
Spacer(Modifier.preferredHeight(4.dp))
}
}
}
}

@Composable
private fun SuggestionHeader(
name: String,
modifier: Modifier = Modifier
) {
Text(
text = name,
style = MaterialTheme.typography.h6,
color = JetsnackTheme.colors.textPrimary,
modifier = modifier
.preferredHeightIn(min = 56.dp)
.padding(horizontal = 24.dp, vertical = 4.dp)
.wrapContentHeight()
)
}

@Composable
private fun Suggestion(
suggestion: String,
onSuggestionSelect: (String) -> Unit,
modifier: Modifier = Modifier
) {
Text(
text = suggestion,
style = MaterialTheme.typography.subtitle1,
modifier = modifier
.preferredHeightIn(min = 48.dp)
.clickable { onSuggestionSelect(suggestion) }
.padding(start = 24.dp)
.wrapContentSize(Alignment.CenterStart)
)
}

@Preview
@Composable
fun PreviewSuggestions() {
JetsnackTheme {
JetsnackSurface {
SearchSuggestions(
suggestions = SearchRepo.getSuggestions(),
onSuggestionSelect = { }
)
}
Spacer(Modifier.preferredHeight(4.dp))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import androidx.compose.runtime.staticAmbientOf
import androidx.compose.ui.graphics.Color
import com.example.jetsnack.ui.utils.SysUiController

private val LightColorPalette = JetsnackColorPalette(
private val LightColorPalette = JetsnackColors(
brand = Shadow5,
uiBackground = Neutral0,
uiBorder = Neutral4,
Expand All @@ -53,7 +53,7 @@ private val LightColorPalette = JetsnackColorPalette(
isDark = false
)

private val DarkColorPalette = JetsnackColorPalette(
private val DarkColorPalette = JetsnackColors(
brand = Shadow1,
uiBackground = Neutral8,
uiBorder = Neutral3,
Expand Down Expand Up @@ -103,15 +103,15 @@ fun JetsnackTheme(

object JetsnackTheme {
@Composable
val colors: JetsnackColorPalette
get() = JetsnackColorAmbient.current
val colors: JetsnackColors
get() = AmbientJetsnackColors.current
}

/**
* Jetsnack custom Color Palette
*/
@Stable
class JetsnackColorPalette(
class JetsnackColors(
gradient6_1: List<Color>,
gradient6_2: List<Color>,
gradient3_1: List<Color>,
Expand Down Expand Up @@ -189,7 +189,7 @@ class JetsnackColorPalette(
var isDark by mutableStateOf(isDark)
private set

fun update(other: JetsnackColorPalette) {
fun update(other: JetsnackColors) {
gradient6_1 = other.gradient6_1
gradient6_2 = other.gradient6_2
gradient3_1 = other.gradient3_1
Expand Down Expand Up @@ -220,15 +220,15 @@ class JetsnackColorPalette(

@Composable
fun ProvideJetsnackColors(
colors: JetsnackColorPalette,
colors: JetsnackColors,
content: @Composable () -> Unit
) {
val colorPalette = remember { colors }
colorPalette.update(colors)
Providers(JetsnackColorAmbient provides colorPalette, children = content)
Providers(AmbientJetsnackColors provides colorPalette, children = content)
}

private val JetsnackColorAmbient = staticAmbientOf<JetsnackColorPalette> {
private val AmbientJetsnackColors = staticAmbientOf<JetsnackColors> {
error("No JetsnackColorPalette provided")
}

Expand Down
Loading