Skip to content

Commit d7673d2

Browse files
authored
Use class.qualifiedName instead of class.simpleName in wasmJsMain where applicable (JetBrains#2780)
Since we migrated to Kotlin 2.3.0 we can use `class.qualifiedName` in k/wasm out of a box. Before that, we used to use `class.simpleName`. I changed it in our modules where it makes sense. Additional changes will be made in other modules published from androidx - https://partnerissuetracker.corp.google.com/issues/470109441 Fixes https://youtrack.jetbrains.com/issue/CMP-9509 ## Testing N/A ## Release Notes N/A
1 parent 4e293f2 commit d7673d2

5 files changed

Lines changed: 57 additions & 5 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2026 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package androidx.compose.material3.adaptive.layout
18+
19+
import androidx.compose.ui.Modifier
20+
21+
@Suppress("NOTHING_TO_INLINE")
22+
internal actual inline fun Modifier.Element.isGraphicsLayerElement(): Boolean {
23+
// TODO: remove this when k/js supports qualifiedName - https://youtrack.jetbrains.com/issue/KT-34534/Kotlin-JS-Add-compiler-intrinsic-for-KClass.qualifiedName
24+
// then all kotlin targets will rely on `qualifiedName` and there will be no need in expect/actual
25+
return this::class.simpleName == "GraphicsLayerElement"
26+
}

compose/material3/adaptive/adaptive-layout/src/webMain/kotlin/androidx/compose/material3/adaptive/layout/PaneScaffold.web.kt renamed to compose/material3/adaptive/adaptive-layout/src/wasmJsMain/kotlin/androidx/compose/material3/adaptive/layout/PaneScaffold.wasm.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package androidx.compose.material3.adaptive.layout
1818

19+
import androidx.compose.ui.Modifier
1920
@Suppress("NOTHING_TO_INLINE")
20-
internal actual inline fun androidx.compose.ui.Modifier.Element.isGraphicsLayerElement(): Boolean {
21-
// TODO: remove this after update to kotlin 2.3.0, where qualifiedName is available for k/wasm
22-
return this::class.simpleName == "GraphicsLayerElement"
21+
internal actual inline fun Modifier.Element.isGraphicsLayerElement(): Boolean {
22+
return this::class.qualifiedName == "androidx.compose.ui.graphics.GraphicsLayerElement"
2323
}

compose/ui/ui-text/src/webMain/kotlin/androidx/compose/ui/text/platform/PlatformFont.web.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ actual sealed class PlatformFont : Font {
2222
actual abstract val identity: String
2323
actual abstract val variationSettings: FontVariation.Settings
2424
internal actual val cacheKey: String
25-
// Unlike k/jvm and k/native, `this::class.qualifiedName` API is not available for k/js and k/wasm.
25+
// Unlike k/jvm and k/native, `this::class.qualifiedName` API is not available in k/js.
26+
// https://youtrack.jetbrains.com/issue/KT-34534
27+
// `class.qualifiedName` is supported in k/wasm since 2.3.0 - https://youtrack.jetbrains.com/issue/KT-69621
28+
// But for simplicity we keep using simpleName for now.
29+
// Reasoning:
2630
// Example: given LoadedFont(identity="abc", ...), it will return "LoadedFont|abc"
27-
// Such implementation is sufficient since PlatformFont is a sealed class, and
31+
// Such implementation is enough since PlatformFont is a sealed class, and
2832
// we control all of its variants (subclasses).
2933
get() = "${this::class.simpleName}|$identity|weight=${weight.weight}|style=$style|variationSettings=${variationSettings.settings}"
3034
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package androidx.lifecycle.viewmodel.compose
18+
19+
// TODO: remove expect actual when k/js support `qualifiedName`
20+
// https://youtrack.jetbrains.com/issue/KT-34534/Kotlin-JS-Add-compiler-intrinsic-for-KClass.qualifiedName
21+
internal actual fun getSaveableKeyPrefix(thisRef: Any?): String =
22+
if (thisRef != null) thisRef::class.simpleName + "." else ""

lifecycle/lifecycle-viewmodel-compose/src/webMain/kotlin/androidx/lifecycle/viewmodel/compose/SavedStateHandleSaver.web.kt renamed to lifecycle/lifecycle-viewmodel-compose/src/wasmJsMain/kotlin/androidx/lifecycle/viewmodel/compose/SavedStateHandleSaver.wasm.kt

File renamed without changes.

0 commit comments

Comments
 (0)