-
-
Notifications
You must be signed in to change notification settings - Fork 321
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
Async drawable doesn't show up if it's the only thing in the text view #189
Comments
Hello @Adonai ! Can you please try the same markdown input with Also, I could not reproduce it. So, let's try to pin point the issue:
As for javadoc... well, AsyncDrawableSpan will set height if it has loaded result. If has none, then height won't be set (and thus |
I'll try to craft minimal reproducible example of this, thanks for quick response! |
Here it is val renderer = Markwon.builder(ctx)
.usePlugin(GlideImagesPlugin.create(ctx))
.build() then val md = renderer.toMarkdown("![7QOIF2X.jpg](https://i.imgur.com/7QOIF2X.jpg)")
messageBody.text = md
AsyncDrawableScheduler.schedule(messageBody)
Note 1: First time it works ok. The second, when images are cached by Glide, it breaks. Note 2: If paired with any text on the other line, it works again: val md = renderer.toMarkdown("No issue!\n\n![7QOIF2X.jpg](https://i.imgur.com/7QOIF2X.jpg)")
messageBody.text = md
AsyncDrawableScheduler.schedule(messageBody) |
I think this may be the culprit: b55b1f0 |
Hello @Adonai ! It might be the culprit but did you test with the previous version? 😄 I did reproduce your report but with a single change it can be fixed: messageBody.setText(md, TextView.BufferType.SPANNABLE); But I recommend to use the: markwon.setMarkdown(messageBody, markdown); which takes care of not only that, but also other things (like measuring ordered lists width, etc) |
@noties both changes didn't work for me. Still empty message.
No, I haven't... not sure it's possible to select specific version with |
Weird, it works for me, I will take a closer look.
I think it is as simple as changing the library version in your dependencies block: implementation 'io.noties.markwon:core:4.2.0' // or any other version, really Checking against latest released version would suffice here, can you try it? |
Hi! I'll be out of town for some time, will surely check once I return. Thanks! |
Hello ! I am seeing what looks like the same issue. For me, downgrading to I'd be happy to help if there is anything I can do/test. |
Hello @LaurentTreguier ! On what API level(s) do you see this behavior? |
This is on API 29, on the emulator |
@LaurentTreguier I still cannot reproduce this issue even on API 29 emulator. Can you please share your |
I'll put this here to make sure it's not lost in the middle of the code: Here is the function I use to setup The Markwon instance: fun Fragment.lazyMarkdown() = lazy {
requireActivity().let {
Markwon.builder(it)
.usePlugin(CorePlugin.create())
.usePlugin(MovementMethodPlugin.create())
.usePlugin(PostPlugin.create())
.usePlugin(StrikethroughPlugin.create())
.usePlugin(ImagesPlugin.create())
.usePlugin(GlideImagesPlugin.create(PostGlideStore(it)))
.build()
}
} Here is the class PostPlugin private constructor() : AbstractMarkwonPlugin() {
override fun configureVisitor(builder: MarkwonVisitor.Builder) {
builder.on(SoftLineBreak::class.java) { visitor, _ -> visitor.forceNewLine() }
builder.on(Text::class.java) { visitor, text ->
visitor.builder().append(
SpannableString(text.literal).apply {
LinkifyCompat.addLinks(this, Linkify.WEB_URLS)
}
)
visitor.visitChildren(text)
}
}
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
builder.imageSizeResolver(object : ImageSizeResolver() {
override fun resolveImageSize(drawable: AsyncDrawable): Rect {
val canvasWidth = drawable.lastKnownCanvasWidth
val factor = canvasWidth.toFloat() / drawable.intrinsicWidth
return Rect(0, 0, canvasWidth, (drawable.intrinsicHeight * factor).toInt())
}
})
}
companion object {
fun create() = PostPlugin()
}
} And here is the class PostGlideStore(private val context: Context) : GlideImagesPlugin.GlideStore {
override fun load(drawable: AsyncDrawable) = AppGlide.with(context)
.load(drawable.destination)
.placeholder( // removing this placeholder fixes the issue
VectorDrawableCompat.create(
context.resources,
R.drawable.ic_image,
context.theme
)
)
override fun cancel(target: Target<*>) = AppGlide.with(context).clear(target)
} Here is a raw markdown string with which that I have seen the issue, using # Gorillaz - El Mañana
[![undefined](https://img.youtube.com/vi/gs1I8_m4AOM/0.jpg)](https://www.youtube.com/watch?v=gs1I8_m4AOM)
[Verse 1]
Summer don't know me no more
He got mad, that's all
Summer don't know me
He'd just let me low in myself
'Cause I do know love
From you then, just dying
[Hook]
I saw that day
Lost my mind
Lord, I'm fine
Maybe in time, you'll want to be mine
[Verse 2]
Don't stop the bud, when it comes
It's the dawn, you'll see
Money won't get there
Ten years passed tonight, you'll flee
If you do that
I'll be sworn
To find you
[Hook]
I saw that day
Lost my mind
Lord, I'm fine
Maybe in time, you'll want to be mine
[Bridge]
I saw that day
Lost my mind
Lord, I'm fine
Maybe in time, you'll want to be mine
[Outro]
(I saw that day)
(Lost my mind)
(Lord, I’m fine)
Maybe in time, you'll want to be mine
Maybe in time, you'll want to be mine
Maybe in time, you'll want to be mine
Maybe in time, you'll want to be mine |
Hello @LaurentTreguier ! Thank you for the info, it was most valuable! I did manage to reproduce the issue and the fix is already in the So, the problem here might indeed be the commit that @Adonai mentioned before. In the commit I tried to reduce the number of invalidations that AyncDrawable goes through. For this to properly to function So, when you have a To have a workaround in current Currently placeholder bounds has few rules:
Hope this resolves this issue and clears a bit how placeholders are displayed |
Hello, I'm back. Will test this in the following days and close the issue. Thanks for your thorough investigation! |
Let me know if issue persists |
I don't know if @Adonai has had time to test the 4.2.2 version, but on my end, it looks like the issue is still here. |
I can reproduce it, the fix is going to be in the next |
Good news, from my testing today, it looks like this issue is fixed for me; thanks @noties ! |
Async drawable doesn't show up if it's the only thing in the text view.
In the source code of the
ReplacementSpan
there's this suspicious javadocAnd
AsyncDrawable.initWithKnownDimensions(...)
is only called ifAsyncDrawableSpan.draw(...)
of the parent span was called.The text was updated successfully, but these errors were encountered: