Skip to content

Commit efff606

Browse files
committed
Bug 1990283 - Migrate TopAppBar to Material 3 in BaseComposeFragment r=android-reviewers,avirvara
This commit refactors the `TopAppBar` in `BaseComposeFragment.kt` to use the Material 3 version. Differential Revision: https://phabricator.services.mozilla.com/D265952
1 parent 9ba5960 commit efff606

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

mobile/android/focus-android/app/lint-baseline.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,6 @@
133133
column="20"/>
134134
</issue>
135135

136-
<issue
137-
id="UsingMaterialAndMaterial3Libraries"
138-
message="Using a material import while also using the material3 library"
139-
errorLine1="import androidx.compose.material.TopAppBar"
140-
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
141-
<location
142-
file="src/main/java/org/mozilla/focus/settings/BaseComposeFragment.kt"
143-
line="17"
144-
column="8"/>
145-
</issue>
146-
147136
<issue
148137
id="DataExtractionRules"
149138
message="The attribute `android:allowBackup` is deprecated from Android 12 and higher and may be removed in future versions. Consider adding the attribute `android:dataExtractionRules` specifying an `@xml` resource which configures cloud backups and device transfers on Android 12 and higher."

mobile/android/focus-android/app/src/main/java/org/mozilla/focus/settings/BaseComposeFragment.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ import androidx.compose.foundation.background
1414
import androidx.compose.foundation.layout.Column
1515
import androidx.compose.foundation.layout.padding
1616
import androidx.compose.foundation.layout.systemBarsPadding
17-
import androidx.compose.material.TopAppBar
17+
import androidx.compose.material3.ExperimentalMaterial3Api
1818
import androidx.compose.material3.Icon
1919
import androidx.compose.material3.IconButton
2020
import androidx.compose.material3.Scaffold
2121
import androidx.compose.material3.Text
22+
import androidx.compose.material3.TopAppBar
23+
import androidx.compose.material3.TopAppBarDefaults
2224
import androidx.compose.runtime.Composable
2325
import androidx.compose.ui.Modifier
2426
import androidx.compose.ui.platform.ComposeView
2527
import androidx.compose.ui.platform.ViewCompositionStrategy
2628
import androidx.compose.ui.res.colorResource
2729
import androidx.compose.ui.res.painterResource
2830
import androidx.compose.ui.res.stringResource
29-
import androidx.compose.ui.unit.dp
3031
import androidx.core.content.ContextCompat
3132
import androidx.fragment.app.Fragment
3233
import org.mozilla.focus.R
@@ -102,7 +103,7 @@ abstract class BaseComposeFragment : Fragment() {
102103
.background(colorResource(id = backgroundColorResource))
103104
.padding(paddingValues),
104105
) {
105-
TopAppBar(
106+
FocusTopAppBar(
106107
title = title,
107108
modifier = Modifier,
108109
onNavigateUpClick = onNavigateUp(),
@@ -122,8 +123,9 @@ abstract class BaseComposeFragment : Fragment() {
122123
}
123124
}
124125

126+
@OptIn(ExperimentalMaterial3Api::class)
125127
@Composable
126-
private fun TopAppBar(
128+
private fun FocusTopAppBar(
127129
title: String,
128130
modifier: Modifier = Modifier,
129131
onNavigateUpClick: () -> Unit,
@@ -132,7 +134,6 @@ private fun TopAppBar(
132134
title = {
133135
Text(
134136
text = title,
135-
color = focusColors.toolbarColor,
136137
)
137138
},
138139
modifier = modifier,
@@ -143,11 +144,14 @@ private fun TopAppBar(
143144
Icon(
144145
painterResource(id = iconsR.drawable.mozac_ic_back_24),
145146
stringResource(R.string.go_back),
146-
tint = focusColors.toolbarColor,
147147
)
148148
}
149149
},
150-
backgroundColor = colorResource(R.color.settings_background),
151-
elevation = 0.dp,
150+
colors = TopAppBarDefaults.topAppBarColors(
151+
containerColor = colorResource(R.color.settings_background),
152+
scrolledContainerColor = colorResource(R.color.settings_background),
153+
navigationIconContentColor = focusColors.toolbarColor,
154+
titleContentColor = focusColors.toolbarColor,
155+
),
152156
)
153157
}

0 commit comments

Comments
 (0)