diff --git a/examples/jetsnack/android/build.gradle.kts b/examples/jetsnack/android/build.gradle.kts index b8904fd7ec..2c73ab43eb 100644 --- a/examples/jetsnack/android/build.gradle.kts +++ b/examples/jetsnack/android/build.gradle.kts @@ -13,6 +13,7 @@ repositories { } dependencies { + implementation(compose.components.resources) implementation(project(":common")) implementation("androidx.activity:activity-compose:1.5.0") } diff --git a/examples/jetsnack/android/src/main/java/com/example/android/MainActivity.kt b/examples/jetsnack/android/src/main/java/com/example/android/MainActivity.kt index 17c8f84568..0971268a4f 100644 --- a/examples/jetsnack/android/src/main/java/com/example/android/MainActivity.kt +++ b/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.appcompat.app.AppCompatActivity 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.theme.Karla -import com.example.jetsnack.ui.theme.Montserrat class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { 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 { MaterialTheme { JetsnackApp() diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/drawableResources.android.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/drawableResources.android.kt deleted file mode 100644 index f17000c779..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/drawableResources.android.kt +++ /dev/null @@ -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 - diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/stringResource.android.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/stringResource.android.kt deleted file mode 100644 index 68b497ec9e..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/stringResource.android.kt +++ /dev/null @@ -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 \ No newline at end of file diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/JetsnackScaffoldContent.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/JetsnackScaffoldContent.kt deleted file mode 100644 index 61281fa863..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/JetsnackScaffoldContent.kt +++ /dev/null @@ -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) - } -} \ No newline at end of file diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/MppJetsnackAppState.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/MppJetsnackAppState.kt deleted file mode 100644 index 0349d7ecba..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/MppJetsnackAppState.kt +++ /dev/null @@ -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 - 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 -} \ No newline at end of file diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/components/SnackAsyncImage.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/components/SnackAsyncImage.kt deleted file mode 100644 index bfd48c5078..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/components/SnackAsyncImage.kt +++ /dev/null @@ -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() - -@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) -} \ No newline at end of file diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/SnackDialog.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/SnackDialog.kt deleted file mode 100644 index 3d9cd7f2f9..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/SnackDialog.kt +++ /dev/null @@ -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) -} \ No newline at end of file diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/Cart.android.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/Cart.android.kt deleted file mode 100644 index 204cd043f4..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/Cart.android.kt +++ /dev/null @@ -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)) -} \ No newline at end of file diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/CartViewModel.android.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/CartViewModel.android.kt deleted file mode 100644 index e0c5f8f018..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/cart/CartViewModel.android.kt +++ /dev/null @@ -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 create(modelClass: Class): T { - return CartViewModel(snackbarManager, snackRepository) as T - } -} - -@OptIn(kotlin.ExperimentalMultiplatform::class) -actual abstract class JetSnackCartViewModel actual constructor() : ViewModel() { - @Composable - actual fun collectOrderLinesAsState(flow: StateFlow>): State> { - return flow.collectAsStateWithLifecycle() - } -} \ No newline at end of file diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/snackCollectionListItemWindowInsets.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/snackCollectionListItemWindowInsets.kt deleted file mode 100644 index ea94ef244e..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/home/snackCollectionListItemWindowInsets.kt +++ /dev/null @@ -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)) -} \ No newline at end of file diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/snackdetail/jetSnackNavigationBarsPadding.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/snackdetail/jetSnackNavigationBarsPadding.kt deleted file mode 100644 index de2c3375fe..0000000000 --- a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/snackdetail/jetSnackNavigationBarsPadding.kt +++ /dev/null @@ -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() \ No newline at end of file diff --git a/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/utils/formatPrice.kt b/examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/utils/Currency.android.kt similarity index 100% rename from examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/utils/formatPrice.kt rename to examples/jetsnack/common/src/androidMain/kotlin/com/example/jetsnack/ui/utils/Currency.android.kt diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/almonds.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/almonds.jpg deleted file mode 100644 index 0f1eef57e3..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/almonds.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/apple_chips.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/apple_chips.jpg deleted file mode 100644 index 37c805d169..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/apple_chips.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/apple_juice.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/apple_juice.jpg deleted file mode 100644 index d519dbcd46..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/apple_juice.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/apple_pie.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/apple_pie.jpg deleted file mode 100644 index 41096b2216..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/apple_pie.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/apple_sauce.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/apple_sauce.jpg deleted file mode 100644 index 7f5331ee24..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/apple_sauce.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/apples.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/apples.jpg deleted file mode 100644 index cc729f1646..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/apples.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/cheese.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/cheese.jpg deleted file mode 100644 index c5c6dce61c..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/cheese.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/chips.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/chips.jpg deleted file mode 100644 index 04d5fe2cd3..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/chips.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/cupcake.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/cupcake.jpg deleted file mode 100644 index 42e766d843..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/cupcake.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/desserts.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/desserts.jpg deleted file mode 100644 index 6d44990765..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/desserts.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/donut.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/donut.jpg deleted file mode 100644 index 076896a812..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/donut.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/eclair.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/eclair.jpg deleted file mode 100644 index 5601780345..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/eclair.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/froyo.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/froyo.jpg deleted file mode 100644 index e1bb068cc9..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/froyo.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/fruit.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/fruit.jpg deleted file mode 100644 index 4122473184..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/fruit.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/gingerbread.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/gingerbread.jpg deleted file mode 100644 index ac069de103..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/gingerbread.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/gluten_free.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/gluten_free.jpg deleted file mode 100644 index 0745457a36..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/gluten_free.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/grapes.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/grapes.jpg deleted file mode 100644 index 3b573787cf..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/grapes.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/honeycomb.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/honeycomb.jpg deleted file mode 100644 index ea632bd25d..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/honeycomb.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/ice_cream_sandwich.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/ice_cream_sandwich.jpg deleted file mode 100644 index fd77631e9a..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/ice_cream_sandwich.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/jelly_bean.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/jelly_bean.jpg deleted file mode 100644 index 84a10208c9..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/jelly_bean.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/kitkat.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/kitkat.jpg deleted file mode 100644 index 75b2e44abb..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/kitkat.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/kiwi.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/kiwi.jpg deleted file mode 100644 index 2197fbd48f..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/kiwi.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/lollipop.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/lollipop.jpg deleted file mode 100644 index 98d1db7d2f..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/lollipop.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/mango.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/mango.jpg deleted file mode 100644 index 717773d7b5..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/mango.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/marshmallow.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/marshmallow.jpg deleted file mode 100644 index cdc1159226..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/marshmallow.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/nougat.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/nougat.jpg deleted file mode 100644 index 1a844d9b9f..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/nougat.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/nuts.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/nuts.jpg deleted file mode 100644 index 03556767ec..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/nuts.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/oreo.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/oreo.jpg deleted file mode 100644 index cf2c3e534c..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/oreo.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/organic.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/organic.jpg deleted file mode 100644 index 2847abf4f0..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/organic.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/paleo.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/paleo.jpg deleted file mode 100644 index 750fcd58e7..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/paleo.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/pie.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/pie.jpg deleted file mode 100644 index 439c18cfbb..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/pie.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/placeholder.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/placeholder.jpg deleted file mode 100644 index 31e05faacb..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/placeholder.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/popcorn.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/popcorn.jpg deleted file mode 100644 index 02713ffdbf..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/popcorn.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/pretzels.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/pretzels.jpg deleted file mode 100644 index d31d4aa4eb..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/pretzels.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/smoothies.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/smoothies.jpg deleted file mode 100644 index f2eaa31bf1..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/smoothies.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/commonMain/composeResources/files/vegan.jpg b/examples/jetsnack/common/src/commonMain/composeResources/files/vegan.jpg deleted file mode 100644 index 29276a68b7..0000000000 Binary files a/examples/jetsnack/common/src/commonMain/composeResources/files/vegan.jpg and /dev/null differ diff --git a/examples/jetsnack/common/src/androidMain/res/font/karla_bold.ttf b/examples/jetsnack/common/src/commonMain/composeResources/font/karla_bold.ttf similarity index 100% rename from examples/jetsnack/common/src/androidMain/res/font/karla_bold.ttf rename to examples/jetsnack/common/src/commonMain/composeResources/font/karla_bold.ttf diff --git a/examples/jetsnack/common/src/androidMain/res/font/karla_regular.ttf b/examples/jetsnack/common/src/commonMain/composeResources/font/karla_regular.ttf similarity index 100% rename from examples/jetsnack/common/src/androidMain/res/font/karla_regular.ttf rename to examples/jetsnack/common/src/commonMain/composeResources/font/karla_regular.ttf diff --git a/examples/jetsnack/common/src/androidMain/res/font/montserrat_light.ttf b/examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_light.ttf similarity index 100% rename from examples/jetsnack/common/src/androidMain/res/font/montserrat_light.ttf rename to examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_light.ttf diff --git a/examples/jetsnack/common/src/androidMain/res/font/montserrat_medium.ttf b/examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_medium.ttf similarity index 100% rename from examples/jetsnack/common/src/androidMain/res/font/montserrat_medium.ttf rename to examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_medium.ttf diff --git a/examples/jetsnack/common/src/androidMain/res/font/montserrat_regular.ttf b/examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_regular.ttf similarity index 100% rename from examples/jetsnack/common/src/androidMain/res/font/montserrat_regular.ttf rename to examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_regular.ttf diff --git a/examples/jetsnack/common/src/androidMain/res/font/montserrat_semibold.ttf b/examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_semibold.ttf similarity index 100% rename from examples/jetsnack/common/src/androidMain/res/font/montserrat_semibold.ttf rename to examples/jetsnack/common/src/commonMain/composeResources/font/montserrat_semibold.ttf diff --git a/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/model/Filter.kt b/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/model/Filter.kt index e8d1862935..8b0e8ddf9c 100644 --- a/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/model/Filter.kt +++ b/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/model/Filter.kt @@ -16,13 +16,13 @@ package com.example.jetsnack.model -//import androidx.compose.material3.icons.Icons -//import androidx.compose.material3.icons.filled.Star +import androidx.compose.material.icons.Icons +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.mutableStateOf import androidx.compose.ui.graphics.vector.ImageVector -//import com.example.jetsnack.Android -//import com.example.jetsnack.SortByAlpha @Stable class Filter( @@ -32,6 +32,7 @@ class Filter( ) { val enabled = mutableStateOf(enabled) } + val filters = listOf( Filter(name = "Organic"), Filter(name = "Gluten-free"), @@ -45,10 +46,10 @@ val priceFilters = listOf( Filter(name = "$$$"), Filter(name = "$$$$") ) -val sortFilters = listOf( - Filter(name = "Android's favorite (default)"), - Filter(name = "Rating",), - Filter(name = "Alphabetical",) +val sortFilters = listOf( + Filter(name = "Android's favorite (default)", icon = Icons.Filled.Android), + Filter(name = "Rating", icon = Icons.Filled.Star), + Filter(name = "Alphabetical", icon = Icons.Filled.SortByAlpha) ) val categoryFilters = listOf( diff --git a/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/components/GradientTintedIconButton.kt b/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/components/GradientTintedIconButton.kt index e709b3416e..6dc687485e 100644 --- a/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/components/GradientTintedIconButton.kt +++ b/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/components/GradientTintedIconButton.kt @@ -91,17 +91,4 @@ fun JetsnackGradientTintedIconButton( modifier = modifierColor ) } -} - -//@Preview -@Composable -private fun GradientTintedIconButtonPreview() { - JetsnackTheme { -// JetsnackGradientTintedIconButton( -// imageVector = Icons.Default.Add, -// onClick = {}, -// contentDescription = "Demo", -// modifier = Modifier.padding(4.dp) -// ) - } -} +} \ No newline at end of file diff --git a/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Theme.kt b/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Theme.kt index 610a514514..fe6ff88cce 100644 --- a/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Theme.kt +++ b/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Theme.kt @@ -17,15 +17,11 @@ package com.example.jetsnack.ui.theme import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.ColorScheme import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.SideEffect -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.Immutable import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color @@ -88,17 +84,9 @@ fun JetsnackTheme( ) { 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) { MaterialTheme( -// colors = debugColors(darkTheme), + colorScheme = debugColors(darkTheme), typography = Typography, shapes = Shapes, content = content @@ -115,169 +103,44 @@ object JetsnackTheme { /** * Jetsnack custom Color Palette */ -@Stable -class JetsnackColors( - gradient6_1: List, - gradient6_2: List, - gradient3_1: List, - gradient3_2: List, - gradient2_1: List, - gradient2_2: List, - gradient2_3: List, - brand: Color, - brandSecondary: Color, - uiBackground: Color, - uiBorder: Color, - uiFloated: Color, - interactivePrimary: List = gradient2_1, - interactiveSecondary: List = gradient2_2, - interactiveMask: List = gradient6_1, - textPrimary: Color = brand, - textSecondary: Color, - textHelp: Color, - textInteractive: Color, - textLink: Color, - tornado1: List, - iconPrimary: Color = brand, - iconSecondary: Color, - iconInteractive: Color, - iconInteractiveInactive: Color, - error: Color, - notificationBadge: Color = error, - 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, - ) -} +@Immutable +data class JetsnackColors( + val gradient6_1: List, + val gradient6_2: List, + val gradient3_1: List, + val gradient3_2: List, + val gradient2_1: List, + val gradient2_2: List, + val gradient2_3: List, + val brand: Color, + val brandSecondary: Color, + val uiBackground: Color, + val uiBorder: Color, + val uiFloated: Color, + val interactivePrimary: List = gradient2_1, + val interactiveSecondary: List = gradient2_2, + val interactiveMask: List = gradient6_1, + val textPrimary: Color = brand, + val textSecondary: Color, + val textHelp: Color, + val textInteractive: Color, + val textLink: Color, + val tornado1: List, + val iconPrimary: Color = brand, + val iconSecondary: Color, + val iconInteractive: Color, + val iconInteractiveInactive: Color, + val error: Color, + val notificationBadge: Color = error, + val isDark: Boolean +) @Composable fun ProvideJetsnackColors( colors: JetsnackColors, content: @Composable () -> Unit ) { - val colorPalette = remember { - // 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) + CompositionLocalProvider(LocalJetsnackColors provides colors, content = content) } private val LocalJetsnackColors = staticCompositionLocalOf { @@ -286,23 +149,46 @@ private val LocalJetsnackColors = staticCompositionLocalOf { /** * 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( -// darkTheme: Boolean, -// debugColor: Color = Color.Magenta -//) = Colors( -// primary = debugColor, -// primaryVariant = debugColor, -// secondary = debugColor, -// secondaryVariant = debugColor, -// background = debugColor, -// surface = debugColor, -// error = debugColor, -// onPrimary = debugColor, -// onSecondary = debugColor, -// onBackground = debugColor, -// onSurface = debugColor, -// onError = debugColor, -// isLight = !darkTheme -//) +fun debugColors( + darkTheme: Boolean, + debugColor: Color = Color.Magenta +) = ColorScheme( + primary = debugColor, + onPrimary = debugColor, + primaryContainer = debugColor, + onPrimaryContainer = debugColor, + inversePrimary = debugColor, + secondary = debugColor, + onSecondary = debugColor, + secondaryContainer = debugColor, + onSecondaryContainer = debugColor, + tertiary = debugColor, + onTertiary = debugColor, + tertiaryContainer = debugColor, + 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, +) diff --git a/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Type.kt b/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Type.kt index e50001ef0b..69ab53cab7 100644 --- a/examples/jetsnack/common/src/commonMain/kotlin/com/example/jetsnack/ui/theme/Type.kt +++ b/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 Karla: FontFamily? = null // init in platform code -val Typography by lazy { - Typography( -// h1 = TextStyle( -// fontFamily = Montserrat, -// fontSize = 96.sp, -// fontWeight = FontWeight.Light, -// lineHeight = 117.sp, -// letterSpacing = (-1.5).sp, -// ), -// h2 = TextStyle( -// fontFamily = Montserrat, -// fontSize = 60.sp, -// fontWeight = FontWeight.Light, -// lineHeight = 73.sp, -// letterSpacing = (-0.5).sp -// ), -// h3 = TextStyle( -// fontFamily = Montserrat, -// fontSize = 48.sp, -// fontWeight = FontWeight.Normal, -// lineHeight = 59.sp -// ), -// h4 = TextStyle( -// fontFamily = Montserrat, -// fontSize = 30.sp, -// fontWeight = FontWeight.SemiBold, -// lineHeight = 37.sp -// ), -// h5 = TextStyle( -// fontFamily = Montserrat, -// fontSize = 24.sp, -// fontWeight = FontWeight.SemiBold, -// lineHeight = 29.sp -// ), -// h6 = TextStyle( -// fontFamily = Montserrat, -// fontSize = 20.sp, -// fontWeight = FontWeight.SemiBold, -// lineHeight = 24.sp -// ), -// subtitle1 = TextStyle( -// fontFamily = Montserrat, -// fontSize = 16.sp, -// fontWeight = FontWeight.SemiBold, -// lineHeight = 24.sp, -// letterSpacing = 0.15.sp -// ), -// subtitle2 = TextStyle( -// fontFamily = Karla, -// fontSize = 14.sp, -// fontWeight = FontWeight.Bold, -// lineHeight = 24.sp, -// letterSpacing = 0.1.sp -// ), -// body1 = TextStyle( -// fontFamily = Karla, -// fontSize = 16.sp, -// fontWeight = FontWeight.Normal, -// lineHeight = 28.sp, -// letterSpacing = 0.15.sp -// ), -// body2 = TextStyle( -// fontFamily = Montserrat, -// fontSize = 14.sp, -// fontWeight = FontWeight.Medium, -// lineHeight = 20.sp, -// letterSpacing = 0.25.sp -// ), -// button = TextStyle( -// fontFamily = Montserrat, -// fontSize = 14.sp, -// fontWeight = FontWeight.SemiBold, -// lineHeight = 16.sp, -// letterSpacing = 1.25.sp -// ), -// caption = TextStyle( -// fontFamily = Karla, -// fontSize = 12.sp, -// fontWeight = FontWeight.Bold, -// lineHeight = 16.sp, -// letterSpacing = 0.4.sp -// ), -// overline = TextStyle( -// fontFamily = Montserrat, -// fontSize = 12.sp, -// fontWeight = FontWeight.SemiBold, -// lineHeight = 16.sp, -// letterSpacing = 1.sp -// ) +val Typography = Typography( + displayLarge = TextStyle( + fontFamily = Montserrat, + fontSize = 96.sp, + fontWeight = FontWeight.Light, + lineHeight = 117.sp, + letterSpacing = (-1.5).sp + ), + displayMedium = TextStyle( + fontFamily = Montserrat, + fontSize = 60.sp, + fontWeight = FontWeight.Light, + lineHeight = 73.sp, + letterSpacing = (-0.5).sp + ), + displaySmall = TextStyle( + fontFamily = Montserrat, + fontSize = 48.sp, + fontWeight = FontWeight.Normal, + lineHeight = 59.sp + ), + headlineMedium = TextStyle( + fontFamily = Montserrat, + fontSize = 30.sp, + fontWeight = FontWeight.SemiBold, + lineHeight = 37.sp + ), + headlineSmall = TextStyle( + fontFamily = Montserrat, + fontSize = 24.sp, + fontWeight = FontWeight.SemiBold, + lineHeight = 29.sp + ), + titleLarge = TextStyle( + fontFamily = Montserrat, + fontSize = 20.sp, + fontWeight = FontWeight.SemiBold, + lineHeight = 24.sp + ), + titleMedium = TextStyle( + fontFamily = Montserrat, + fontSize = 16.sp, + fontWeight = FontWeight.SemiBold, + lineHeight = 24.sp, + letterSpacing = 0.15.sp + ), + titleSmall = TextStyle( + fontFamily = Karla, + fontSize = 14.sp, + fontWeight = FontWeight.Bold, + lineHeight = 24.sp, + letterSpacing = 0.1.sp + ), + bodyLarge = TextStyle( + fontFamily = Karla, + fontSize = 16.sp, + fontWeight = FontWeight.Normal, + lineHeight = 28.sp, + letterSpacing = 0.15.sp + ), + bodyMedium = TextStyle( + fontFamily = Montserrat, + fontSize = 14.sp, + fontWeight = FontWeight.Medium, + lineHeight = 20.sp, + letterSpacing = 0.25.sp + ), + labelLarge = TextStyle( + fontFamily = Montserrat, + fontSize = 14.sp, + fontWeight = FontWeight.SemiBold, + lineHeight = 16.sp, + letterSpacing = 1.25.sp + ), + bodySmall = TextStyle( + fontFamily = Karla, + fontSize = 12.sp, + fontWeight = FontWeight.Bold, + lineHeight = 16.sp, + letterSpacing = 0.4.sp + ), + labelSmall = TextStyle( + fontFamily = Montserrat, + fontSize = 12.sp, + fontWeight = FontWeight.SemiBold, + lineHeight = 16.sp, + letterSpacing = 1.sp ) -} +) diff --git a/examples/jetsnack/common/src/iosMain/kotlin/com/example/jetsnack/ui/main.ios.kt b/examples/jetsnack/common/src/iosMain/kotlin/com/example/jetsnack/ui/main.ios.kt index 703480ffa1..a22d5a0ba6 100644 --- a/examples/jetsnack/common/src/iosMain/kotlin/com/example/jetsnack/ui/main.ios.kt +++ b/examples/jetsnack/common/src/iosMain/kotlin/com/example/jetsnack/ui/main.ios.kt @@ -1,10 +1,9 @@ package com.example.jetsnack.ui import androidx.compose.ui.window.ComposeUIViewController -import com.example.jetsnack.JetSnackAppEntryPoint import platform.UIKit.UIViewController fun MainViewController(): UIViewController = ComposeUIViewController { - JetSnackAppEntryPoint() + JetsnackApp() } \ No newline at end of file