[Identity] Gracefully handle non-material themes.#11583
[Identity] Gracefully handle non-material themes.#11583carlosmuvi-stripe wants to merge 4 commits intomasterfrom
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.
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.
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.
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