diff --git a/components/gradle.properties b/components/gradle.properties index f4fd2d49f3..ffd9218f0c 100644 --- a/components/gradle.properties +++ b/components/gradle.properties @@ -8,7 +8,7 @@ android.useAndroidX=true #Versions kotlin.version=1.9.21 -compose.version=1.6.0-dev1334 +compose.version=1.6.0-dev1340 agp.version=8.1.2 #Compose diff --git a/components/resources/library/src/androidInstrumentedTest/kotlin/org/jetbrains/compose/resources/ComposeResourceTest.android.kt b/components/resources/library/src/androidInstrumentedTest/kotlin/org/jetbrains/compose/resources/ComposeResourceTest.android.kt index b96859515b..7c4441a9e1 100644 --- a/components/resources/library/src/androidInstrumentedTest/kotlin/org/jetbrains/compose/resources/ComposeResourceTest.android.kt +++ b/components/resources/library/src/androidInstrumentedTest/kotlin/org/jetbrains/compose/resources/ComposeResourceTest.android.kt @@ -21,6 +21,11 @@ class ComposeResourceTest { dropImageCache() } + @Before + fun configureTestEnvironment() { + getResourceEnvironment = ::getTestEnvironment + } + @Test fun testCountRecompositions() = runComposeUiTest { runBlockingTest { diff --git a/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.android.kt b/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.android.kt index e32e51290b..cc4c816ab3 100644 --- a/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.android.kt +++ b/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.android.kt @@ -4,7 +4,7 @@ import android.content.res.Configuration import android.content.res.Resources import java.util.* -internal actual fun getResourceEnvironment(): ResourceEnvironment { +internal actual fun getSystemEnvironment(): ResourceEnvironment { val locale = Locale.getDefault() val configuration = Resources.getSystem().configuration val isDarkTheme = configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES diff --git a/components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.kt b/components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.kt index 8fe001b8fe..cb53469131 100644 --- a/components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.kt +++ b/components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.kt @@ -39,11 +39,14 @@ internal val DefaultComposeEnvironment = object : ComposeEnvironment { //ComposeEnvironment provider will be overridden for tests internal val LocalComposeEnvironment = staticCompositionLocalOf { DefaultComposeEnvironment } +internal expect fun getSystemEnvironment(): ResourceEnvironment + +//the function reference will be overridden for tests /** * Provides the resource environment for non-composable access to string resources. * It is an expensive operation! Don't use it in composable functions with no cache! */ -internal expect fun getResourceEnvironment(): ResourceEnvironment +internal var getResourceEnvironment = ::getSystemEnvironment internal fun Resource.getPathByEnvironment(environment: ResourceEnvironment): String { //Priority of environments: https://developer.android.com/guide/topics/resources/providing-resources#table2 diff --git a/components/resources/library/src/commonTest/kotlin/org/jetbrains/compose/resources/TestComposeEnvironment.kt b/components/resources/library/src/commonTest/kotlin/org/jetbrains/compose/resources/TestComposeEnvironment.kt index dd40f171c5..ad19013d8b 100644 --- a/components/resources/library/src/commonTest/kotlin/org/jetbrains/compose/resources/TestComposeEnvironment.kt +++ b/components/resources/library/src/commonTest/kotlin/org/jetbrains/compose/resources/TestComposeEnvironment.kt @@ -2,12 +2,14 @@ package org.jetbrains.compose.resources import androidx.compose.runtime.Composable +internal fun getTestEnvironment() = ResourceEnvironment( + language = LanguageQualifier("en"), + region = RegionQualifier("US"), + theme = ThemeQualifier.LIGHT, + density = DensityQualifier.XHDPI +) + internal val TestComposeEnvironment = object : ComposeEnvironment { @Composable - override fun rememberEnvironment() = ResourceEnvironment( - language = LanguageQualifier("en"), - region = RegionQualifier("US"), - theme = ThemeQualifier.LIGHT, - density = DensityQualifier.XHDPI - ) + override fun rememberEnvironment() = getTestEnvironment() } \ No newline at end of file diff --git a/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.desktop.kt b/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.desktop.kt index 7e2eb848a4..8c45734ebe 100644 --- a/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.desktop.kt +++ b/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.desktop.kt @@ -5,7 +5,7 @@ import org.jetbrains.skiko.currentSystemTheme import java.awt.Toolkit import java.util.* -internal actual fun getResourceEnvironment(): ResourceEnvironment { +internal actual fun getSystemEnvironment(): ResourceEnvironment { val locale = Locale.getDefault() //FIXME: don't use skiko internals val isDarkTheme = currentSystemTheme == SystemTheme.DARK diff --git a/components/resources/library/src/desktopTest/kotlin/org/jetbrains/compose/resources/ComposeResourceTest.desktop.kt b/components/resources/library/src/desktopTest/kotlin/org/jetbrains/compose/resources/ComposeResourceTest.desktop.kt index b96859515b..7c4441a9e1 100644 --- a/components/resources/library/src/desktopTest/kotlin/org/jetbrains/compose/resources/ComposeResourceTest.desktop.kt +++ b/components/resources/library/src/desktopTest/kotlin/org/jetbrains/compose/resources/ComposeResourceTest.desktop.kt @@ -21,6 +21,11 @@ class ComposeResourceTest { dropImageCache() } + @Before + fun configureTestEnvironment() { + getResourceEnvironment = ::getTestEnvironment + } + @Test fun testCountRecompositions() = runComposeUiTest { runBlockingTest { diff --git a/components/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.ios.kt b/components/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.ios.kt index da4f438363..780e76fcaa 100644 --- a/components/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.ios.kt +++ b/components/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.ios.kt @@ -4,7 +4,7 @@ import platform.Foundation.* import platform.UIKit.UIScreen import platform.UIKit.UIUserInterfaceStyle -internal actual fun getResourceEnvironment(): ResourceEnvironment { +internal actual fun getSystemEnvironment(): ResourceEnvironment { val locale = NSLocale.currentLocale() val mainScreen = UIScreen.mainScreen diff --git a/components/resources/library/src/jsMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.js.kt b/components/resources/library/src/jsMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.js.kt index d81bccce7b..4039c79438 100644 --- a/components/resources/library/src/jsMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.js.kt +++ b/components/resources/library/src/jsMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.js.kt @@ -9,7 +9,7 @@ private external class Intl { } } -internal actual fun getResourceEnvironment(): ResourceEnvironment { +internal actual fun getSystemEnvironment(): ResourceEnvironment { val locale = Intl.Locale(window.navigator.language) val isDarkTheme = window.matchMedia("(prefers-color-scheme: dark)").matches //96 - standard browser DPI https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio diff --git a/components/resources/library/src/macosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.macos.kt b/components/resources/library/src/macosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.macos.kt index 91c8cf20c6..83404652ee 100644 --- a/components/resources/library/src/macosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.macos.kt +++ b/components/resources/library/src/macosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.macos.kt @@ -6,7 +6,7 @@ import platform.CoreGraphics.CGDisplayPixelsWide import platform.CoreGraphics.CGDisplayScreenSize import platform.Foundation.* -internal actual fun getResourceEnvironment(): ResourceEnvironment { +internal actual fun getSystemEnvironment(): ResourceEnvironment { val locale = NSLocale.currentLocale() val isDarkTheme = NSUserDefaults.standardUserDefaults.stringForKey("AppleInterfaceStyle") == "Dark" diff --git a/components/resources/library/src/wasmJsMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.wasmJs.kt b/components/resources/library/src/wasmJsMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.wasmJs.kt index 4ab2d1cc05..48f3acd851 100644 --- a/components/resources/library/src/wasmJsMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.wasmJs.kt +++ b/components/resources/library/src/wasmJsMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.wasmJs.kt @@ -9,7 +9,7 @@ private external class Intl { } } -internal actual fun getResourceEnvironment(): ResourceEnvironment { +internal actual fun getSystemEnvironment(): ResourceEnvironment { val locale = Intl.Locale(window.navigator.language) val isDarkTheme = window.matchMedia("(prefers-color-scheme: dark)").matches //96 - standard browser DPI https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio diff --git a/gradle-plugins/gradle.properties b/gradle-plugins/gradle.properties index 64c141928c..aa953f63cd 100644 --- a/gradle-plugins/gradle.properties +++ b/gradle-plugins/gradle.properties @@ -2,7 +2,7 @@ org.gradle.parallel=true kotlin.code.style=official # Default version of Compose Libraries used by Gradle plugin -compose.version=1.6.0-dev1268 +compose.version=1.6.0-dev1340 # The latest version of Compose Compiler used by Gradle plugin. Used only in tests/CI. compose.tests.compiler.version=1.5.4 # The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests/CI.