Skip to content

Commit df09b6d

Browse files
committed
Bug 1976700 - Add support to hide navigation bar when keyboard is shown. r=android-reviewers,petru
Differential Revision: https://phabricator.services.mozilla.com/D257843
1 parent 2f2fada commit df09b6d

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,7 @@ abstract class BaseBrowserFragment :
13211321
browserStore = store,
13221322
components = activity.components,
13231323
settings = activity.settings(),
1324+
hideWhenKeyboardShown = true,
13241325
customTabSession = customTabSessionId?.let { store.state.findCustomTab(it) },
13251326
)
13261327

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserNavigationBar.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import org.mozilla.fenix.browser.store.BrowserScreenStore
2626
import org.mozilla.fenix.components.AppStore
2727
import org.mozilla.fenix.components.Components
2828
import org.mozilla.fenix.components.StoreProvider
29+
import org.mozilla.fenix.compose.utils.KeyboardState
30+
import org.mozilla.fenix.compose.utils.keyboardAsState
2931
import org.mozilla.fenix.theme.FirefoxTheme
3032
import org.mozilla.fenix.utils.Settings
3133

@@ -41,6 +43,7 @@ import org.mozilla.fenix.utils.Settings
4143
* @param browserStore [BrowserStore] used for observing the browsing details.
4244
* @param components [Components] allowing interactions with other application features.
4345
* @param settings [Settings] object to get the toolbar position and other settings.
46+
* @param hideWhenKeyboardShown If true, navigation bar will be hidden when the keyboard is visible.
4447
* @param customTabSession [CustomTabSessionState] if the toolbar is shown in a custom tab.
4548
*/
4649
@Suppress("LongParameterList")
@@ -53,6 +56,7 @@ class BrowserNavigationBar(
5356
private val browserStore: BrowserStore,
5457
private val components: Components,
5558
private val settings: Settings,
59+
private val hideWhenKeyboardShown: Boolean,
5660
customTabSession: CustomTabSessionState? = null,
5761
) : FenixBrowserToolbarView(
5862
context = context,
@@ -132,8 +136,14 @@ class BrowserNavigationBar(
132136
@Composable
133137
private fun DefaultNavigationBarContent(showDivider: Boolean) {
134138
val uiState by store.observeAsState(initialValue = store.state) { it }
139+
val isKeyboardVisible = if (hideWhenKeyboardShown) {
140+
val keyboardState by keyboardAsState()
141+
keyboardState == KeyboardState.Opened
142+
} else {
143+
false
144+
}
135145

136-
if (uiState.displayState.navigationActions.isNotEmpty()) {
146+
if (uiState.displayState.navigationActions.isNotEmpty() && !isKeyboardVisible) {
137147
FirefoxTheme {
138148
NavigationBar(
139149
actions = uiState.displayState.navigationActions,

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ class HomeFragment : Fragment() {
315315
container = binding.navigationBarContainer,
316316
appStore = components.appStore,
317317
browserStore = store,
318+
hideWhenKeyboardShown = true,
318319
)
319320

320321
if (requireContext().settings().isExperimentationEnabled) {

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/toolbar/HomeNavigationBar.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import mozilla.components.compose.browser.toolbar.store.BrowserToolbarStore
2222
import mozilla.components.lib.state.ext.observeAsState
2323
import org.mozilla.fenix.components.AppStore
2424
import org.mozilla.fenix.components.StoreProvider
25+
import org.mozilla.fenix.compose.utils.KeyboardState
26+
import org.mozilla.fenix.compose.utils.keyboardAsState
2527
import org.mozilla.fenix.ext.components
2628
import org.mozilla.fenix.theme.FirefoxTheme
2729

@@ -34,13 +36,15 @@ import org.mozilla.fenix.theme.FirefoxTheme
3436
* @param container [ViewGroup] which will serve as parent of this View.
3537
* @param appStore [AppStore] to sync from.
3638
* @param browserStore [BrowserStore] used for observing the browsing details.
39+
* @param hideWhenKeyboardShown If true, navigation bar will be hidden when the keyboard is visible.
3740
*/
3841
class HomeNavigationBar(
3942
private val context: Context,
4043
private val lifecycleOwner: Fragment,
4144
private val container: ViewGroup,
4245
private val appStore: AppStore,
4346
private val browserStore: BrowserStore,
47+
private val hideWhenKeyboardShown: Boolean,
4448
) : FenixHomeToolbar {
4549
val store = StoreProvider.get(lifecycleOwner) {
4650
BrowserToolbarStore(
@@ -59,8 +63,14 @@ class HomeNavigationBar(
5963
@Composable
6064
private fun DefaultNavigationBarContent(showDivider: Boolean) {
6165
val uiState by store.observeAsState(initialValue = store.state) { it }
66+
val isKeyboardVisible = if (hideWhenKeyboardShown) {
67+
val keyboardState by keyboardAsState()
68+
keyboardState == KeyboardState.Opened
69+
} else {
70+
false
71+
}
6272

63-
if (uiState.displayState.navigationActions.isNotEmpty()) {
73+
if (uiState.displayState.navigationActions.isNotEmpty() && !isKeyboardVisible) {
6474
FirefoxTheme {
6575
NavigationBar(
6676
actions = uiState.displayState.navigationActions,

0 commit comments

Comments
 (0)