Skip to content
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

[resources] Fix regionCode crash on iOS before 17 #4473

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import platform.UIKit.UIUserInterfaceStyle
internal actual fun getSystemEnvironment(): ResourceEnvironment {
val locale = NSLocale.currentLocale()

val languageCode = locale.languageCode
val regionCode = locale.objectForKey(NSLocaleCountryCode) as? String
val mainScreen = UIScreen.mainScreen
val isDarkTheme = mainScreen.traitCollection().userInterfaceStyle == UIUserInterfaceStyle.UIUserInterfaceStyleDark

//there is no an API to get a physical screen size and calculate a real DPI
val density = mainScreen.scale.toFloat()
return ResourceEnvironment(
language = LanguageQualifier(locale.languageCode),
region = RegionQualifier(locale.regionCode.orEmpty()),
language = LanguageQualifier(languageCode),
region = RegionQualifier(regionCode.orEmpty()),
theme = ThemeQualifier.selectByValue(isDarkTheme),
density = DensityQualifier.selectByDensity(density)
)
Expand Down