Skip to content

Commit

Permalink
improved ui and image loading
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 13, 2023
1 parent 73e5ca0 commit d0f7952
Show file tree
Hide file tree
Showing 32 changed files with 744 additions and 58 deletions.
1 change: 1 addition & 0 deletions app/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ kotlin {
api(libs.kamel)
api(libs.napier)
api(libs.moko.resources.compose)
api(libs.blurhash)

api(libs.windowsize.multiplatform)
api(libs.insetsx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package dev.datlag.burningseries.common

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.StackAnimation
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.fade
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.predictiveBackAnimation
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.stackAnimation
import com.arkivanov.essenty.backhandler.BackHandler
import com.vanniktech.blurhash.BlurHash
import com.vanniktech.blurhash.BlurHash.decode as defaultDecode

@OptIn(ExperimentalFoundationApi::class)
actual fun Modifier.onClick(
Expand All @@ -33,4 +38,9 @@ actual fun <C : Any, T : Any> backAnimation(
backHandler = backHandler,
animation = stackAnimation(fade()),
onBack = onBack
)
)

actual fun BlurHash.decode(hash: String, width: Int, height: Int): ImageBitmap? {
val bitmap = defaultDecode(hash, width, height)
return bitmap?.asImageBitmap()
}
14 changes: 8 additions & 6 deletions app/shared/src/commonMain/kotlin/dev/datlag/burningseries/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import com.moriatsushi.insetsx.rememberWindowInsetsController
import dev.datlag.burningseries.ui.theme.Colors
import dev.datlag.burningseries.ui.theme.CommonSchemeTheme
import dev.datlag.burningseries.ui.theme.toLegacyColors
import dev.datlag.burningseries.ui.theme.toLegacyShapes
import dev.datlag.burningseries.shared.SharedRes
import dev.datlag.burningseries.ui.theme.*
import dev.icerock.moko.resources.compose.fontFamilyResource
import org.kodein.di.DI

val LocalDarkMode = compositionLocalOf<Boolean> { error("No dark mode state provided") }
Expand All @@ -37,11 +37,13 @@ fun App(
LocalDarkMode provides systemDarkTheme
) {
MaterialTheme(
colorScheme = if (systemDarkTheme) Colors.getDarkScheme() else Colors.getLightScheme()
colorScheme = if (systemDarkTheme) Colors.getDarkScheme() else Colors.getLightScheme(),
typography = ManropeTypography()
) {
androidx.compose.material.MaterialTheme(
colors = MaterialTheme.colorScheme.toLegacyColors(systemDarkTheme),
shapes = MaterialTheme.shapes.toLegacyShapes()
shapes = MaterialTheme.shapes.toLegacyShapes(),
typography = ManropeTypographyLegacy()
) {
SystemProvider {
CommonSchemeTheme {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.datlag.burningseries.common

import com.vanniktech.blurhash.BlurHash

fun BlurHash.random(): String {
val list = listOf(
"LEHLh[WB2yk8pyoJadR*.7kCMdnj",
"LKN]Rv%2Tw=w]~RBVZRi};RPxuwH",
"L4D9hwcE00~WL#V@%~\$%00ad~qIA",
"LBFh@Z=wrY\$_~obE\$+t6NPIpIqa7",
"LLJGsB{y0NNY^jn\$RPXTso\$zt7R*",
"LSNAhr00.TbI%M-=%NayS\$f9IUM{"
)
return list.random()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.DpSize
import dev.datlag.burningseries.ui.theme.shape.DiagonalShape

inline fun Modifier.ifTrue(predicate: Boolean, builder: Modifier.() -> Modifier) = then(if (predicate) builder() else Modifier)
Expand Down Expand Up @@ -65,4 +67,11 @@ fun Modifier.pressClick(maxTranslation: Float = 10F) = composed {
fun Modifier.diagonalShape(
angle: Float,
position: DiagonalShape.POSITION = DiagonalShape.POSITION.TOP
) = this.clip(DiagonalShape(angle, position))
) = this.clip(DiagonalShape(angle, position))

fun DpSize.toSize(): Size {
return Size(
width = this.width.value,
height = this.height.value
)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.datlag.burningseries.common

import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.StackAnimation
import com.arkivanov.decompose.router.stack.StackNavigation
import com.arkivanov.essenty.backhandler.BackHandler
import com.vanniktech.blurhash.BlurHash

expect fun Modifier.onClick(
enabled: Boolean = true,
Expand All @@ -15,4 +17,10 @@ expect fun Modifier.onClick(
expect fun <C : Any, T : Any> backAnimation(
backHandler: BackHandler,
onBack: () -> Unit
) : StackAnimation<C, T>
) : StackAnimation<C, T>

expect fun BlurHash.decode(
hash: String,
width: Int,
height: Int
): ImageBitmap?
Loading

0 comments on commit d0f7952

Please sign in to comment.