Skip to content

Commit 9abf814

Browse files
committed
Workaround for missing Dispatchers.Main
1 parent 274f271 commit 9abf814

File tree

8 files changed

+113
-7
lines changed

8 files changed

+113
-7
lines changed

compose/ui/ui-test/src/linuxMain/kotlin/androidx/compose/ui/test/Synchronization.linuxMain.kt

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

1717
package androidx.compose.ui.test
1818

19+
import androidx.compose.ui.platform.ComposeUiMainDispatcher
1920
import kotlinx.cinterop.ExperimentalForeignApi
2021
import kotlinx.cinterop.cValue
21-
import kotlinx.coroutines.Dispatchers
2222
import kotlinx.coroutines.runBlocking
2323
import platform.posix.nanosleep
2424
import platform.posix.timespec
@@ -32,7 +32,7 @@ internal actual fun <T> runOnUiThread(action: () -> T): T {
3232
return if (isOnUiThread()) {
3333
action()
3434
} else {
35-
runBlocking(Dispatchers.Main) {
35+
runBlocking(ComposeUiMainDispatcher) {
3636
action()
3737
}
3838
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2023 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.ui
18+
19+
import kotlin.coroutines.CoroutineContext
20+
import kotlinx.coroutines.Dispatchers
21+
22+
internal actual val PostDelayedDispatcher: CoroutineContext
23+
get() = Dispatchers.Main

compose/ui/ui/src/jsNativeMain/kotlin/androidx/compose/ui/Actuals.jsNative.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package androidx.compose.ui
1818

1919
import androidx.compose.ui.node.ModifierNodeElement
2020
import androidx.compose.ui.platform.InspectorInfo
21-
import kotlin.coroutines.CoroutineContext
22-
import kotlinx.coroutines.Dispatchers
2321
import kotlinx.coroutines.CancellationException
2422

2523
internal actual fun classKeyForObject(a: Any): Any {
@@ -33,6 +31,3 @@ internal actual fun InspectorInfo.tryPopulateReflectively(
3331
element: ModifierNodeElement<*>
3432
) {
3533
}
36-
37-
internal actual val PostDelayedDispatcher: CoroutineContext
38-
get() = Dispatchers.Main
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2023 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.ui
18+
19+
import kotlin.coroutines.CoroutineContext
20+
import kotlinx.coroutines.Dispatchers
21+
22+
internal actual val PostDelayedDispatcher: CoroutineContext
23+
get() = Dispatchers.Main
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2023 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.ui
18+
19+
import androidx.compose.ui.platform.ComposeUiMainDispatcher
20+
import kotlin.coroutines.CoroutineContext
21+
22+
internal actual val PostDelayedDispatcher: CoroutineContext
23+
get() = ComposeUiMainDispatcher
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2025 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.ui.platform
18+
19+
import kotlinx.coroutines.CoroutineDispatcher
20+
21+
lateinit var ComposeUiMainDispatcher: CoroutineDispatcher // TODO: https://github.com/Kotlin/kotlinx.coroutines/issues/4286
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2020 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.ui.platform
18+
19+
import kotlinx.coroutines.CoroutineDispatcher
20+
21+
internal actual val GlobalSnapshotManagerDispatcher: CoroutineDispatcher get() = ComposeUiMainDispatcher

0 commit comments

Comments
 (0)