Skip to content

Commit 2cc8689

Browse files
committed
Update DisposableEffect.kt
1 parent c86502b commit 2cc8689

File tree

13 files changed

+622
-0
lines changed

13 files changed

+622
-0
lines changed

composeApp/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ kotlin {
9696
implementation(libs.androidx.lifecycle.viewmodel)
9797
implementation(libs.androidx.lifecycle.runtime.compose)
9898

99+
implementation(projects.crosslensCompose)
99100
implementation(projects.crosslensCore)
100101
implementation(projects.crosslensUi)
101102
}

composeApp/src/commonMain/kotlin/dev/teogor/crosslens/App.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.runtime.remember
2929
import androidx.compose.ui.Alignment
3030
import androidx.compose.ui.Modifier
3131
import androidx.compose.ui.unit.dp
32+
import dev.teogor.crosslens.compose.lifecycle.getConfigurationStateMonitor
3233
import dev.teogor.crosslens.core.buildHashCode
3334
import dev.teogor.crosslens.ui.rememberVisibilityState
3435
import org.jetbrains.compose.ui.tooling.preview.Preview
@@ -49,6 +50,8 @@ public fun App() {
4950
visibility.show()
5051
visibility.toggle()
5152
}
53+
val configurationStateMonitor = getConfigurationStateMonitor()
54+
configurationStateMonitor.isChanging()
5255
remember {
5356
buildHashCode {
5457
append(visibility.isVisible)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public final class dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor {
2+
public static final field $stable I
3+
public fun <init> (Landroid/app/Activity;)V
4+
public final fun isChanging ()Z
5+
}
6+
7+
public final class dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor_androidKt {
8+
public static final fun getConfigurationStateMonitor (Landroidx/compose/runtime/Composer;I)Ldev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor;
9+
}
10+
11+
public final class dev/teogor/crosslens/compose/lifecycle/EffectsKt {
12+
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
13+
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
14+
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
15+
public static final fun DisposableEffectIgnoringConfiguration ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
16+
}
17+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public final class dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor {
2+
public static final field $stable I
3+
public fun <init> ()V
4+
public final fun isChanging ()Z
5+
}
6+
7+
public final class dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor_jvmKt {
8+
public static final fun getConfigurationStateMonitor (Landroidx/compose/runtime/Composer;I)Ldev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor;
9+
}
10+
11+
public final class dev/teogor/crosslens/compose/lifecycle/EffectsKt {
12+
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
13+
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
14+
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
15+
public static final fun DisposableEffectIgnoringConfiguration ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
16+
}
17+

crosslens-compose/build.gradle.kts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright 2024 Teogor (Teodor Grigor)
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+
* https://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+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
17+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
18+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
19+
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
20+
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions
21+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
22+
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
23+
24+
plugins {
25+
alias(libs.plugins.jetbrains.kotlin.multiplatform)
26+
alias(libs.plugins.android.library)
27+
alias(libs.plugins.jetbrains.compose)
28+
alias(libs.plugins.jetbrains.compose.compiler)
29+
alias(libs.plugins.teogor.winds)
30+
}
31+
32+
winds {
33+
moduleMetadata {
34+
artifactDescriptor {
35+
name = "Compose"
36+
}
37+
}
38+
}
39+
40+
kotlin {
41+
explicitApi()
42+
43+
applyDefaultHierarchyTemplate()
44+
45+
jvm {
46+
kotlin {
47+
jvmToolchain(11)
48+
}
49+
}
50+
51+
js(IR) {
52+
browser()
53+
nodejs()
54+
}
55+
56+
@OptIn(ExperimentalWasmDsl::class)
57+
wasmJs {
58+
browser()
59+
nodejs()
60+
binaries.executable()
61+
}
62+
63+
androidTarget {
64+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
65+
compilerOptions {
66+
jvmTarget.set(JvmTarget.JVM_11)
67+
}
68+
}
69+
70+
listOf(
71+
iosX64(),
72+
iosArm64(),
73+
iosSimulatorArm64()
74+
).forEach { target ->
75+
target.binaries.framework {
76+
baseName = "crosslens-compose"
77+
}
78+
}
79+
80+
macosX64()
81+
macosArm64()
82+
83+
sourceSets {
84+
commonMain.dependencies {
85+
implementation(compose.runtime)
86+
implementation(compose.ui)
87+
88+
implementation(libs.kotlinx.coroutines.core)
89+
}
90+
}
91+
}
92+
93+
android {
94+
namespace = "dev.teogor.crosslens.compose"
95+
compileSdk = libs.versions.android.compileSdk.get().toInt()
96+
97+
defaultConfig {
98+
minSdk = libs.versions.android.minSdk.get().toInt()
99+
}
100+
101+
compileOptions {
102+
sourceCompatibility = JavaVersion.VERSION_11
103+
targetCompatibility = JavaVersion.VERSION_11
104+
}
105+
106+
kotlin {
107+
jvmToolchain(11)
108+
}
109+
}
110+
111+
tasks.withType<KotlinJvmCompile>().configureEach {
112+
compilerOptions {
113+
jvmTarget.set(JvmTarget.JVM_11)
114+
}
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2024 Teogor (Teodor Grigor)
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+
* https://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 dev.teogor.crosslens.compose.lifecycle
18+
19+
import android.app.Activity
20+
import android.content.Context
21+
import android.content.ContextWrapper
22+
import androidx.compose.runtime.Composable
23+
import androidx.compose.runtime.NonRestartableComposable
24+
import androidx.compose.runtime.Stable
25+
import androidx.compose.runtime.remember
26+
import androidx.compose.ui.platform.LocalContext
27+
28+
private tailrec fun Context.getActivity(): Activity? = when (this) {
29+
is Activity -> this
30+
is ContextWrapper -> baseContext.getActivity()
31+
else -> null
32+
}
33+
34+
/**
35+
* Retrieves the [ConfigurationStateMonitor] instance for checking configuration changes.
36+
*
37+
* @return An instance of [ConfigurationStateMonitor].
38+
*/
39+
@Composable
40+
@NonRestartableComposable
41+
public actual fun getConfigurationStateMonitor(): ConfigurationStateMonitor {
42+
val context = LocalContext.current
43+
return remember(context) { ConfigurationStateMonitor(context.getActivity()) }
44+
}
45+
46+
/**
47+
* Monitors the state of configuration changes.
48+
*
49+
* This class provides functionality to determine if the application is currently
50+
* undergoing a configuration change, such as screen rotations or other system-level
51+
* changes that affect the application's state.
52+
*/
53+
@Stable
54+
public actual class ConfigurationStateMonitor(
55+
private val activity: Activity?
56+
) {
57+
/**
58+
* Checks if a configuration change is currently ongoing.
59+
*
60+
* @return `true` if a configuration change is in progress; `false` otherwise.
61+
*/
62+
public actual fun isChanging(): Boolean {
63+
return activity?.isChangingConfigurations ?: false
64+
}
65+
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2024 Teogor (Teodor Grigor)
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+
* https://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 dev.teogor.crosslens.compose.lifecycle
18+
19+
import androidx.compose.runtime.Composable
20+
import androidx.compose.runtime.NonRestartableComposable
21+
import androidx.compose.runtime.Stable
22+
import androidx.compose.runtime.remember
23+
24+
private val configurationStateMonitor = ConfigurationStateMonitor()
25+
26+
/**
27+
* Retrieves the [ConfigurationStateMonitor] instance for checking configuration changes.
28+
*
29+
* @return An instance of [ConfigurationStateMonitor].
30+
*/
31+
@Composable
32+
@NonRestartableComposable
33+
public actual fun getConfigurationStateMonitor(): ConfigurationStateMonitor {
34+
return remember { configurationStateMonitor }
35+
}
36+
37+
/**
38+
* Monitors the state of configuration changes.
39+
*
40+
* This class provides functionality to determine if the application is currently
41+
* undergoing a configuration change, such as screen rotations or other system-level
42+
* changes that affect the application's state.
43+
*/
44+
@Stable
45+
public actual class ConfigurationStateMonitor {
46+
/**
47+
* Checks if a configuration change is currently ongoing.
48+
*
49+
* @return `true` if a configuration change is in progress; `false` otherwise.
50+
*/
51+
public actual fun isChanging(): Boolean = false
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2024 Teogor (Teodor Grigor)
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+
* https://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 dev.teogor.crosslens.compose.lifecycle
18+
19+
import androidx.compose.runtime.Composable
20+
import androidx.compose.runtime.NonRestartableComposable
21+
import androidx.compose.runtime.Stable
22+
23+
/**
24+
* Retrieves the [ConfigurationStateMonitor] instance for checking configuration changes.
25+
*
26+
* @return An instance of [ConfigurationStateMonitor].
27+
*/
28+
@Composable
29+
@NonRestartableComposable
30+
public expect fun getConfigurationStateMonitor(): ConfigurationStateMonitor
31+
32+
/**
33+
* Monitors the state of configuration changes.
34+
*
35+
* This class provides functionality to determine if the application is currently
36+
* undergoing a configuration change, such as screen rotations or other system-level
37+
* changes that affect the application's state.
38+
*/
39+
@Stable
40+
public expect class ConfigurationStateMonitor {
41+
42+
/**
43+
* Checks if a configuration change is currently ongoing.
44+
*
45+
* @return `true` if a configuration change is in progress; `false` otherwise.
46+
*/
47+
public fun isChanging(): Boolean
48+
}

0 commit comments

Comments
 (0)