File tree Expand file tree Collapse file tree 7 files changed +28
-14
lines changed
androidMain/kotlin/com/arkivanov/decompose/mainthread
commonMain/kotlin/com/arkivanov/decompose
darwinMain/kotlin/com/arkivanov/decompose/mainthread
jvmMain/kotlin/com/arkivanov/decompose/mainthread Expand file tree Collapse file tree 7 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -71,13 +71,15 @@ public final class com/arkivanov/decompose/DecomposeExperimentFlags {
7171public final class com/arkivanov/decompose/DecomposeSettings {
7272 public static final field Companion Lcom/arkivanov/decompose/DecomposeSettings$Companion;
7373 public fun <init> ()V
74- public fun <init> (Z )V
75- public synthetic fun <init> (ZILkotlin /jvm/internal/DefaultConstructorMarker;)V
74+ public fun <init> (ZZ )V
75+ public synthetic fun <init> (ZZILkotlin /jvm/internal/DefaultConstructorMarker;)V
7676 public final fun component1 ()Z
77- public final fun copy (Z)Lcom/arkivanov/decompose/DecomposeSettings;
78- public static synthetic fun copy$default (Lcom/arkivanov/decompose/DecomposeSettings;ZILjava/lang/Object;)Lcom/arkivanov/decompose/DecomposeSettings;
77+ public final fun component2 ()Z
78+ public final fun copy (ZZ)Lcom/arkivanov/decompose/DecomposeSettings;
79+ public static synthetic fun copy$default (Lcom/arkivanov/decompose/DecomposeSettings;ZZILjava/lang/Object;)Lcom/arkivanov/decompose/DecomposeSettings;
7980 public fun equals (Ljava/lang/Object;)Z
8081 public final fun getDuplicateConfigurationsEnabled ()Z
82+ public final fun getMainThreadCheckEnabled ()Z
8183 public fun hashCode ()I
8284 public fun toString ()Ljava/lang/String;
8385}
Original file line number Diff line number Diff line change @@ -483,13 +483,16 @@ final class <#A: out kotlin/Any> com.arkivanov.decompose.router.pages/Pages { //
483483}
484484
485485final class com.arkivanov.decompose/DecomposeSettings { // com.arkivanov.decompose/DecomposeSettings|null[0]
486- constructor <init>(kotlin/Boolean = ...) // com.arkivanov.decompose/DecomposeSettings.<init>|<init>(kotlin.Boolean){}[0]
486+ constructor <init>(kotlin/Boolean = ..., kotlin/Boolean = ... ) // com.arkivanov.decompose/DecomposeSettings.<init>|<init>(kotlin.Boolean; kotlin.Boolean){}[0]
487487
488488 final val duplicateConfigurationsEnabled // com.arkivanov.decompose/DecomposeSettings.duplicateConfigurationsEnabled|{}duplicateConfigurationsEnabled[0]
489489 final fun <get-duplicateConfigurationsEnabled>(): kotlin/Boolean // com.arkivanov.decompose/DecomposeSettings.duplicateConfigurationsEnabled.<get-duplicateConfigurationsEnabled>|<get-duplicateConfigurationsEnabled>(){}[0]
490+ final val mainThreadCheckEnabled // com.arkivanov.decompose/DecomposeSettings.mainThreadCheckEnabled|{}mainThreadCheckEnabled[0]
491+ final fun <get-mainThreadCheckEnabled>(): kotlin/Boolean // com.arkivanov.decompose/DecomposeSettings.mainThreadCheckEnabled.<get-mainThreadCheckEnabled>|<get-mainThreadCheckEnabled>(){}[0]
490492
491493 final fun component1(): kotlin/Boolean // com.arkivanov.decompose/DecomposeSettings.component1|component1(){}[0]
492- final fun copy(kotlin/Boolean = ...): com.arkivanov.decompose/DecomposeSettings // com.arkivanov.decompose/DecomposeSettings.copy|copy(kotlin.Boolean){}[0]
494+ final fun component2(): kotlin/Boolean // com.arkivanov.decompose/DecomposeSettings.component2|component2(){}[0]
495+ final fun copy(kotlin/Boolean = ..., kotlin/Boolean = ...): com.arkivanov.decompose/DecomposeSettings // com.arkivanov.decompose/DecomposeSettings.copy|copy(kotlin.Boolean;kotlin.Boolean){}[0]
493496 final fun equals(kotlin/Any?): kotlin/Boolean // com.arkivanov.decompose/DecomposeSettings.equals|equals(kotlin.Any?){}[0]
494497 final fun hashCode(): kotlin/Int // com.arkivanov.decompose/DecomposeSettings.hashCode|hashCode(){}[0]
495498 final fun toString(): kotlin/String // com.arkivanov.decompose/DecomposeSettings.toString|toString(){}[0]
Original file line number Diff line number Diff line change @@ -71,13 +71,15 @@ public final class com/arkivanov/decompose/DecomposeExperimentFlags {
7171public final class com/arkivanov/decompose/DecomposeSettings {
7272 public static final field Companion Lcom/arkivanov/decompose/DecomposeSettings$Companion;
7373 public fun <init> ()V
74- public fun <init> (Z )V
75- public synthetic fun <init> (ZILkotlin /jvm/internal/DefaultConstructorMarker;)V
74+ public fun <init> (ZZ )V
75+ public synthetic fun <init> (ZZILkotlin /jvm/internal/DefaultConstructorMarker;)V
7676 public final fun component1 ()Z
77- public final fun copy (Z)Lcom/arkivanov/decompose/DecomposeSettings;
78- public static synthetic fun copy$default (Lcom/arkivanov/decompose/DecomposeSettings;ZILjava/lang/Object;)Lcom/arkivanov/decompose/DecomposeSettings;
77+ public final fun component2 ()Z
78+ public final fun copy (ZZ)Lcom/arkivanov/decompose/DecomposeSettings;
79+ public static synthetic fun copy$default (Lcom/arkivanov/decompose/DecomposeSettings;ZZILjava/lang/Object;)Lcom/arkivanov/decompose/DecomposeSettings;
7980 public fun equals (Ljava/lang/Object;)Z
8081 public final fun getDuplicateConfigurationsEnabled ()Z
82+ public final fun getMainThreadCheckEnabled ()Z
8183 public fun hashCode ()I
8284 public fun toString ()Ljava/lang/String;
8385}
Original file line number Diff line number Diff line change 11package com.arkivanov.decompose.mainthread
22
33import android.os.Looper
4+ import com.arkivanov.decompose.DecomposeSettings
45import com.arkivanov.decompose.errorhandler.onDecomposeError
56
67private val mainThreadId: Long? by lazy {
78 try {
89 Looper .getMainLooper().thread.id
9- } catch (e : Exception ) {
10+ } catch (_ : Exception ) {
1011 null
1112 }
1213}
1314
1415internal actual fun checkMainThread () {
15- if ((mainThreadId != null ) && (Thread .currentThread().id != mainThreadId)) {
16+ if (DecomposeSettings .settings.mainThreadCheckEnabled && (mainThreadId != null ) && (Thread .currentThread().id != mainThreadId)) {
1617 onDecomposeError(NotOnMainThreadException (currentThreadName = Thread .currentThread().name))
1718 }
1819}
Original file line number Diff line number Diff line change @@ -7,9 +7,13 @@ import kotlin.concurrent.Volatile
77 *
88 * @param duplicateConfigurationsEnabled controls whether duplicate configurations are enabled or not. Default value is `false`.
99 * Excludes the `Child Items` navigation model, which doesn't support duplicate configurations.
10+ * @param mainThreadCheckEnabled controls whether main thread checks are enabled or not.
11+ * If enabled, Decompose will log an error if it detects access from a background thread when it was expected from the main thread.
12+ * Default value is `true`.
1013 */
1114data class DecomposeSettings (
1215 val duplicateConfigurationsEnabled : Boolean = false ,
16+ val mainThreadCheckEnabled : Boolean = true ,
1317) {
1418
1519 companion object {
Original file line number Diff line number Diff line change 11package com.arkivanov.decompose.mainthread
22
3+ import com.arkivanov.decompose.DecomposeSettings
34import com.arkivanov.decompose.errorhandler.onDecomposeError
45import platform.Foundation.NSThread
56
67internal actual fun checkMainThread () {
7- if (! NSThread .isMainThread()) {
8+ if (DecomposeSettings .settings.mainThreadCheckEnabled && ! NSThread .isMainThread()) {
89 onDecomposeError(NotOnMainThreadException (currentThreadName = NSThread .currentThread.description()))
910 }
1011}
Original file line number Diff line number Diff line change 11package com.arkivanov.decompose.mainthread
22
3+ import com.arkivanov.decompose.DecomposeSettings
34import com.arkivanov.decompose.errorhandler.onDecomposeError
45
56internal actual fun checkMainThread () {
6- if (mainThreadChecker?.isMainThread() == false ) {
7+ if (DecomposeSettings .settings.mainThreadCheckEnabled && mainThreadChecker?.isMainThread() == false ) {
78 onDecomposeError(NotOnMainThreadException (currentThreadName = Thread .currentThread().name))
89 }
910}
You can’t perform that action at this time.
0 commit comments