Skip to content

Commit 7732532

Browse files
authored
Fix: ANR in the Tab switcher (#6872)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1207418217763355/task/1211510795041274?focus=true ### Description An attempt to fix an ANR when layout out the tab switcher items. Since the stack trace pointed to a delay when calculating breakpoints, I've added a couple of optimizations to how we process and display the title in the item's TextView: - updated the title's `layout_width` attribute to fill the item's width - changed the `breakStrategy` to simple - added a limit to the title length (could be using long URLs if no title available) ### Steps to test this PR It's not easy to reproduce, so just smoke-check that items are displayed properly. Otherwise QA-optional.
1 parent 957d8a1 commit 7732532

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

app/src/main/java/com/duckduckgo/app/tabs/ui/TabRendererExtension.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.duckduckgo.app.tabs.ui
1818

1919
import android.content.Context
20-
import android.net.Uri
20+
import androidx.core.net.toUri
2121
import com.duckduckgo.app.browser.R
2222
import com.duckduckgo.app.tabs.model.TabEntity
2323
import com.duckduckgo.app.tabs.model.isBlank
@@ -28,7 +28,7 @@ fun TabEntity.displayTitle(context: Context): String {
2828
return context.getString(R.string.newTabMenuItem)
2929
}
3030

31-
return title ?: Uri.parse(resolvedUrl()).host ?: ""
31+
return title ?: resolvedUrl().toUri().host?.take(TabSwitcherAdapter.TabSwitcherViewHolder.MAX_TITLE_LENGTH) ?: ""
3232
}
3333

3434
private fun TabEntity.resolvedUrl(): String {

app/src/main/java/com/duckduckgo/app/tabs/ui/TabSwitcherAdapter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ class TabSwitcherAdapter(
469469
const val TRACKER_ANIMATION_TILE_INFO_PANEL = 2
470470

471471
const val EXTRA_CLOSE_BUTTON_TOUCH_AREA = 6 // dp
472+
473+
const val MAX_TITLE_LENGTH = 50
472474
}
473475

474476
interface TabViewHolder {

app/src/main/res/layout/item_tab_grid.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
android:id="@+id/tabUnread"
4545
android:layout_width="9dp"
4646
android:layout_height="9dp"
47-
android:elevation="30dp"
4847
android:importantForAccessibility="no"
4948
android:src="@drawable/tab_unread_indicator"
5049
app:layout_constraintCircle="@id/favicon"
@@ -78,14 +77,15 @@
7877

7978
<com.duckduckgo.common.ui.view.text.DaxTextView
8079
android:id="@+id/title"
81-
android:layout_width="wrap_content"
80+
android:layout_width="0dp"
8281
android:layout_height="wrap_content"
8382
android:ellipsize="end"
8483
android:lines="1"
8584
android:maxLines="1"
8685
android:textIsSelectable="false"
8786
android:layout_marginStart="@dimen/keyline_2"
8887
android:layout_marginEnd="6dp"
88+
android:breakStrategy="simple"
8989
app:layout_constrainedWidth="true"
9090
app:layout_constraintEnd_toStartOf="@+id/selectionIndicator"
9191
app:layout_constraintStart_toEndOf="@id/favicon"

app/src/main/res/layout/item_tab_list.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
android:layout_height="9dp"
4949
android:layout_marginEnd="2dp"
5050
android:layout_marginBottom="2dp"
51-
android:elevation="30dp"
5251
android:importantForAccessibility="no"
5352
android:src="@drawable/tab_unread_indicator"
5453
app:layout_constraintCircle="@id/favicon"
@@ -91,6 +90,7 @@
9190
android:ellipsize="end"
9291
android:lines="1"
9392
android:textIsSelectable="false"
93+
android:breakStrategy="simple"
9494
app:layout_constraintEnd_toStartOf="@id/selectionIndicator"
9595
app:layout_constraintStart_toEndOf="@id/favicon"
9696
app:layout_constraintTop_toTopOf="parent"

0 commit comments

Comments
 (0)