Skip to content

Commit 328e289

Browse files
malmsteinanikiki
authored andcommitted
Delay adding FocusedView until it's necessary (#4772)
Task/Issue URL: https://app.asana.com/0/1157893581871903/1207816154536989/f ### Description Delay the addition of the FocusedView until it’s necessary ### Steps to test this PR _Enable FocusedView_ - [x] Fresh install, add some favourites - [x] Visit a site so it’s setup for the next time the app opens - [x] Force close and open it up again - [x] Tap on the omnibar - [x] Verify that FocusedView is visible - [x] Open New Tab - [x] Visit a site - [x] Tap on the omnibar - [x] Verify FocusedView is visible
1 parent 01a5ade commit 328e289

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ class BrowserTabFragment :
830830
configureOmnibarTextInput()
831831
configureFindInPage()
832832
configureAutoComplete()
833-
configureFocusedView()
834833
configureNewTab()
835834
initPrivacyProtectionsPopup()
836835

@@ -2128,18 +2127,6 @@ class BrowserTabFragment :
21282127
binding.autoCompleteSuggestionsList.adapter = autoCompleteSuggestionsAdapter
21292128
}
21302129

2131-
private fun configureFocusedView() {
2132-
focusedViewProvider.provideFocusedViewVersion().onEach { focusedView ->
2133-
binding.focusedViewContainerLayout.addView(
2134-
focusedView.getView(requireContext()),
2135-
LayoutParams(
2136-
LayoutParams.MATCH_PARENT,
2137-
LayoutParams.MATCH_PARENT,
2138-
),
2139-
)
2140-
}.launchIn(lifecycleScope)
2141-
}
2142-
21432130
private fun configureNewTab() {
21442131
newBrowserTab.newTabLayout.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
21452132
if (omnibar.omniBarContainer.isPressed) {
@@ -3563,20 +3550,43 @@ class BrowserTabFragment :
35633550
// viewState.showFavourites needs to be moved to FocusedViewModel
35643551
if (viewState.showSuggestions || viewState.showFavorites) {
35653552
if (viewState.favorites.isNotEmpty() && viewState.showFavorites) {
3553+
showFocusedView()
35663554
binding.autoCompleteSuggestionsList.gone()
3567-
binding.focusedViewContainerLayout.show()
35683555
} else {
35693556
binding.autoCompleteSuggestionsList.show()
3570-
binding.focusedViewContainerLayout.gone()
35713557
autoCompleteSuggestionsAdapter.updateData(viewState.searchResults.query, viewState.searchResults.suggestions)
3558+
hideFocusedView()
35723559
}
35733560
} else {
35743561
binding.autoCompleteSuggestionsList.gone()
3575-
binding.focusedViewContainerLayout.gone()
3562+
hideFocusedView()
35763563
}
35773564
}
35783565
}
35793566

3567+
private fun showFocusedView() {
3568+
binding.focusedViewContainerLayout.show()
3569+
configureFocusedView()
3570+
}
3571+
3572+
private fun configureFocusedView() {
3573+
if (binding.focusedViewContainerLayout.childCount == 0) {
3574+
focusedViewProvider.provideFocusedViewVersion().onEach { focusedView ->
3575+
binding.focusedViewContainerLayout.addView(
3576+
focusedView.getView(requireContext()),
3577+
LayoutParams(
3578+
LayoutParams.MATCH_PARENT,
3579+
LayoutParams.MATCH_PARENT,
3580+
),
3581+
)
3582+
}.launchIn(lifecycleScope)
3583+
}
3584+
}
3585+
3586+
private fun hideFocusedView() {
3587+
binding.focusedViewContainerLayout.gone()
3588+
}
3589+
35803590
fun renderOmnibar(viewState: OmnibarViewState) {
35813591
renderIfChanged(viewState, lastSeenOmnibarViewState) {
35823592
lastSeenOmnibarViewState = viewState

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
android:id="@+id/focusedViewContainerLayout"
5252
android:clipToPadding="false"
5353
android:elevation="4dp"
54+
android:background="?attr/daxColorSurface"
5455
android:layout_width="match_parent"
5556
android:layout_height="match_parent"
5657
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

0 commit comments

Comments
 (0)