This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1875465 - Part 3: Add tab strip ui for tablets
- Loading branch information
1 parent
02e7419
commit 7556e1a
Showing
6 changed files
with
548 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
fenix/app/src/main/java/org/mozilla/fenix/browser/tabstrip/TabStripCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.browser.tabstrip | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Card | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import org.mozilla.fenix.compose.annotation.LightDarkPreview | ||
import org.mozilla.fenix.theme.FirefoxTheme | ||
|
||
private val cardShape = RoundedCornerShape(8.dp) | ||
internal val defaultTabStripCardElevation = 0.dp | ||
internal val selectedTabStripCardElevation = 1.dp | ||
|
||
/** | ||
* Card composable used in Tab Strip items. | ||
* | ||
* @param modifier The modifier to be applied to the card. | ||
* @param backgroundColor The background color of the card. | ||
* @param elevation The elevation of the card. | ||
* @param content The content of the card. | ||
*/ | ||
@Composable | ||
fun TabStripCard( | ||
modifier: Modifier = Modifier, | ||
backgroundColor: Color = FirefoxTheme.colors.layer3, | ||
elevation: Dp = defaultTabStripCardElevation, | ||
content: @Composable () -> Unit, | ||
) { | ||
Card( | ||
shape = cardShape, | ||
backgroundColor = backgroundColor, | ||
elevation = elevation, | ||
modifier = modifier, | ||
content = content, | ||
) | ||
} | ||
|
||
@LightDarkPreview | ||
@Composable | ||
private fun TabStripCardPreview() { | ||
FirefoxTheme { | ||
TabStripCard { | ||
Box( | ||
modifier = Modifier | ||
.height(56.dp) | ||
.width(200.dp) | ||
.padding(8.dp), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
Text( | ||
text = "Tab Strip Card", | ||
color = FirefoxTheme.colors.textPrimary, | ||
style = FirefoxTheme.typography.subtitle1, | ||
) | ||
} | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
fenix/app/src/main/java/org/mozilla/fenix/browser/tabstrip/TabStripState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.browser.tabstrip | ||
|
||
import android.graphics.Bitmap | ||
import mozilla.components.browser.state.state.BrowserState | ||
|
||
/** | ||
* The ui state of the tabs strip. | ||
* | ||
* @property tabs The list of [TabUIState]. | ||
*/ | ||
data class TabsStripState( | ||
val tabs: List<TabUIState>, | ||
) { | ||
companion object { | ||
val initial = TabsStripState(tabs = emptyList()) | ||
} | ||
} | ||
|
||
/** | ||
* The ui state of a tab. | ||
* | ||
* @property id The id of the tab. | ||
* @property title The title of the tab. | ||
* @property icon The icon of the tab. | ||
* @property isPrivate Whether or not the tab is private. | ||
* @property isSelected Whether or not the tab is selected. | ||
*/ | ||
data class TabUIState( | ||
val id: String, | ||
val title: String, | ||
val icon: Bitmap? = null, | ||
val isPrivate: Boolean, | ||
val isSelected: Boolean, | ||
) | ||
|
||
/** | ||
* Converts [BrowserState] to [TabsStripState] that contains the information needed to render the | ||
* tabs strip. | ||
*/ | ||
internal fun BrowserState.toTabsStripState( | ||
onHome: Boolean, | ||
isPrivateMode: Boolean, | ||
): TabsStripState { | ||
return TabsStripState( | ||
tabs = tabs | ||
.filter { | ||
if (isPrivateMode) { | ||
it.content.private | ||
} else { | ||
!it.content.private | ||
} | ||
} | ||
.map { | ||
TabUIState( | ||
id = it.id, | ||
title = it.content.title, | ||
icon = it.content.icon, | ||
isPrivate = it.content.private, | ||
isSelected = !onHome && it.id == selectedTabId, | ||
) | ||
}, | ||
) | ||
} |
Oops, something went wrong.