Skip to content

Commit

Permalink
Merge pull request #7 from SEAbdulbasit/bump-compose-version
Browse files Browse the repository at this point in the history
Bump compose version
  • Loading branch information
SEAbdulbasit authored Mar 23, 2024
2 parents 84bd4c8 + a70c2a6 commit 1d7d997
Show file tree
Hide file tree
Showing 42 changed files with 278 additions and 479 deletions.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ agp.version=7.4.2
#Versions
kotlin.version=1.9.20
compose.version=1.5.10
compose.wasm.version=1.5.10-dev-wasm03
compose.wasm.version=1.6.0-beta01
org.jetbrains.compose.experimental.wasm.enabled=true
org.jetbrains.compose.experimental.jscanvas.enabled=true
compose.compiler.version=1.5.3
#kotlin.experimental.tryK2=true
Expand Down
5 changes: 1 addition & 4 deletions iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@ struct ContentView: View {
ComposeView()
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler
}
}



}
3 changes: 0 additions & 3 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ kotlin {
api("androidx.activity:activity-compose:1.8.0")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.core:core-ktx:1.12.0")
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
}
}
val iosX64Main by getting
Expand All @@ -62,14 +61,12 @@ kotlin {
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
dependencies {
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
}
}
val desktopMain by getting {
dependencies {
implementation(compose.desktop.common)
dependencies {
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
}
}
}
Expand Down
18 changes: 0 additions & 18 deletions shared/src/androidMain/kotlin/font.kt

This file was deleted.

File renamed without changes
165 changes: 69 additions & 96 deletions shared/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,188 +4,161 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Typography
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import details.RecipeDetails
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import model.recipesList
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.resource
import org.jetbrains.compose.resources.Font
import recipeappkmp.shared.generated.resources.Res
import recipeslist.RecipesListScreen
import sensor.SensorManager
import sharedelementtransaction.*

