-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented Material3 SearchBar feature in FoodExpirationDates App #284
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||||
package com.lorenzovainigli.foodexpirationdates.view.composable | ||||||||
|
||||||||
import android.annotation.SuppressLint | ||||||||
import android.os.Build | ||||||||
import android.util.Log | ||||||||
import androidx.annotation.RequiresApi | ||||||||
|
@@ -8,16 +9,20 @@ import androidx.compose.foundation.layout.fillMaxSize | |||||||
import androidx.compose.foundation.layout.padding | ||||||||
import androidx.compose.material.icons.Icons | ||||||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||||||||
import androidx.compose.material.icons.automirrored.filled.Chat | ||||||||
import androidx.compose.material3.ExperimentalMaterial3Api | ||||||||
import androidx.compose.material3.Icon | ||||||||
import androidx.compose.material3.IconButton | ||||||||
import androidx.compose.material3.MaterialTheme | ||||||||
import androidx.compose.material3.OutlinedTextField | ||||||||
import androidx.compose.material3.Scaffold | ||||||||
import androidx.compose.material3.SnackbarDuration | ||||||||
import androidx.compose.material3.SnackbarHost | ||||||||
import androidx.compose.material3.SnackbarHostState | ||||||||
import androidx.compose.material3.SnackbarResult | ||||||||
import androidx.compose.material3.Surface | ||||||||
import androidx.compose.material3.Text | ||||||||
import androidx.compose.material3.TextField | ||||||||
import androidx.compose.material3.TopAppBarDefaults | ||||||||
import androidx.compose.runtime.Composable | ||||||||
import androidx.compose.runtime.MutableState | ||||||||
|
@@ -57,13 +62,15 @@ fun MyScaffold( | |||||||
navController: NavHostController, | ||||||||
navDestination: String? = null, | ||||||||
showSnackbar: MutableState<Boolean>, | ||||||||
content: @Composable () -> Unit | ||||||||
searchQuery : MutableState<String>, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whenever possible, if you introduce a new parameter, add a default. This prevent you from having to change all calls of the function. Think about the situation in which a function is called 100 times.
Suggested change
|
||||||||
content: @Composable () -> Unit, | ||||||||
) { | ||||||||
val snackbarHostState = remember { SnackbarHostState() } | ||||||||
val coroutineScope = rememberCoroutineScope() | ||||||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior() | ||||||||
val currentBackStackEntry by navController.currentBackStackEntryAsState() | ||||||||
val context = LocalContext.current | ||||||||
|
||||||||
if (showSnackbar.value){ | ||||||||
coroutineScope.launch { | ||||||||
try { | ||||||||
|
@@ -118,7 +125,7 @@ fun MyScaffold( | |||||||
}, | ||||||||
actions = { | ||||||||
if (destination?.contains(Screen.MainScreen.route) == true) { | ||||||||
MainScreenMenu(activity) | ||||||||
MainScreenMenu(activity, searchQuery) | ||||||||
} | ||||||||
}, | ||||||||
navigationIcon = { | ||||||||
|
@@ -154,6 +161,7 @@ fun MyScaffold( | |||||||
} | ||||||||
} | ||||||||
|
||||||||
@SuppressLint("UnrememberedMutableState") | ||||||||
@RequiresApi(Build.VERSION_CODES.O) | ||||||||
@PreviewLightDark | ||||||||
@PreviewScreenSizes | ||||||||
|
@@ -167,10 +175,13 @@ fun MyScaffoldPreview() { | |||||||
} | ||||||||
MyScaffold( | ||||||||
navController = navController, | ||||||||
showSnackbar = showSnackbar | ||||||||
showSnackbar = showSnackbar, | ||||||||
searchQuery = mutableStateOf("") | ||||||||
Comment on lines
+178
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change no longer necessary after introducing a default.
Suggested change
|
||||||||
) { | ||||||||
|
||||||||
MainScreen( | ||||||||
navController = rememberNavController() | ||||||||
navController = rememberNavController(), | ||||||||
searchQuery = mutableStateOf("") | ||||||||
Comment on lines
+183
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change no longer necessary after introducing a default.
Suggested change
|
||||||||
) | ||||||||
} | ||||||||
} | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ import androidx.compose.ui.tooling.preview.Preview | |
import androidx.compose.ui.tooling.preview.PreviewLightDark | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.lorenzovainigli.foodexpirationdates.BuildConfig | ||
import com.google.android.datatransport.BuildConfig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong, please revert this. |
||
import com.lorenzovainigli.foodexpirationdates.DEVELOPER_EMAIL | ||
import com.lorenzovainigli.foodexpirationdates.GITHUB_URL | ||
import com.lorenzovainigli.foodexpirationdates.PLAY_STORE_URL | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to introduce commented code.