-
Notifications
You must be signed in to change notification settings - Fork 657
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
[connect] Use AndroidX Navigation in Example app #9767
Conversation
Risky Change This is considered a risky change because it adjusts the sample app build.gradle, please review carefully. By adding the label |
Diffuse output:
APK
|
|
||
private enum class SheetType { | ||
SETTINGS, | ||
APPEARANCE, | ||
} | ||
@Suppress("ConstPropertyName") | ||
private object MainDestination { | ||
const val ComponentPicker = "ComponentPicker" |
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.
👀 Ignoring lint and sticking with PascalCase so minimize thrash when we can use the type-safe DSL.
@AndroidEntryPoint | ||
class MainActivity : ComponentActivity() { | ||
|
||
private val viewModel: EmbeddedComponentLoaderViewModel by viewModels() |
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.
👀 removed in favor of hiltViewModel()
-- see below
* Safer [NavHostController.navigateUp] that prevents navigating past the previous screen, | ||
* typically due to accidental double-clicks. | ||
*/ | ||
fun NavHostController.safeNavigateUp() { |
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.
👀
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.
Nice extension!
@@ -38,7 +35,7 @@ fun AppearanceView( | |||
navigationIcon = { | |||
IconButton(onClick = onDismiss) { | |||
Icon( | |||
imageVector = Icons.AutoMirrored.Default.ArrowBack, | |||
imageVector = Icons.Default.Close, |
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.
👀 More standard to use X
for a modal
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.
Makes sense. In that case can we change SettingsView to match?
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.
Maybe, but SettingsView isn't a modal, which can/should be a back arrow
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.
Hmmm, I see what you're saying. I'm fine keeping it as-is then
@@ -20,14 +20,13 @@ fun BackIconButton(onClick: () -> Unit) { | |||
} | |||
|
|||
@Composable | |||
fun MoreIconButton( | |||
fun CustomizeAppearanceIconButton( |
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.
👀
@Suppress("LongMethod") | ||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
private fun ComponentPickerContent() { |
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.
👀 extracted to its own file
@@ -29,6 +29,7 @@ dependencies { | |||
implementation libs.androidx.browser | |||
implementation libs.androidx.fragment | |||
implementation libs.androidx.fragmentCompose | |||
implementation libs.androidx.hiltNavigationCompose |
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.
You'll need to run ./gradlew connectexample:apiDump
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.
Oops not that command the one you ran 🤦
ca5ff6f
to
79af50d
Compare
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.
Looks great! We should have the SettingsView match the AppearanceView though and also use an 'x' in place of a back arrow
* Safer [NavHostController.navigateUp] that prevents navigating past the previous screen, | ||
* typically due to accidental double-clicks. | ||
*/ | ||
fun NavHostController.safeNavigateUp() { |
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.
Nice extension!
@@ -38,7 +35,7 @@ fun AppearanceView( | |||
navigationIcon = { | |||
IconButton(onClick = onDismiss) { | |||
Icon( | |||
imageVector = Icons.AutoMirrored.Default.ArrowBack, | |||
imageVector = Icons.Default.Close, |
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.
Makes sense. In that case can we change SettingsView to match?
@@ -0,0 +1,9 @@ | |||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
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.
Nice! Where did you find this?
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.
official page: https://fonts.google.com/icons
|
||
@OptIn(PrivateBetaConnectSDK::class, ExperimentalMaterialApi::class) | ||
@Composable | ||
fun ComponentPickerContent( |
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.
Nice refactor!
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.
gradle file changes LGTM
Summary
Main changes:
androidx.hilt:hilt-navigation-compose
See inline comments for more.
Motivation
https://jira.corp.stripe.com/browse/MXMOBILE-2512
This is in preparation for adding Account Onboarding component settings, which we want to navigate to from the Settings screen.
Testing
Screenshots
In addition to showing the happy path, the demo below also shows error state and app restoration.
Screen.Recording.2024-12-09.at.11.35.36.AM-compressed.mov