Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.CornerRadius
Expand All @@ -18,6 +20,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/** Container holding shared shimmer animation state. */
@Stable
class Shimmer internal constructor(
internal val translateState: State<Float>,
internal val gradientWidthFactor: Float,
Expand Down Expand Up @@ -46,7 +49,9 @@ fun rememberShimmer(
),
label = "RememberShimmerTranslate",
)
return Shimmer(translateState, gradientWidthFactor)
return remember(gradientWidthFactor) {
Shimmer(translateState, gradientWidthFactor)
}
}

/** Apply a remembered shimmer to this modifier. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import io.github.composegears.valkyrie.jewel.tooling.GlobalPreviewState
import io.github.composegears.valkyrie.sdk.shared.ValkyrieMode
import io.github.composegears.valkyrie.service.PersistentSettings.ValkyrieState
import io.github.composegears.valkyrie.ui.domain.model.PreviewType
import io.github.composegears.valkyrie.ui.screen.webimport.material.domain.model.font.MaterialFontSettings.Companion.DEFAULT_FILL
import io.github.composegears.valkyrie.ui.screen.webimport.material.domain.model.font.MaterialFontSettings.Companion.DEFAULT_GRADE
import io.github.composegears.valkyrie.ui.screen.webimport.material.domain.model.font.MaterialFontSettings.Companion.DEFAULT_OPTICAL_SIZE
import io.github.composegears.valkyrie.ui.screen.webimport.material.domain.model.font.MaterialFontSettings.Companion.DEFAULT_WEIGHT
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.model.SizeSettings.Companion.DEFAULT_SIZE
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.settings.SizeSettings.Companion.DEFAULT_SIZE
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.domain.model.MaterialFontSettings.Companion.DEFAULT_FILL
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.domain.model.MaterialFontSettings.Companion.DEFAULT_GRADE
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.domain.model.MaterialFontSettings.Companion.DEFAULT_OPTICAL_SIZE
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.domain.model.MaterialFontSettings.Companion.DEFAULT_WEIGHT

@State(name = "Valkyrie.Settings", storages = [Storage("valkyrie_settings.xml")])
class PersistentSettings : SimplePersistentStateComponent<ValkyrieState>(ValkyrieState()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import io.github.composegears.valkyrie.service.PersistentSettings.Companion.pers
import io.github.composegears.valkyrie.ui.domain.model.PreviewType
import io.github.composegears.valkyrie.ui.extension.or
import io.github.composegears.valkyrie.ui.extension.updateState
import io.github.composegears.valkyrie.ui.screen.webimport.material.domain.model.font.MaterialFontSettings.Companion.DEFAULT_FILL
import io.github.composegears.valkyrie.ui.screen.webimport.material.domain.model.font.MaterialFontSettings.Companion.DEFAULT_GRADE
import io.github.composegears.valkyrie.ui.screen.webimport.material.domain.model.font.MaterialFontSettings.Companion.DEFAULT_OPTICAL_SIZE
import io.github.composegears.valkyrie.ui.screen.webimport.material.domain.model.font.MaterialFontSettings.Companion.DEFAULT_WEIGHT
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.model.SizeSettings.Companion.DEFAULT_SIZE
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.settings.SizeSettings.Companion.DEFAULT_SIZE
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.domain.model.MaterialFontSettings.Companion.DEFAULT_FILL
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.domain.model.MaterialFontSettings.Companion.DEFAULT_GRADE
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.domain.model.MaterialFontSettings.Companion.DEFAULT_OPTICAL_SIZE
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.domain.model.MaterialFontSettings.Companion.DEFAULT_WEIGHT
import java.util.Collections.emptyList
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import com.composegears.tiamat.compose.Navigation
import com.composegears.tiamat.compose.navDestination
import com.composegears.tiamat.compose.navigationSlideInOut
import com.composegears.tiamat.compose.rememberNavController
import io.github.composegears.valkyrie.ui.screen.webimport.material.MaterialSymbolsImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.bootstrap.BootstrapImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.boxicons.BoxIconsImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.eva.EvaImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.feather.FeatherImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.fontawesome.FontAwesomeImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.ionicons.IoniconsImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.lucide.LucideImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.MaterialSymbolsImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.remix.RemixImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.tabler.TablerImportScreen

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ import io.github.composegears.valkyrie.ui.screen.webimport.IconProviders.Ionicon
import io.github.composegears.valkyrie.ui.screen.webimport.IconProviders.Lucide
import io.github.composegears.valkyrie.ui.screen.webimport.IconProviders.Remix
import io.github.composegears.valkyrie.ui.screen.webimport.IconProviders.Tabler
import io.github.composegears.valkyrie.ui.screen.webimport.material.MaterialSymbolsImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.bootstrap.BootstrapImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.boxicons.BoxIconsImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.eva.EvaImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.feather.FeatherImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.fontawesome.FontAwesomeImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.ionicons.IoniconsImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.lucide.LucideImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.materialsymbols.MaterialSymbolsImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.remix.RemixImportScreen
import io.github.composegears.valkyrie.ui.screen.webimport.standard.tabler.TablerImportScreen
import io.github.composegears.valkyrie.util.stringResource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.composegears.valkyrie.ui.screen.webimport.standard.common
package io.github.composegears.valkyrie.ui.screen.webimport.common

import androidx.compose.runtime.Stable
import androidx.lifecycle.ViewModel
Expand All @@ -8,21 +8,23 @@ import com.composegears.tiamat.navigation.asStateFlow
import com.composegears.tiamat.navigation.recordOf
import io.github.composegears.valkyrie.parser.unified.util.IconNameFormatter
import io.github.composegears.valkyrie.sdk.core.extensions.safeAs
import io.github.composegears.valkyrie.ui.screen.webimport.common.model.FontByteArray
import io.github.composegears.valkyrie.ui.screen.webimport.common.model.GridItem
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.domain.StandardIconProvider
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.model.IconStyle
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.model.InferredCategory
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.model.SizeSettings
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.model.StandardIcon
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.model.StandardIconConfig
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.util.filterByCategory
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.StandardIconProvider
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.category.InferredCategory
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.font.FontByteArray
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.icon.GridItem
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.icon.IconStyle
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.icon.StandardIcon
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.icon.StandardIconConfig
import io.github.composegears.valkyrie.ui.screen.webimport.common.domain.settings.SizeSettings
import io.github.composegears.valkyrie.ui.screen.webimport.common.util.filterByCategory
import kotlin.coroutines.cancellation.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.yield

class StandardIconViewModel(
savedState: MutableSavedState,
Expand Down Expand Up @@ -67,6 +69,8 @@ class StandardIconViewModel(
val styleKey = normalizedSelectedStyle?.id
restoredFont?.let { fontCache[styleKey] = it }

provider.onStyleChanged(normalizedSelectedStyle)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if (restoredFont == null) {
downloadFont(normalizedSelectedStyle)
}
Expand Down Expand Up @@ -105,6 +109,7 @@ class StandardIconViewModel(
settings = SizeSettings(size = provider.persistentSize),
selectedStyle = selectedStyle,
)
provider.onStyleChanged(selectedStyle)
downloadFont(selectedStyle)
prefetchStyleFonts(
styles = config.styles,
Expand All @@ -128,10 +133,18 @@ class StandardIconViewModel(

if (cachedFont == null) {
updateSuccess { it.copy(fontByteArray = null) }
// Yield so Compose renders the skeleton before font bytes arrive.
// Without this, providers with in-memory caches (suspendLazy) return
// instantly β€” both state updates are batched into one frame and the
// skeleton is never visible.
yield()
runCatching {
val bytes = provider.loadFontBytes(resolvedStyle)
fontCache[styleKey] = bytes
updateSuccess { it.copy(fontByteArray = bytes) }
}.onFailure { error ->
if (error is CancellationException) throw error
updateSuccess { it.copy(fontByteArray = null) }
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
} else {
updateSuccess { it.copy(fontByteArray = cachedFont) }
Expand All @@ -145,7 +158,7 @@ class StandardIconViewModel(
val currentState = stateRecord.value.safeAs<StandardState.Success>() ?: return@launch

runCatching {
val svgContent = provider.downloadSvg(icon, currentState.settings)
val svgContent = provider.downloadSvg(icon, currentState.settings, currentState.selectedStyle)

_events.send(
StandardIconEvent.IconDownloaded(
Expand Down Expand Up @@ -177,6 +190,7 @@ class StandardIconViewModel(
val cachedFont = withContext(Dispatchers.Main.immediate) {
fontCache[style.id]
}
provider.onStyleChanged(style)
updateSuccess { state ->
state.copy(
selectedStyle = style,
Expand Down
Loading
Loading