@OptIn(ExperimentalResourceApi::class)
@Composable
fun App(sensorManager: SensorManager, isLarge: Boolean = false) {

var rubikRegular by remember { mutableStateOf<FontFamily?>(null) }
var rubikSemiBold by remember { mutableStateOf<FontFamily?>(null) }
var rubikBold by remember { mutableStateOf<FontFamily?>(null) }
val platformContext = getPlatformContext()

LaunchedEffect(Unit) {
launch(Dispatchers.Unconfined) {
rubikRegular =
FontFamily(font("Rubik", "rubik_regular", FontWeight.Normal, FontStyle.Normal, platformContext))
}
launch(Dispatchers.Unconfined) {
rubikSemiBold =
FontFamily(font("Rubik", "rubik_medium", FontWeight.SemiBold, FontStyle.Normal, platformContext))
}
launch(Dispatchers.Unconfined) {
rubikBold = FontFamily(font("Rubik", "rubik_bold", FontWeight.Bold, FontStyle.Normal, platformContext))
}
}
val rubikFamily = FontFamily(
listOf(
Font(Res.font.rubik_light),
Font(Res.font.rubik_medium),
Font(Res.font.rubik_regular),
Font(Res.font.rubik_bold)
)
)

val typo = Typography(
h1 = TextStyle(
fontWeight = FontWeight.Light,
fontSize = 45.sp,
letterSpacing = (-1.5).sp,
fontFamily = rubikBold
fontFamily = rubikFamily
),
h2 = TextStyle(
fontWeight = FontWeight.Light,
fontSize = 35.sp,
letterSpacing = (-0.5).sp,
fontFamily = rubikBold
fontFamily = rubikFamily
),
h3 = TextStyle(
fontWeight = FontWeight.Normal,
fontSize = 30.sp,
letterSpacing = 0.sp,
fontFamily = rubikBold
fontFamily = rubikFamily
),
h4 = TextStyle(
fontWeight = FontWeight.Normal,
fontSize = 25.sp,
letterSpacing = 0.25.sp,
fontFamily = rubikBold
fontFamily = rubikFamily
),
h5 = TextStyle(
fontWeight = FontWeight.Normal,
fontSize = 20.sp,
letterSpacing = 0.sp,
fontFamily = rubikBold
fontFamily = rubikFamily
),
h6 = TextStyle(
fontWeight = FontWeight.Medium,
fontSize = 20.sp,
letterSpacing = 0.15.sp,
fontFamily = rubikSemiBold
fontFamily = rubikFamily
),
subtitle1 = TextStyle(
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
letterSpacing = 0.15.sp,
fontFamily = rubikSemiBold
fontFamily = rubikFamily
),
subtitle2 = TextStyle(
fontWeight = FontWeight.Medium,
fontSize = 14.sp,
letterSpacing = 0.1.sp,
fontFamily = rubikSemiBold
fontFamily = rubikFamily
),
body1 = TextStyle(
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
letterSpacing = 0.5.sp,
fontFamily = rubikRegular
fontFamily = rubikFamily
),
body2 = TextStyle(
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
letterSpacing = 0.25.sp,
fontFamily = rubikRegular
fontFamily = rubikFamily
),
button = TextStyle(
fontWeight = FontWeight.Medium,
fontSize = 14.sp,
letterSpacing = 1.25.sp,
fontFamily = rubikRegular
fontFamily = rubikFamily
),
caption = TextStyle(
fontWeight = FontWeight.Normal,
fontSize = 12.sp,
letterSpacing = 0.4.sp,
fontFamily = rubikRegular
fontFamily = rubikFamily
),
overline = TextStyle(
fontWeight = FontWeight.Normal,
fontSize = 10.sp,
letterSpacing = 1.5.sp,
fontFamily = rubikRegular
fontFamily = rubikFamily
)
)

if (rubikRegular != null && rubikBold != null && rubikSemiBold != null) {
MaterialTheme(typography = typo) {
val items by remember { mutableStateOf(recipesList) }
var width by remember { mutableStateOf(0) }
var currentScreen by remember { mutableStateOf<Screens>(Screens.RecipesList) }
var updateIds by remember { mutableStateOf("") }
MaterialTheme(typography = typo) {
val items by remember { mutableStateOf(recipesList) }
var width by remember { mutableStateOf(0) }
var currentScreen by remember { mutableStateOf<Screens>(Screens.RecipesList) }
var updateIds by remember { mutableStateOf("") }

Box(modifier = Modifier.fillMaxSize().onGloballyPositioned {
width = it.size.width
})

SharedElementsRoot {
val sharedTransaction = this
Box {
RecipesListScreen(isLarge = isLarge,
items = items,
width = width,
updateIds = updateIds,
onClick = { recipe ->
prepareTransition(
recipe.id, recipe.description, recipe.title, recipe.image
)
updateIds = "update_dummy_ids"
currentScreen = Screens.RecipeDetails(
recipe = recipe,
)
})

when (val screen = currentScreen) {
is Screens.RecipeDetails -> {
RecipeDetails(isLarge = isLarge,
sensorManager = sensorManager,
recipe = screen.recipe,
goBack = {
updateIds = ""
sharedTransaction.prepareTransition()
prepareTransition(
screen.recipe.id,
screen.recipe.description,
screen.recipe.title,
screen.recipe.image
)
currentScreen = Screens.RecipesList
})

val chefImage = remember { mutableStateOf<ImageBitmap?>(null) }
LaunchedEffect(Unit) {
withContext(Dispatchers.Default) {
chefImage.value = resource("chef.png").readBytes().toImageBitmap()
}
}

Box(modifier = Modifier.fillMaxSize().onGloballyPositioned {
width = it.size.width
})

SharedElementsRoot {
val sharedTransaction = this
Box {
RecipesListScreen(isLarge = isLarge,
items = items,
width = width,
updateIds = updateIds,
onClick = { recipe, imageBitmap ->
prepareTransition(
recipe.id, recipe.description, recipe.title, recipe.image
)
updateIds = "update_dummy_ids"
currentScreen = Screens.RecipeDetails(
recipe = recipe,
imageBitmap = imageBitmap,
)
})

when (val screen = currentScreen) {
is Screens.RecipeDetails -> {
RecipeDetails(isLarge = isLarge,
sensorManager = sensorManager,
recipe = screen.recipe,
imageBitmap = screen.imageBitmap,
chefImage = chefImage.value,
goBack = {
updateIds = ""
sharedTransaction.prepareTransition()
prepareTransition(
screen.recipe.id,
screen.recipe.description,
screen.recipe.title,
screen.recipe.image
)
currentScreen = Screens.RecipesList
})

}
}

Screens.RecipesList -> {
// do nothing
}
Screens.RecipesList -> {
// do nothing
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions shared/src/commonMain/kotlin/Resources.kt

This file was deleted.

4 changes: 1 addition & 3 deletions shared/src/commonMain/kotlin/Screen.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import androidx.compose.ui.graphics.ImageBitmap
import model.Recipe

/**
Expand All @@ -7,7 +6,6 @@ import model.Recipe
sealed interface Screens {
object RecipesList : Screens
data class RecipeDetails(
val recipe: Recipe,
val imageBitmap: ImageBitmap
val recipe: Recipe
) : Screens
}
22 changes: 10 additions & 12 deletions shared/src/commonMain/kotlin/details/IngradientItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ import androidx.compose.ui.draw.rotate
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import model.Recipe
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource
import recipeappkmp.shared.generated.resources.Res

@OptIn(ExperimentalResourceApi::class)
@Composable
fun IngredientItem(recipe: Recipe, ingredient: String, chefImage: ImageBitmap?) {
fun IngredientItem(recipe: Recipe, ingredient: String) {
Box(modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 8.dp)) {
Box(
modifier = Modifier
Expand Down Expand Up @@ -65,17 +66,14 @@ fun IngredientItem(recipe: Recipe, ingredient: String, chefImage: ImageBitmap?)
CircleShape
),
) {
chefImage?.let {
Image(
bitmap = it,
contentDescription = null,
modifier = Modifier.padding(12.dp).rotate(-30f),
colorFilter = ColorFilter.tint(if (recipe.bgColor.luminance() > 0.3) Color.Companion.Black else Color.White)
)
}
Image(
painter = painterResource(Res.drawable.chef),
contentDescription = null,
modifier = Modifier.padding(12.dp).rotate(-30f),
colorFilter = ColorFilter.tint(if (recipe.bgColor.luminance() > 0.3) Color.Companion.Black else Color.White)
)

}
}
}


}
Loading

0 comments on commit 1d7d997

Please sign in to comment.