-
Notifications
You must be signed in to change notification settings - Fork 663
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
[Identity][Compose] Remove all fragments and use a Compose NavHost #5981
Conversation
import com.stripe.android.identity.analytics.IdentityAnalyticsRequestFactory | ||
import com.stripe.android.identity.networking.models.Requirement | ||
|
||
internal abstract class IdentityTopLevelDestination( |
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.
Note: The content of this class is not changed(except the one place below) but just moved from NavigationDestinations.kt
|
||
internal class PassportScanDestination( | ||
internal abstract class DocumentScanDestination( |
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.
DocumentScanDestination is the super class of PassportScanDestination
, IDScanDestination
and DriverLicenseScanDestination
, as their parameters list are exactly the same
|
||
internal class PassportUploadDestination( | ||
internal abstract class DocumentUploadDestination( |
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.
DocumentUploadDestination is the super class of PassportUploadDestination
, IDUploadDestination
and DriverLicenseUploadDestination
, as their parameters list are exactly the same
Diffuse output:
APK
DEX
ARSC
|
// If this happens, set the back button destination to [DEFAULT_BACK_BUTTON_DESTINATION] | ||
const val UNEXPECTED_ROUTE = "UnexpectedRoute" | ||
|
||
fun errorTitle(backStackEntry: NavBackStackEntry) = |
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.
the parameters passed to a destination is set with destinationRoute.withParams
method.
destinationRoute
is something like Error?arg1={arg1}&arg2={arg2}
destinationRoute.withParams
set the params with actual values Error?arg1=value1&arg2=value2
.
This would in turn created a NavBackStackEntry
with a bundle with "arg1"="value1", "arg2"="value2"
, then we created these static function to fetch corresponding entries. This is a slightly generalized version of FinancialConnection's ManualEntrySuccess.microdeposits
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.
👏 love it!
@@ -53,92 +52,90 @@ internal fun ConfirmationScreen( | |||
val verificationPageState by identityViewModel.verificationPage.observeAsState(Resource.loading()) | |||
val context = LocalContext.current | |||
|
|||
MdcTheme { |
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.
Note: all Screen changes are just removing the encapsulating MdcTheme
, as we now have it in the NavHost
* Navigate to the [IdentityTopLevelDestination] by calling NavController.navigate(fragmentID, bundle). | ||
*/ | ||
internal fun NavController.navigateTo(destination: IdentityTopLevelDestination) { | ||
navigate(destination.routeWithArgs) { |
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.
this was changed from navigate(fragmentId)
to navigate(routeWithArgs)
26390cd
to
5f7e62d
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.
Looking good! a few comments.
onBackPressedCallback = | ||
IdentityActivityOnBackPressedCallback( | ||
this, | ||
navController, | ||
identityViewModel | ||
) | ||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback) |
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.
should this be under a LaunchedEffect
? so that it doesn't get retriggered on recompositions.
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.
it is wrapped within a LaunchedEffect
in IdentityNavGraph
: link
identity/src/main/java/com/stripe/android/identity/IdentityActivity.kt
Outdated
Show resolved
Hide resolved
import androidx.navigation.navArgument | ||
import com.stripe.android.identity.networking.models.CollectedDataParam | ||
|
||
internal class CameraPermissionDeniedDestination( |
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.
I like this to pass params as an abstraction 👏
// If this happens, set the back button destination to [DEFAULT_BACK_BUTTON_DESTINATION] | ||
const val UNEXPECTED_ROUTE = "UnexpectedRoute" | ||
|
||
fun errorTitle(backStackEntry: NavBackStackEntry) = |
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.
👏 love it!
identity/src/main/java/com/stripe/android/identity/navigation/IdentityTopLevelDestination.kt
Show resolved
Hide resolved
identity/src/main/java/com/stripe/android/identity/navigation/IdentityTopLevelDestination.kt
Outdated
Show resolved
Hide resolved
identityViewModel.verificationArgs.brandLogo, | ||
verificationPage, | ||
onConsentAgreed = { | ||
coroutineScope.launch { |
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.
should this be run using viewModelScope
instead? otherwise the api call would be cancelled if the component leaves the composition.
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.
hmm I think it's OK because postVerificationPageDataAndMaybeNavigate
post an API and triggers navigation(which would make ConsentScreen
leaving the composition)
Summary
Final PR to fully migrate Identity SDK to jetpack compose.
Before the SDK use a NavController to navigate between
Fragment
s. This PR replaced all fragments with aIdentityNavGraph
with differentcomposable
s. Eachcomposable
is represented by a String route.Before the PR
IdentityTopLevelDestination
and its subclassesDestinationRoute
abstract class, which dynamically populates the route fromrouteBase?argName1={argName1}&argName2={argName2}
torouteBase?argName1=value1&argName2=value2
, and exposed static method to fetch the arguments fromNavBackStackEntry
(similar to FinancialConnection'ManualEntrySuccess.microdeposits
methods), seeErrorDestination.errorTitle
for detailsNavController.navigateTo(destination: IdentityTopLevelDestination)
, its implementation was to navigate between fragmentIdsBellow is a 1-to-1 mapping between Fragments and subclasses of IdentityTopLevelDestination.
After the PR:
IdentityTopLevelDestination
and their subclasses is moved to their own filesIdentityNavGraph
created, creating aNavHost
with differentcomposable
sNavController.navigateTo(destination: IdentityTopLevelDestination)
implementation changed from fragmentId to routesfragmentId
s are used as indicator of a screen, now we checked theroute
string insteadNavController.clearDataAndNavigateUp
- checking which screen is in backStackEntryIdentityActivity.isConsent
/IdentityActivity.isConfirmation
/IdentityActivity.isErrorThatShouldFail
- checking what is the current screenErrorScreen
's backButton destination - indicating which screen to popUp to when back is pressedMdcTheme
on individual screens as now we have it in theNavHost
, apart from that there are no changes in the screens. These are all the Screen files:ConfirmationScreen
ConsentScreen
DocSelectionScreen
DocumentScanScreen
ErrorScreen
SelfieScreen
UploadScreen
Motivation
Go full Jetpack Compose
Testing
Screenshots
Changelog