Browse Source

upd 2

ok/upd_jetsnack_to_new_libs
Oleksandr.Karpovich 2 months ago
parent
commit
151675c0a3
  1. 1
      examples/jetsnack/android/build.gradle.kts
  2. 17
      examples/jetsnack/android/src/main/java/com/example/android/MainActivity.kt
  3. 13
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/drawableResources.android.kt
  4. 114
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/stringResource.android.kt
  5. 74
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/JetsnackScaffoldContent.kt
  6. 123
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/MppJetsnackAppState.kt
  7. 69
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/components/SnackAsyncImage.kt
  8. 9
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/SnackDialog.kt
  9. 189
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/Cart.android.kt
  10. 48
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/CartViewModel.android.kt
  11. 12
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/snackCollectionListItemWindowInsets.kt
  12. 14
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/snackdetail/jetSnackNavigationBarsPadding.kt
  13. 0
      examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/utils/Currency.android.kt
  14. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/almonds.jpg
  15. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/apple_chips.jpg
  16. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/apple_juice.jpg
  17. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/apple_pie.jpg
  18. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/apple_sauce.jpg
  19. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/apples.jpg
  20. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/cheese.jpg
  21. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/chips.jpg
  22. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/cupcake.jpg
  23. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/desserts.jpg
  24. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/donut.jpg
  25. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/eclair.jpg
  26. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/froyo.jpg
  27. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/fruit.jpg
  28. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/gingerbread.jpg
  29. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/gluten_free.jpg
  30. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/grapes.jpg
  31. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/honeycomb.jpg
  32. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/ice_cream_sandwich.jpg
  33. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/jelly_bean.jpg
  34. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/kitkat.jpg
  35. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/kiwi.jpg
  36. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/lollipop.jpg
  37. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/mango.jpg
  38. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/marshmallow.jpg
  39. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/nougat.jpg
  40. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/nuts.jpg
  41. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/oreo.jpg
  42. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/organic.jpg
  43. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/paleo.jpg
  44. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/pie.jpg
  45. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/placeholder.jpg
  46. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/popcorn.jpg
  47. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/pretzels.jpg
  48. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/smoothies.jpg
  49. BIN
      examples/jetsnack/common/src/commonMain/composeResources/files/vegan.jpg
  50. 0
      examples/jetsnack/common/src/commonMain/composeResources/font/karla_bold.ttf
  51. 0
      examples/jetsnack/common/src/commonMain/composeResources/font/karla_regular.ttf
  52. 0
      examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_light.ttf
  53. 0
      examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_medium.ttf
  54. 0
      examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_regular.ttf
  55. 0
      examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_semibold.ttf
  56. 17
      examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/model/Filter.kt
  57. 13
      examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/components/GradientTintedIconButton.kt
  58. 266
      examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Theme.kt
  59. 178
      examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Type.kt
  60. 3
      examples/jetsnack/common/src/iosMain/kotlin/com/example/jetsnack/ui/main.ios.kt

1
examples/jetsnack/android/build.gradle.kts

@ -13,6 +13,7 @@ repositories {
} }
dependencies { dependencies {
implementation(compose.components.resources)
implementation(project(":common")) implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.5.0") implementation("androidx.activity:activity-compose:1.5.0")
} }

17
examples/jetsnack/android/src/main/java/com/example/android/MainActivity.kt

