Skip to content

Commit 69a5489

Browse files
authored
fix an issue where nav bar would stay visible together with the keyboard when NTP was opened (#6086)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1208671518894266/task/1210267290350843?focus=true ### Description When opening the new tab page, we initial don't show the keyboard. This scheduled a delayed task to execute and show the navigation bar. Before the time elapses to run the task, we automatically show the keyboard and focus on the omnibar, which hides the nav bar. However, the initially scheduled task would eventually execute and re-show the navigation bar even though the keyboard was also already visible. The fix is to cancel the delayed task to show the navigation bar whenever the keyboard state changes. ### Steps to test this PR - [ ] Enable visual design experiment. - [ ] Go to any page. - [ ] Open a new tab page. - [ ] Verify keyboard is visible and navigation bar isn't. - [ ] Close the app and reopen it. - [ ] Verify that when NTP loads, keyboard is visible and navigation bar isn't. - [ ] Try it multiple times.
1 parent 1369050 commit 69a5489

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

app/src/main/java/com/duckduckgo/app/browser/navigation/bar/BrowserNavigationBarViewIntegration.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.duckduckgo.common.ui.view.show
2929
import com.duckduckgo.common.utils.keyboardVisibilityFlow
3030
import kotlinx.coroutines.CoroutineScope
3131
import kotlinx.coroutines.Job
32+
import kotlinx.coroutines.delay
3233
import kotlinx.coroutines.flow.distinctUntilChanged
3334
import kotlinx.coroutines.launch
3435

@@ -53,7 +54,8 @@ class BrowserNavigationBarViewIntegration(
5354
} ?: browserTabFragmentBinding.navigationBar
5455

5556
private var stateObserverJob: Job? = null
56-
private var keyboardVisibilityJob: Job? = null
57+
private var keyboardVisibilityObserverJob: Job? = null
58+
private var navigationBarVisibilityChangeJob: Job? = null
5759

5860
init {
5961
stateObserverJob = lifecycleScope.launch {
@@ -92,21 +94,22 @@ class BrowserNavigationBarViewIntegration(
9294
private fun onEnabled() {
9395
// we're hiding the navigation bar when keyboard is shown,
9496
// to prevent it from being "pushed up" within the coordinator layout
95-
keyboardVisibilityJob = lifecycleScope.launch {
97+
keyboardVisibilityObserverJob = lifecycleScope.launch {
9698
omnibar.textInputRootView.keyboardVisibilityFlow().distinctUntilChanged().collect { keyboardVisible ->
99+
navigationBarVisibilityChangeJob?.cancel()
97100
if (keyboardVisible) {
98101
navigationBarView.gone()
99102
} else {
100-
navigationBarView.postDelayed(
101-
{ navigationBarView.show() },
102-
BrowserTabFragment.KEYBOARD_DELAY,
103-
)
103+
navigationBarVisibilityChangeJob = launch {
104+
delay(BrowserTabFragment.KEYBOARD_DELAY)
105+
navigationBarView.show()
106+
}
104107
}
105108
}
106109
}
107110
}
108111

109112
private fun onDisabled() {
110-
keyboardVisibilityJob?.cancel()
113+
keyboardVisibilityObserverJob?.cancel()
111114
}
112115
}

0 commit comments

Comments
 (0)