-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix remembers painter twice and break the cache #303
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -166,7 +166,7 @@ public class ResourcePainterProvider( | |
loadSvgPainter(inputStream, scope) | ||
} | ||
}, | ||
rememberAction = { remember(url, scope.density) { it } }, | ||
paintAction = { it }, | ||
) | ||
|
||
private fun patchSvg( | ||
|
@@ -205,7 +205,7 @@ public class ResourcePainterProvider( | |
loadingAction = { resourceUrl -> | ||
resourceUrl.openStream().use { loadXmlImageVector(InputSource(it), scope) } | ||
}, | ||
rememberAction = { rememberVectorPainter(it) }, | ||
paintAction = { rememberVectorPainter(it) }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can still remember the vector because vector self is a key. |
||
) | ||
|
||
@Composable | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I rename the rememberAction to paintAction, it more seems like a action to convert T to a painter |
||
): Painter { | ||
@Suppress("TooGenericExceptionCaught") // This is a last-resort fallback when icons fail to load | ||
val painter = | ||
|
@@ -241,7 +241,7 @@ public class ResourcePainterProvider( | |
return errorPainter | ||
} | ||
|
||
return rememberAction(painter) | ||
return paintAction(painter) | ||
} | ||
|
||
private class Scope( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not remember painter here, because we have already the cache here.
Before:
After:
It only happened with first default selected icon button