-
Notifications
You must be signed in to change notification settings - Fork 703
[Identity] Gracefully handle non-material themes. #11583
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
base: master
Are you sure you want to change the base?
[Identity] Gracefully handle non-material themes. #11583
Conversation
|
Risky Change This is considered a risky change because it adjusts the sample app build.gradle, please review carefully. By adding the label |
| create("appcompat") { | ||
| manifestPlaceholders["appTheme"] = "@style/Theme.AppCompatTest" | ||
| manifestPlaceholders["appIcon"] = "@drawable/merchant_logo_purple" | ||
| manifestPlaceholders["appIconRound"] = "@drawable/merchant_logo_purple" | ||
|
|
||
| dimension = "theme" | ||
| applicationIdSuffix = ".appcompat" | ||
| versionNameSuffix = "-appcompat" | ||
| } |
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.
to test non-material theming, now you can use
./gradlew :identity-example:installAppcompatDebug
|
Diffuse output: APKDEXARSC |
| @Composable | ||
| private fun detectHostThemeType(): HostThemeType { | ||
| val context = LocalContext.current | ||
|
|
||
| val isMaterialTheme = remember { | ||
| runCatching { | ||
| context.obtainStyledAttributes(MaterialR.styleable.ThemeAdapterMaterialTheme).use { ta -> | ||
| ta.hasValue(MaterialR.styleable.ThemeAdapterMaterialTheme_isMaterialTheme) | ||
| } | ||
| }.getOrDefault(false) | ||
| } | ||
|
|
||
| val isMaterial3Theme = remember { | ||
| runCatching { | ||
| context.obtainStyledAttributes(Material3R.styleable.ThemeAdapterMaterial3Theme).use { ta -> | ||
| ta.hasValue(Material3R.styleable.ThemeAdapterMaterial3Theme_isMaterial3Theme) | ||
| } | ||
| }.getOrDefault(false) | ||
| } | ||
|
|
||
| return when { | ||
| isMaterialTheme -> HostThemeType.MaterialComponents | ||
| isMaterial3Theme -> HostThemeType.Material3 | ||
| else -> HostThemeType.AppCompat | ||
| } | ||
| } | ||
|
|
||
| private enum class HostThemeType { | ||
| MaterialComponents, | ||
| Material3, | ||
| AppCompat | ||
| } |
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 this from payments. Cannot move to a shared module (stripe-ui-core) since it requires mdc / material theming related dependencies that other SDKs might not use.
| val defaultParameters = ThemeParameters( | ||
| colors = MaterialTheme.colors, | ||
| typography = MaterialTheme.typography, | ||
| shapes = MaterialTheme.shapes | ||
| ) |
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.
Use default Material theme if theme params cannot be extracted from a MaterialComponents theme.
Summary
MaterialThemeis required for Identity, we should handle non-Material theme usage gracefully to avoid crashes.AppCompat theme is still required
Motivation
👻
Testing
Screenshots
Changelog