Unverified Commit 02683bcd authored by Ivan Matkov's avatar Ivan Matkov Committed by GitHub

Check availability of UITraitCollection.currentTraitCollection (#730)

parent aa7e1bf7
package org.jetbrains.skiko package org.jetbrains.skiko
import kotlinx.cinterop.useContents
import platform.Foundation.NSProcessInfo
import platform.UIKit.* import platform.UIKit.*
import platform.UIKit.UIUserInterfaceStyle.* import platform.UIKit.UIUserInterfaceStyle.*
actual val currentSystemTheme: SystemTheme actual val currentSystemTheme: SystemTheme
get() = when (UITraitCollection.currentTraitCollection.userInterfaceStyle) { get() = if (supportsCurrentTraitCollectionApi) {
UIUserInterfaceStyleDark -> SystemTheme.DARK when (UITraitCollection.currentTraitCollection.userInterfaceStyle) {
UIUserInterfaceStyleLight -> SystemTheme.LIGHT UIUserInterfaceStyleDark -> SystemTheme.DARK
else -> SystemTheme.UNKNOWN UIUserInterfaceStyleLight -> SystemTheme.LIGHT
else -> SystemTheme.UNKNOWN
}
} else {
SystemTheme.LIGHT
} }
/*
* Getting trait collection for the current execution context supports only on iOS 13.0+
* https://developer.apple.com/documentation/uikit/uitraitcollection/3238080-currenttraitcollection?language=objc
*/
private val supportsCurrentTraitCollectionApi get() = NSProcessInfo.processInfo.operatingSystemVersion.useContents {
majorVersion >= 13
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment