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
import kotlinx.cinterop.useContents
import platform.Foundation.NSProcessInfo
import platform.UIKit.*
import platform.UIKit.UIUserInterfaceStyle.*
actual val currentSystemTheme: SystemTheme
get() = when (UITraitCollection.currentTraitCollection.userInterfaceStyle) {
UIUserInterfaceStyleDark -> SystemTheme.DARK
UIUserInterfaceStyleLight -> SystemTheme.LIGHT
else -> SystemTheme.UNKNOWN
get() = if (supportsCurrentTraitCollectionApi) {
when (UITraitCollection.currentTraitCollection.userInterfaceStyle) {
UIUserInterfaceStyleDark -> SystemTheme.DARK
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