@ -4,29 +4,12 @@ import android.os.Bundle
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import com.example.jetsnack.R
import com.example.jetsnack.ui.JetsnackApp import com.example.jetsnack.ui.JetsnackApp
import com.example.jetsnack.ui.theme.Karla
import com.example.jetsnack.ui.theme.Montserrat
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
Montserrat = FontFamily(
Font(R.font.montserrat_light, FontWeight.Light),
Font(R.font.montserrat_regular, FontWeight.Normal),
Font(R.font.montserrat_medium, FontWeight.Medium),
Font(R.font.montserrat_semibold, FontWeight.SemiBold)
)
Karla = FontFamily(
Font(R.font.karla_regular, FontWeight.Normal),
Font(R.font.karla_bold, FontWeight.Bold)
)
setContent { setContent {
MaterialTheme { MaterialTheme {
JetsnackApp() JetsnackApp()

13
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/drawableResources.android.kt

@ -1,13 +0,0 @@
package com.example.jetsnack
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
@Composable
actual fun painterResource(id: Int): Painter {
return androidx.compose.ui.res.painterResource(id)
}
actual val MppR.drawable.empty_state_search: Int
get() = R.drawable.empty_state_search

114
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/stringResource.android.kt

@ -1,114 +0,0 @@
@file:Suppress("PrivatePropertyName")
package com.example.jetsnack
import androidx.compose.runtime.Composable
@Composable
actual fun stringResource(id: Int): String {
return androidx.compose.ui.res.stringResource(id)
}
@Composable
actual fun stringResource(id: Int, part: String): String {
return androidx.compose.ui.res.stringResource(id, part)
}
@Composable
actual fun stringResource(id: Int, count: Int): String {
return androidx.compose.ui.res.stringResource(id, count)
}
// Filters
actual val MppR.string.label_filters: Int get() = R.string.label_filters
// Qty
actual val MppR.string.quantity: Int get() = R.string.quantity
actual val MppR.string.label_decrease: Int get() = R.string.label_decrease
actual val MppR.string.label_increase: Int get() = R.string.label_increase
// Snack detail
actual val MppR.string.label_back: Int get() = R.string.label_back
actual val MppR.string.detail_header: Int get() = R.string.detail_header
actual val MppR.string.detail_placeholder: Int get() = R.string.detail_placeholder
actual val MppR.string.see_more: Int get() = R.string.see_more
actual val MppR.string.see_less: Int get() = R.string.see_less
actual val MppR.string.ingredients: Int get() = R.string.ingredients
actual val MppR.string.ingredients_list: Int get() = R.string.ingredients_list
actual val MppR.string.add_to_cart: Int get() = R.string.add_to_cart
// Home
actual val MppR.string.label_select_delivery: Int get() = R.string.label_select_delivery
// Filter
actual val MppR.string.max_calories: Int get() = R.string.max_calories
actual val MppR.string.per_serving: Int get() = R.string.per_serving
actual val MppR.string.sort: Int get() = R.string.sort
actual val MppR.string.lifestyle: Int get() = R.string.lifestyle
actual val MppR.string.category: Int get() = R.string.category
actual val MppR.string.price: Int get() = R.string.price
actual val MppR.string.reset: Int get() = R.string.reset
actual val MppR.string.close: Int get() = R.string.close
// Profile
actual val MppR.string.work_in_progress: Int get() = R.string.work_in_progress
actual val MppR.string.grab_beverage: Int get() = R.string.grab_beverage
// Home
actual val MppR.string.home_feed: Int get() = R.string.home_feed
actual val MppR.string.home_search: Int get() = R.string.home_search
actual val MppR.string.home_cart: Int get() = R.string.home_cart
actual val MppR.string.home_profile: Int get() = R.string.home_profile
// Search
actual val MppR.string.search_no_matches: Int get() = R.string.search_no_matches
actual val MppR.string.search_no_matches_retry: Int get() = R.string.search_no_matches_retry
actual val MppR.string.label_add: Int get() = R.string.label_add
actual val MppR.string.search_count: Int get() = R.string.search_count
actual val MppR.string.label_search: Int get() = R.string.label_search
actual val MppR.string.search_jetsnack: Int get() = R.string.search_jetsnack
actual val MppR.string.cart_increase_error: Int get() = R.string.cart_increase_error
actual val MppR.string.cart_decrease_error: Int get() = R.string.cart_decrease_error
// Cart
actual val MppR.plurals.cart_order_count: Int get() = R.plurals.cart_order_count
actual val MppR.string.cart_order_header: Int get() = R.string.cart_order_header
actual val MppR.string.remove_item: Int get() = R.string.remove_item
actual val MppR.string.cart_summary_header: Int get() = R.string.cart_summary_header
actual val MppR.string.cart_subtotal_label: Int get() = R.string.cart_subtotal_label
actual val MppR.string.cart_shipping_label: Int get() = R.string.cart_shipping_label
actual val MppR.string.cart_total_label: Int get() = R.string.cart_total_label
actual val MppR.string.cart_checkout: Int get() = R.string.cart_checkout
actual val MppR.string.label_remove: Int get() = R.string.label_remove

74
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/JetsnackScaffoldContent.kt

@ -1,74 +0,0 @@
package com.example.jetsnack.ui
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import androidx.navigation.navArgument
import com.example.jetsnack.ui.home.Feed
import com.example.jetsnack.ui.home.HomeSections
import com.example.jetsnack.ui.home.Profile
import com.example.jetsnack.ui.home.cart.Cart
import com.example.jetsnack.ui.home.search.Search
import com.example.jetsnack.ui.snackdetail.SnackDetail
@Composable
actual fun JetsnackScaffoldContent(
innerPaddingModifier: PaddingValues,
appState: MppJetsnackAppState
) {
NavHost(
navController = appState.navController,
startDestination = MainDestinations.HOME_ROUTE,
modifier = Modifier.padding(innerPaddingModifier)
) {
jetsnackNavGraph(
onSnackSelected = appState::navigateToSnackDetail,
upPress = appState::upPress
)
}
}
private fun NavGraphBuilder.jetsnackNavGraph(
onSnackSelected: (Long, NavBackStackEntry) -> Unit,
upPress: () -> Unit,
) {
navigation(
route = MainDestinations.HOME_ROUTE,
startDestination = HomeSections.FEED.route
) {
addHomeGraph(onSnackSelected)
}
composable(
"${MainDestinations.SNACK_DETAIL_ROUTE}/{${MainDestinations.SNACK_ID_KEY}}",
arguments = listOf(navArgument(MainDestinations.SNACK_ID_KEY) { type = NavType.LongType })
) { backStackEntry ->
val arguments = requireNotNull(backStackEntry.arguments)
val snackId = arguments.getLong(MainDestinations.SNACK_ID_KEY)
SnackDetail(snackId, upPress, onSnackClick = { onSnackSelected(snackId, backStackEntry) })
}
}
fun NavGraphBuilder.addHomeGraph(
onSnackSelected: (Long, NavBackStackEntry) -> Unit,
modifier: Modifier = Modifier
) {
composable(HomeSections.FEED.route) { from ->
Feed(onSnackClick = { id -> onSnackSelected(id, from) }, modifier)
}
composable(HomeSections.SEARCH.route) { from ->
Search(onSnackClick = { id -> onSnackSelected(id, from) }, modifier)
}
composable(HomeSections.CART.route) { from ->
Cart(onSnackClick = { id -> onSnackSelected(id, from) }, modifier)
}
composable(HomeSections.PROFILE.route) {
Profile(modifier)
}
}

123
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/MppJetsnackAppState.kt

@ -1,123 +0,0 @@
package com.example.jetsnack.ui
import android.content.res.Resources
import androidx.compose.material3.ScaffoldState
import androidx.compose.material3.rememberScaffoldState
import androidx.compose.runtime.*
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.Lifecycle
import androidx.navigation.*
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.jetsnack.model.SnackbarManager
import com.example.jetsnack.ui.home.HomeSections
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
@Stable
actual class MppJetsnackAppState(
actual val scaffoldState: ScaffoldState,
actual val snackbarManager: SnackbarManager,
actual val coroutineScope: CoroutineScope,
val navController: NavHostController,
val resources: Resources
) {
init {
coroutineScope.launch {
snackbarManager.messages.collect { currentMessages ->
if (currentMessages.isNotEmpty()) {
val message = currentMessages[0]
val text = resources.getText(message.message).toString()
// Display the snackbar on the screen. `showSnackbar` is a function
// that suspends until the snackbar disappears from the screen
scaffoldState.snackbarHostState.showSnackbar(text)
// Once the snackbar is gone or dismissed, notify the SnackbarManager
snackbarManager.setMessageShown(message.id)
}
}
}
}
private val bottomBarRoutes = bottomBarTabs.map { it.route }
actual val bottomBarTabs: Array<HomeSections>
get() = HomeSections.values()
actual val currentRoute: String?
get() = navController.currentDestination?.route
@Composable
actual fun shouldShowBottomBar(): Boolean {
return navController
.currentBackStackEntryAsState().value?.destination?.route in bottomBarRoutes
}
actual fun navigateToBottomBarRoute(route: String) {
if (route != currentRoute) {
navController.navigate(route) {
launchSingleTop = true
restoreState = true
// Pop up backstack to the first destination and save state. This makes going back
// to the start destination when pressing back in any other bottom tab.
popUpTo(findStartDestination(navController.graph).id) {
saveState = true
}
}
}
}
fun navigateToSnackDetail(snackId: Long, from: NavBackStackEntry) {
// In order to discard duplicated navigation events, we check the Lifecycle
if (from.lifecycleIsResumed()) {
navController.navigate("${MainDestinations.SNACK_DETAIL_ROUTE}/$snackId")
}
}
fun upPress() {
navController.navigateUp()
}
}
@Suppress("UsePropertyAccessSyntax")
private fun NavBackStackEntry.lifecycleIsResumed() =
this.getLifecycle().currentState == Lifecycle.State.RESUMED
private val NavGraph.startDestination: NavDestination?
get() = findNode(startDestinationId)
/**
* Copied from similar function in NavigationUI.kt
*
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:navigation/navigation-ui/src/main/java/androidx/navigation/ui/NavigationUI.kt
*/
private tailrec fun findStartDestination(graph: NavDestination): NavDestination {
return if (graph is NavGraph) findStartDestination(graph.startDestination!!) else graph
}
@Composable
actual fun rememberMppJetsnackAppState(): MppJetsnackAppState {
val scaffoldState = rememberScaffoldState()
val navController = rememberNavController()
val resources = resources()
val snackbarManager = SnackbarManager
val coroutineScope = rememberCoroutineScope()
return remember(scaffoldState, navController, snackbarManager, resources, coroutineScope) {
MppJetsnackAppState(scaffoldState, snackbarManager, coroutineScope, navController, resources)
}
}
/**
* A composable function that returns the [Resources]. It will be recomposed when `Configuration`
* gets updated.
*/
@Composable
@ReadOnlyComposable
private fun resources(): Resources {
LocalConfiguration.current
return LocalContext.current.resources
}

69
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/components/SnackAsyncImage.kt

@ -1,69 +0,0 @@
package com.example.jetsnack.ui.components
import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.TweenSpec
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.with
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
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.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
import com.example.common.generated.resources.Res
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.jetbrains.compose.resources.ExperimentalResourceApi
private val imagesCache = mutableMapOf<String, ImageBitmap>()
@SuppressLint("UnusedContentLambdaTargetStateParameter")
@OptIn(ExperimentalAnimationApi::class, ExperimentalResourceApi::class)
@Composable
actual fun SnackAsyncImage(imageUrl: String, contentDescription: String?, modifier: Modifier) {
var img: ImageBitmap? by remember(imageUrl) { mutableStateOf(null) }
AnimatedContent(img, transitionSpec = {
fadeIn(TweenSpec()) with fadeOut(TweenSpec())
}) {
if (img != null) {
Image(img!!, contentDescription = contentDescription, modifier = modifier, contentScale = ContentScale.Crop)
} else {
Box(modifier = modifier)
}
}
LaunchedEffect(imageUrl) {
if (imagesCache.contains(imageUrl)) {
img = imagesCache[imageUrl]
} else {
withContext(Dispatchers.IO) {
img = try {
Res.readBytes(imageUrl).toAndroidBitmap().asImageBitmap().also {
imagesCache[imageUrl] = it
img = it
}
} catch (e: Throwable) {
e.printStackTrace()
null
}
}
}
}
}
fun ByteArray.toAndroidBitmap(): Bitmap {
return BitmapFactory.decodeByteArray(this, 0, size)
}

9
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/SnackDialog.kt

@ -1,9 +0,0 @@
package com.example.jetsnack.ui.home
import androidx.compose.runtime.Composable
import androidx.compose.ui.window.Dialog
@Composable
actual fun SnackDialog(onCloseRequest: () -> Unit, content: @Composable () -> Unit) {
Dialog(onDismissRequest = onCloseRequest, content = content)
}

189
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/Cart.android.kt

@ -1,189 +0,0 @@
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.jetsnack.ui.home.cart
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.icons.Icons
import androidx.compose.material3.icons.filled.Close
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ChainStyle
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.jetsnack.R
import com.example.jetsnack.model.OrderLine
import com.example.jetsnack.model.SnackRepo
import com.example.jetsnack.ui.components.JetsnackDivider
import com.example.jetsnack.ui.components.QuantitySelector
import com.example.jetsnack.ui.components.SnackImage
import com.example.jetsnack.ui.theme.JetsnackTheme
import com.example.jetsnack.ui.utils.formatPrice
@Composable
actual fun provideCartViewModel(): CartViewModel {
return viewModel(factory = CartViewModel.provideFactory())
}
@Composable
actual fun ActualCartItem(
orderLine: OrderLine,
removeSnack: (Long) -> Unit,
increaseItemCount: (Long) -> Unit,
decreaseItemCount: (Long) -> Unit,
onSnackClick: (Long) -> Unit,
modifier: Modifier
) {
val snack = orderLine.snack
ConstraintLayout(
modifier = modifier
.fillMaxWidth()
.clickable { onSnackClick(snack.id) }
.background(JetsnackTheme.colors.uiBackground)
.padding(horizontal = 24.dp)
) {
val (divider, image, name, tag, priceSpacer, price, remove, quantity) = createRefs()
createVerticalChain(name, tag, priceSpacer, price, chainStyle = ChainStyle.Packed)
SnackImage(
imageUrl = snack.imageUrl,
contentDescription = null,
modifier = Modifier
.size(100.dp)
.constrainAs(image) {
top.linkTo(parent.top, margin = 16.dp)
bottom.linkTo(parent.bottom, margin = 16.dp)
start.linkTo(parent.start)
}
)
Text(
text = snack.name,
style = MaterialTheme.typography.subtitle1,
color = JetsnackTheme.colors.textSecondary,
modifier = Modifier.constrainAs(name) {
linkTo(
start = image.end,
startMargin = 16.dp,
end = remove.start,
endMargin = 16.dp,
bias = 0f
)
}
)
IconButton(
onClick = { removeSnack(snack.id) },
modifier = Modifier
.constrainAs(remove) {
top.linkTo(parent.top)
end.linkTo(parent.end)
}
.padding(top = 12.dp)
) {
Icon(
imageVector = Icons.Filled.Close,
tint = JetsnackTheme.colors.iconSecondary,
contentDescription = stringResource(R.string.label_remove)
)
}
Text(
text = snack.tagline,
style = MaterialTheme.typography.body1,
color = JetsnackTheme.colors.textHelp,
modifier = Modifier.constrainAs(tag) {
linkTo(
start = image.end,
startMargin = 16.dp,
end = parent.end,
endMargin = 16.dp,
bias = 0f
)
}
)
Spacer(
Modifier
.height(8.dp)
.constrainAs(priceSpacer) {
linkTo(top = tag.bottom, bottom = price.top)
}
)
Text(
text = formatPrice(snack.price),
style = MaterialTheme.typography.subtitle1,
color = JetsnackTheme.colors.textPrimary,
modifier = Modifier.constrainAs(price) {
linkTo(
start = image.end,
end = quantity.start,
startMargin = 16.dp,
endMargin = 16.dp,
bias = 0f
)
}
)
QuantitySelector(
count = orderLine.count,
decreaseItemCount = { decreaseItemCount(snack.id) },
increaseItemCount = { increaseItemCount(snack.id) },
modifier = Modifier.constrainAs(quantity) {
baseline.linkTo(price.baseline)
end.linkTo(parent.end)
}
)
JetsnackDivider(
Modifier.constrainAs(divider) {
linkTo(start = parent.start, end = parent.end)
top.linkTo(parent.bottom)
}
)
}
}
@Composable
private fun CartPreview() {
JetsnackTheme {
Cart(
orderLines = SnackRepo.getCart(),
removeSnack = {},
increaseItemCount = {},
decreaseItemCount = {},
inspiredByCart = SnackRepo.getInspiredByCart(),
onSnackClick = {}
)
}
}
@Composable
actual fun rememberQuantityString(res: Int, qty: Int, vararg args: Any): String {
val resources = LocalContext.current.resources
return remember(qty, resources) { resources.getQuantityString(R.plurals.cart_order_count, qty, qty) }
}
@Composable
actual fun getCartContentInsets(): WindowInsets {
return WindowInsets.statusBars.add(WindowInsets(top = 56.dp))
}

48
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/CartViewModel.android.kt

@ -1,48 +0,0 @@
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.jetsnack.ui.home.cart
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.example.jetsnack.model.OrderLine
import com.example.jetsnack.model.SnackRepo
import com.example.jetsnack.model.SnackbarManager
import kotlinx.coroutines.flow.StateFlow
/**
* Factory for CartViewModel that takes SnackbarManager as a dependency
*/
fun CartViewModel.Companion.provideFactory(
snackbarManager: SnackbarManager = SnackbarManager,
snackRepository: SnackRepo = SnackRepo
): ViewModelProvider.Factory = object : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return CartViewModel(snackbarManager, snackRepository) as T
}
}
@OptIn(kotlin.ExperimentalMultiplatform::class)
actual abstract class JetSnackCartViewModel actual constructor() : ViewModel() {
@Composable
actual fun collectOrderLinesAsState(flow: StateFlow<List<OrderLine>>): State<List<OrderLine>> {
return flow.collectAsStateWithLifecycle()
}
}

12
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/snackCollectionListItemWindowInsets.kt

@ -1,12 +0,0 @@
package com.example.jetsnack.ui.home
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.add
import androidx.compose.foundation.layout.statusBars
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
@Composable
actual fun snackCollectionListItemWindowInsets(): WindowInsets {
return WindowInsets.statusBars.add(WindowInsets(top = 56.dp))
}

14
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/snackdetail/jetSnackNavigationBarsPadding.kt

@ -1,14 +0,0 @@
package com.example.jetsnack.ui.snackdetail
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@Composable
actual fun Modifier.jetSnackNavigationBarsPadding(): Modifier = this.navigationBarsPadding()
@Composable
actual fun Modifier.jetSnackStatusBarsPadding(): Modifier = this.statusBarsPadding()
@Composable
actual fun Modifier.jetSnackSystemBarsPadding(): Modifier = this.systemBarsPadding()

0
examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/utils/formatPrice.kt → examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/utils/Currency.android.kt

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/almonds.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 332 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/apple_chips.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/apple_juice.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/apple_pie.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/apple_sauce.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/apples.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/cheese.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/chips.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/cupcake.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/desserts.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/donut.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/eclair.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/froyo.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/fruit.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 382 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/gingerbread.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 653 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/gluten_free.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 496 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/grapes.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 212 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/honeycomb.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 380 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/ice_cream_sandwich.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/jelly_bean.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/kitkat.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/kiwi.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/lollipop.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/mango.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/marshmallow.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 137 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/nougat.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/nuts.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/oreo.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/organic.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/paleo.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/pie.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 135 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/placeholder.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/popcorn.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/pretzels.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/smoothies.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

BIN
examples/jetsnack/common/src/commonMain/composeResources/files/vegan.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 187 KiB

0
examples/jetsnack/common/src/androidMain/res/font/karla_bold.ttf → examples/jetsnack/common/src/commonMain/composeResources/font/karla_bold.ttf

0
examples/jetsnack/common/src/androidMain/res/font/karla_regular.ttf → examples/jetsnack/common/src/commonMain/composeResources/font/karla_regular.ttf

0
examples/jetsnack/common/src/androidMain/res/font/montserrat_light.ttf → examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_light.ttf

0
examples/jetsnack/common/src/androidMain/res/font/montserrat_medium.ttf → examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_medium.ttf

0
examples/jetsnack/common/src/androidMain/res/font/montserrat_regular.ttf → examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_regular.ttf

0
examples/jetsnack/common/src/androidMain/res/font/montserrat_semibold.ttf → examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_semibold.ttf

17
examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/model/Filter.kt

@ -16,13 +16,13 @@
package com.example.jetsnack.model package com.example.jetsnack.model
//import androidx.compose.material3.icons.Icons import androidx.compose.material.icons.Icons
//import androidx.compose.material3.icons.filled.Star import androidx.compose.material.icons.filled.Android
import androidx.compose.material.icons.filled.SortByAlpha
import androidx.compose.material.icons.filled.Star
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
//import com.example.jetsnack.Android
//import com.example.jetsnack.SortByAlpha
@Stable @Stable
class Filter( class Filter(
@ -32,6 +32,7 @@ class Filter(
) { ) {
val enabled = mutableStateOf(enabled) val enabled = mutableStateOf(enabled)
} }
val filters = listOf( val filters = listOf(
Filter(name = "Organic"), Filter(name = "Organic"),
Filter(name = "Gluten-free"), Filter(name = "Gluten-free"),
@ -45,10 +46,10 @@ val priceFilters = listOf(
Filter(name = "$$$"), Filter(name = "$$$"),
Filter(name = "$$$$") Filter(name = "$$$$")
) )
val sortFilters = listOf<Filter>( val sortFilters = listOf(
Filter(name = "Android's favorite (default)"), Filter(name = "Android's favorite (default)", icon = Icons.Filled.Android),
Filter(name = "Rating",), Filter(name = "Rating", icon = Icons.Filled.Star),
Filter(name = "Alphabetical",) Filter(name = "Alphabetical", icon = Icons.Filled.SortByAlpha)
) )
val categoryFilters = listOf( val categoryFilters = listOf(

13
examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/components/GradientTintedIconButton.kt

@ -92,16 +92,3 @@ fun JetsnackGradientTintedIconButton(
) )
} }
} }
//@Preview
@Composable
private fun GradientTintedIconButtonPreview() {
JetsnackTheme {
// JetsnackGradientTintedIconButton(
// imageVector = Icons.Default.Add,
// onClick = {},
// contentDescription = "Demo",
// modifier = Modifier.padding(4.dp)
// )
}
}

266
examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Theme.kt

@ -17,15 +17,11 @@
package com.example.jetsnack.ui.theme package com.example.jetsnack.ui.theme
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.SideEffect import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@ -88,17 +84,9 @@ fun JetsnackTheme(
) { ) {
val colors = if (darkTheme) DarkColorPalette else LightColorPalette val colors = if (darkTheme) DarkColorPalette else LightColorPalette
// TODO: implement setSystemBarsColor for android!
// val sysUiController = rememberSystemUiController()
// SideEffect {
// sysUiController.setSystemBarsColor(
// color = colors.uiBackground.copy(alpha = AlphaNearOpaque)
// )
// }
ProvideJetsnackColors(colors) { ProvideJetsnackColors(colors) {
MaterialTheme( MaterialTheme(
// colors = debugColors(darkTheme), colorScheme = debugColors(darkTheme),
typography = Typography, typography = Typography,
shapes = Shapes, shapes = Shapes,
content = content content = content
@ -115,169 +103,44 @@ object JetsnackTheme {
/** /**
* Jetsnack custom Color Palette * Jetsnack custom Color Palette
*/ */
@Stable @Immutable
class JetsnackColors( data class JetsnackColors(
gradient6_1: List<Color>, val gradient6_1: List<Color>,
gradient6_2: List<Color>, val gradient6_2: List<Color>,
gradient3_1: List<Color>, val gradient3_1: List<Color>,
gradient3_2: List<Color>, val gradient3_2: List<Color>,
gradient2_1: List<Color>, val gradient2_1: List<Color>,
gradient2_2: List<Color>, val gradient2_2: List<Color>,
gradient2_3: List<Color>, val gradient2_3: List<Color>,
brand: Color, val brand: Color,
brandSecondary: Color, val brandSecondary: Color,
uiBackground: Color, val uiBackground: Color,
uiBorder: Color, val uiBorder: Color,
uiFloated: Color, val uiFloated: Color,
interactivePrimary: List<Color> = gradient2_1, val interactivePrimary: List<Color> = gradient2_1,
interactiveSecondary: List<Color> = gradient2_2, val interactiveSecondary: List<Color> = gradient2_2,
interactiveMask: List<Color> = gradient6_1, val interactiveMask: List<Color> = gradient6_1,
textPrimary: Color = brand, val textPrimary: Color = brand,
textSecondary: Color, val textSecondary: Color,
textHelp: Color, val textHelp: Color,
textInteractive: Color, val textInteractive: Color,
textLink: Color, val textLink: Color,
tornado1: List<Color>, val tornado1: List<Color>,
iconPrimary: Color = brand, val iconPrimary: Color = brand,
iconSecondary: Color, val iconSecondary: Color,
iconInteractive: Color, val iconInteractive: Color,
iconInteractiveInactive: Color, val iconInteractiveInactive: Color,
error: Color, val error: Color,
notificationBadge: Color = error, val notificationBadge: Color = error,
isDark: Boolean val isDark: Boolean
) {
var gradient6_1 by mutableStateOf(gradient6_1)
private set
var gradient6_2 by mutableStateOf(gradient6_2)
private set
var gradient3_1 by mutableStateOf(gradient3_1)
private set
var gradient3_2 by mutableStateOf(gradient3_2)
private set
var gradient2_1 by mutableStateOf(gradient2_1)
private set
var gradient2_2 by mutableStateOf(gradient2_2)
private set
var gradient2_3 by mutableStateOf(gradient2_3)
private set
var brand by mutableStateOf(brand)
private set
var brandSecondary by mutableStateOf(brandSecondary)
private set
var uiBackground by mutableStateOf(uiBackground)
private set
var uiBorder by mutableStateOf(uiBorder)
private set
var uiFloated by mutableStateOf(uiFloated)
private set
var interactivePrimary by mutableStateOf(interactivePrimary)
private set
var interactiveSecondary by mutableStateOf(interactiveSecondary)
private set
var interactiveMask by mutableStateOf(interactiveMask)
private set
var textPrimary by mutableStateOf(textPrimary)
private set
var textSecondary by mutableStateOf(textSecondary)
private set
var textHelp by mutableStateOf(textHelp)
private set
var textInteractive by mutableStateOf(textInteractive)
private set
var tornado1 by mutableStateOf(tornado1)
private set
var textLink by mutableStateOf(textLink)
private set
var iconPrimary by mutableStateOf(iconPrimary)
private set
var iconSecondary by mutableStateOf(iconSecondary)
private set
var iconInteractive by mutableStateOf(iconInteractive)
private set
var iconInteractiveInactive by mutableStateOf(iconInteractiveInactive)
private set
var error by mutableStateOf(error)
private set
var notificationBadge by mutableStateOf(notificationBadge)
private set
var isDark by mutableStateOf(isDark)
private set
fun update(other: JetsnackColors) {
gradient6_1 = other.gradient6_1
gradient6_2 = other.gradient6_2
gradient3_1 = other.gradient3_1
gradient3_2 = other.gradient3_2
gradient2_1 = other.gradient2_1
gradient2_2 = other.gradient2_2
gradient2_3 = other.gradient2_3
brand = other.brand
brandSecondary = other.brandSecondary
uiBackground = other.uiBackground
uiBorder = other.uiBorder
uiFloated = other.uiFloated
interactivePrimary = other.interactivePrimary
interactiveSecondary = other.interactiveSecondary
interactiveMask = other.interactiveMask
textPrimary = other.textPrimary
textSecondary = other.textSecondary
textHelp = other.textHelp
textInteractive = other.textInteractive
textLink = other.textLink
tornado1 = other.tornado1
iconPrimary = other.iconPrimary
iconSecondary = other.iconSecondary
iconInteractive = other.iconInteractive
iconInteractiveInactive = other.iconInteractiveInactive
error = other.error
notificationBadge = other.notificationBadge
isDark = other.isDark
}
fun copy(): JetsnackColors = JetsnackColors(
gradient6_1 = gradient6_1,
gradient6_2 = gradient6_2,
gradient3_1 = gradient3_1,
gradient3_2 = gradient3_2,
gradient2_1 = gradient2_1,
gradient2_2 = gradient2_2,
gradient2_3 = gradient2_3,
brand = brand,
brandSecondary = brandSecondary,
uiBackground = uiBackground,
uiBorder = uiBorder,
uiFloated = uiFloated,
interactivePrimary = interactivePrimary,
interactiveSecondary = interactiveSecondary,
interactiveMask = interactiveMask,
textPrimary = textPrimary,
textSecondary = textSecondary,
textHelp = textHelp,
textInteractive = textInteractive,
textLink = textLink,
tornado1 = tornado1,
iconPrimary = iconPrimary,
iconSecondary = iconSecondary,
iconInteractive = iconInteractive,
iconInteractiveInactive = iconInteractiveInactive,
error = error,
notificationBadge = notificationBadge,
isDark = isDark,
) )
}
@Composable @Composable
fun ProvideJetsnackColors( fun ProvideJetsnackColors(
colors: JetsnackColors, colors: JetsnackColors,
content: @Composable () -> Unit content: @Composable () -> Unit
) { ) {
val colorPalette = remember { CompositionLocalProvider(LocalJetsnackColors provides colors, content = content)
// Explicitly creating a new object here so we don't mutate the initial [colors]
// provided, and overwrite the values set in it.
colors.copy()
}
colorPalette.update(colors)
CompositionLocalProvider(LocalJetsnackColors provides colorPalette, content = content)
} }
private val LocalJetsnackColors = staticCompositionLocalOf<JetsnackColors> { private val LocalJetsnackColors = staticCompositionLocalOf<JetsnackColors> {
@ -286,23 +149,46 @@ private val LocalJetsnackColors = staticCompositionLocalOf<JetsnackColors> {
/** /**
* A Material [Colors] implementation which sets all colors to [debugColor] to discourage usage of * A Material [Colors] implementation which sets all colors to [debugColor] to discourage usage of
* [MaterialTheme.colors] in preference to [JetsnackTheme.colors]. * [MaterialTheme.colorScheme] in preference to [JetsnackTheme.colors].
*/ */
//fun debugColors( fun debugColors(
// darkTheme: Boolean, darkTheme: Boolean,
// debugColor: Color = Color.Magenta debugColor: Color = Color.Magenta
//) = Colors( ) = ColorScheme(
// primary = debugColor, primary = debugColor,
// primaryVariant = debugColor, onPrimary = debugColor,
// secondary = debugColor, primaryContainer = debugColor,
// secondaryVariant = debugColor, onPrimaryContainer = debugColor,
// background = debugColor, inversePrimary = debugColor,
// surface = debugColor, secondary = debugColor,
// error = debugColor, onSecondary = debugColor,
// onPrimary = debugColor, secondaryContainer = debugColor,
// onSecondary = debugColor, onSecondaryContainer = debugColor,
// onBackground = debugColor, tertiary = debugColor,
// onSurface = debugColor, onTertiary = debugColor,
// onError = debugColor, tertiaryContainer = debugColor,
// isLight = !darkTheme onTertiaryContainer = debugColor,
//) background = debugColor,
onBackground = debugColor,
surface = debugColor,
onSurface = debugColor,
surfaceVariant = debugColor,
onSurfaceVariant = debugColor,
surfaceTint = debugColor,
inverseSurface = debugColor,
inverseOnSurface = debugColor,
error = debugColor,
onError = debugColor,
errorContainer = debugColor,
onErrorContainer = debugColor,
outline = debugColor,
outlineVariant = debugColor,
scrim = debugColor,
surfaceBright = debugColor,
surfaceDim = debugColor,
surfaceContainer = debugColor,
surfaceContainerHigh = debugColor,
surfaceContainerHighest = debugColor,
surfaceContainerLow = debugColor,
surfaceContainerLowest = debugColor,
)

178
examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Type.kt

@ -25,94 +25,92 @@ import androidx.compose.ui.unit.sp
var Montserrat: FontFamily? = null // init in platform code var Montserrat: FontFamily? = null // init in platform code
var Karla: FontFamily? = null // init in platform code var Karla: FontFamily? = null // init in platform code
val Typography by lazy { val Typography = Typography(
Typography( displayLarge = TextStyle(
// h1 = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 96.sp,
// fontSize = 96.sp, fontWeight = FontWeight.Light,
// fontWeight = FontWeight.Light, lineHeight = 117.sp,
// lineHeight = 117.sp, letterSpacing = (-1.5).sp
// letterSpacing = (-1.5).sp, ),
// ), displayMedium = TextStyle(
// h2 = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 60.sp,
// fontSize = 60.sp, fontWeight = FontWeight.Light,
// fontWeight = FontWeight.Light, lineHeight = 73.sp,
// lineHeight = 73.sp, letterSpacing = (-0.5).sp
// letterSpacing = (-0.5).sp ),
// ), displaySmall = TextStyle(
// h3 = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 48.sp,
// fontSize = 48.sp, fontWeight = FontWeight.Normal,
// fontWeight = FontWeight.Normal, lineHeight = 59.sp
// lineHeight = 59.sp ),
// ), headlineMedium = TextStyle(
// h4 = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 30.sp,
// fontSize = 30.sp, fontWeight = FontWeight.SemiBold,
// fontWeight = FontWeight.SemiBold, lineHeight = 37.sp
// lineHeight = 37.sp ),
// ), headlineSmall = TextStyle(
// h5 = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 24.sp,
// fontSize = 24.sp, fontWeight = FontWeight.SemiBold,
// fontWeight = FontWeight.SemiBold, lineHeight = 29.sp
// lineHeight = 29.sp ),
// ), titleLarge = TextStyle(
// h6 = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 20.sp,
// fontSize = 20.sp, fontWeight = FontWeight.SemiBold,
// fontWeight = FontWeight.SemiBold, lineHeight = 24.sp
// lineHeight = 24.sp ),
// ), titleMedium = TextStyle(
// subtitle1 = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 16.sp,
// fontSize = 16.sp, fontWeight = FontWeight.SemiBold,
// fontWeight = FontWeight.SemiBold, lineHeight = 24.sp,
// lineHeight = 24.sp, letterSpacing = 0.15.sp
// letterSpacing = 0.15.sp ),
// ), titleSmall = TextStyle(
// subtitle2 = TextStyle( fontFamily = Karla,
// fontFamily = Karla, fontSize = 14.sp,
// fontSize = 14.sp, fontWeight = FontWeight.Bold,
// fontWeight = FontWeight.Bold, lineHeight = 24.sp,
// lineHeight = 24.sp, letterSpacing = 0.1.sp
// letterSpacing = 0.1.sp ),
// ), bodyLarge = TextStyle(
// body1 = TextStyle( fontFamily = Karla,
// fontFamily = Karla, fontSize = 16.sp,
// fontSize = 16.sp, fontWeight = FontWeight.Normal,
// fontWeight = FontWeight.Normal, lineHeight = 28.sp,
// lineHeight = 28.sp, letterSpacing = 0.15.sp
// letterSpacing = 0.15.sp ),
// ), bodyMedium = TextStyle(
// body2 = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 14.sp,
// fontSize = 14.sp, fontWeight = FontWeight.Medium,
// fontWeight = FontWeight.Medium, lineHeight = 20.sp,
// lineHeight = 20.sp, letterSpacing = 0.25.sp
// letterSpacing = 0.25.sp ),
// ), labelLarge = TextStyle(
// button = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 14.sp,
// fontSize = 14.sp, fontWeight = FontWeight.SemiBold,
// fontWeight = FontWeight.SemiBold, lineHeight = 16.sp,
// lineHeight = 16.sp, letterSpacing = 1.25.sp
// letterSpacing = 1.25.sp ),
// ), bodySmall = TextStyle(
// caption = TextStyle( fontFamily = Karla,
// fontFamily = Karla, fontSize = 12.sp,
// fontSize = 12.sp, fontWeight = FontWeight.Bold,
// fontWeight = FontWeight.Bold, lineHeight = 16.sp,
// lineHeight = 16.sp, letterSpacing = 0.4.sp
// letterSpacing = 0.4.sp ),
// ), labelSmall = TextStyle(
// overline = TextStyle( fontFamily = Montserrat,
// fontFamily = Montserrat, fontSize = 12.sp,
// fontSize = 12.sp, fontWeight = FontWeight.SemiBold,
// fontWeight = FontWeight.SemiBold, lineHeight = 16.sp,
// lineHeight = 16.sp, letterSpacing = 1.sp
// letterSpacing = 1.sp )
// )
) )
}

3
examples/jetsnack/common/src/iosMain/kotlin/com/example/jetsnack/ui/main.ios.kt

@ -1,10 +1,9 @@
package com.example.jetsnack.ui package com.example.jetsnack.ui
import androidx.compose.ui.window.ComposeUIViewController import androidx.compose.ui.window.ComposeUIViewController
import com.example.jetsnack.JetSnackAppEntryPoint
import platform.UIKit.UIViewController import platform.UIKit.UIViewController
fun MainViewController(): UIViewController = fun MainViewController(): UIViewController =
ComposeUIViewController { ComposeUIViewController {
JetSnackAppEntryPoint() JetsnackApp()
} }
Loading…
Cancel
Save