Skip to content

Commit 7a13d6c

Browse files
authored
Merge pull request #983 from wordpress-mobile/avoid_creating_unnecessary_video_image_drawables
Avoid creating loading drawables when there are no images/videos to load
2 parents 4dedbd5 + 505df61 commit 7a13d6c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,13 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
13701370

13711371
private fun loadImages() {
13721372
val spans = this.text.getSpans(0, text.length, AztecImageSpan::class.java)
1373+
1374+
// Avoid the work of getting placeholder drawable if there are no images. This becomes a big
1375+
// on screens that have many AztecText views
1376+
if (spans.isEmpty()) {
1377+
return
1378+
}
1379+
13731380
val loadingDrawable = getPlaceholderDrawableFromResID(context, drawableLoading, maxImagesWidth)
13741381

13751382
// Make sure to keep a reference to the maxWidth, otherwise in the Callbacks there is
@@ -1404,6 +1411,13 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
14041411

14051412
private fun loadVideos() {
14061413
val spans = this.text.getSpans(0, text.length, AztecVideoSpan::class.java)
1414+
1415+
// Avoid the work of getting placeholder drawable if there are no videos. This becomes a big
1416+
// on screens that have many AztecText views
1417+
if (spans.isEmpty()) {
1418+
return
1419+
}
1420+
14071421
val loadingDrawable = getPlaceholderDrawableFromResID(context, drawableLoading, maxImagesWidth)
14081422
val videoListenerRef = this.onVideoInfoRequestedListener
14091423

0 commit comments

Comments
 (0)