Skip to content

Commit

Permalink
Fix remembers painter twice to break the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
devkanro committed Feb 17, 2024
1 parent d8ddff1 commit 0e039d8
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 15 deletions.
4 changes: 4 additions & 0 deletions foundation/api/foundation.api
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,7 @@ public final class org/jetbrains/jewel/foundation/theme/ThemeIconData$Companion
public final fun getEmpty ()Lorg/jetbrains/jewel/foundation/theme/ThemeIconData;
}

public final class org/jetbrains/jewel/foundation/util/DebugKt {
public static final fun getInDebugMode ()Z
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.jewel.ui.util
package org.jetbrains.jewel.foundation.util

import org.jetbrains.jewel.foundation.InternalJewelApi

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.jewel.foundation.utils
package org.jetbrains.jewel.foundation.util

internal enum class LogLevel(val color: String) {
Trace("\u001b[38;5;33m"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.jetbrains.jewel.ui.painter.hints.ColorBasedPaletteReplacement
import org.jetbrains.jewel.ui.painter.hints.Dark
import org.jetbrains.jewel.ui.painter.hints.HiDpi
import org.jetbrains.jewel.ui.painter.hints.KeyBasedPaletteReplacement
import org.jetbrains.jewel.ui.util.inDebugMode
import org.jetbrains.jewel.foundation.util.inDebugMode
import org.jetbrains.jewel.ui.util.toRgbaHexString

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.jetbrains.jewel.ui.painter.hints.Dark
import org.jetbrains.jewel.ui.painter.hints.HiDpi
import org.jetbrains.jewel.ui.painter.hints.KeyBasedPaletteReplacement
import org.jetbrains.jewel.ui.painter.hints.PathOverride
import org.jetbrains.jewel.ui.util.inDebugMode
import org.jetbrains.jewel.foundation.util.inDebugMode

/** Provides the default [PainterHint]s to use to load images. */
public class StandalonePainterHintsProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import org.jetbrains.jewel.ui.component.ToggleableChip
import org.jetbrains.jewel.ui.theme.colorPalette

@Composable
@View(title = "ChipsAndTree", position = 11)
@View(title = "ChipsAndTree", position = 11, icon = "icons/showAsTree.svg")
fun ChipsAndTree() {
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(16.dp)) {
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Expand Down
6 changes: 6 additions & 0 deletions samples/standalone/src/main/resources/icons/showAsTree.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions ui/api/ui.api
Original file line number Diff line number Diff line change
Expand Up @@ -2378,10 +2378,6 @@ public final class org/jetbrains/jewel/ui/util/ColorExtensionsKt {
public static final fun toRgbaHexString-8_81llA (J)Ljava/lang/String;
}

public final class org/jetbrains/jewel/ui/util/DebugKt {
public static final fun getInDebugMode ()Z
}

public final class org/jetbrains/jewel/ui/util/ModifierExtensionsKt {
public static final fun thenIf (Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function1;)Landroidx/compose/ui/Modifier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.ui.res.loadImageBitmap
import androidx.compose.ui.res.loadSvgPainter
import androidx.compose.ui.res.loadXmlImageVector
import androidx.compose.ui.unit.Density
import org.jetbrains.jewel.ui.util.inDebugMode
import org.jetbrains.jewel.foundation.util.inDebugMode
import org.w3c.dom.Document
import org.xml.sax.InputSource
import java.io.IOException
Expand Down Expand Up @@ -166,7 +166,7 @@ public class ResourcePainterProvider(
loadSvgPainter(inputStream, scope)
}
},
rememberAction = { remember(url, scope.density) { it } },
paintAction = { it },
)

private fun patchSvg(
Expand Down Expand Up @@ -205,7 +205,7 @@ public class ResourcePainterProvider(
loadingAction = { resourceUrl ->
resourceUrl.openStream().use { loadXmlImageVector(InputSource(it), scope) }
},
rememberAction = { rememberVectorPainter(it) },
paintAction = { rememberVectorPainter(it) },
)

@Composable
Expand All @@ -218,14 +218,14 @@ public class ResourcePainterProvider(
val bitmap = resourceUrl.openStream().use { loadImageBitmap(it) }
BitmapPainter(bitmap)
},
rememberAction = { remember(url, scope.density) { it } },
paintAction = { it },
)

@Composable
private fun <T> tryLoadingResource(
url: URL,
loadingAction: (URL) -> T,
rememberAction: @Composable (T) -> Painter,
paintAction: @Composable (T) -> Painter,
): Painter {
@Suppress("TooGenericExceptionCaught") // This is a last-resort fallback when icons fail to load
val painter =
Expand All @@ -241,7 +241,7 @@ public class ResourcePainterProvider(
return errorPainter
}

return rememberAction(painter)
return paintAction(painter)
}

private class Scope(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ private class StrokeImpl(private val color: Color) : PainterSuffixHint(), Painte
Color(0xFFF28C35),
Color(0xFF955AE0),
)

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is StrokeImpl) return false

if (color != other.color) return false

return true
}

override fun toString(): String = "Stroke(color=$color)"

override fun hashCode(): Int = color.hashCode()
}

/**
Expand Down

0 comments on commit 0e039d8

Please sign in to comment.