-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from teogor/feature/configuration-state-monitor
Implement Configuration State Monitoring for Compose
- Loading branch information
Showing
13 changed files
with
622 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public final class dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor { | ||
public static final field $stable I | ||
public fun <init> (Landroid/app/Activity;)V | ||
public final fun isChanging ()Z | ||
} | ||
|
||
public final class dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor_androidKt { | ||
public static final fun getConfigurationStateMonitor (Landroidx/compose/runtime/Composer;I)Ldev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor; | ||
} | ||
|
||
public final class dev/teogor/crosslens/compose/lifecycle/EffectsKt { | ||
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V | ||
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V | ||
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V | ||
public static final fun DisposableEffectIgnoringConfiguration ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public final class dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor { | ||
public static final field $stable I | ||
public fun <init> ()V | ||
public final fun isChanging ()Z | ||
} | ||
|
||
public final class dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor_jvmKt { | ||
public static final fun getConfigurationStateMonitor (Landroidx/compose/runtime/Composer;I)Ldev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor; | ||
} | ||
|
||
public final class dev/teogor/crosslens/compose/lifecycle/EffectsKt { | ||
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V | ||
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V | ||
public static final fun DisposableEffectIgnoringConfiguration (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V | ||
public static final fun DisposableEffectIgnoringConfiguration ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi | ||
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl | ||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile | ||
|
||
plugins { | ||
alias(libs.plugins.jetbrains.kotlin.multiplatform) | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.jetbrains.compose) | ||
alias(libs.plugins.jetbrains.compose.compiler) | ||
alias(libs.plugins.teogor.winds) | ||
} | ||
|
||
winds { | ||
moduleMetadata { | ||
artifactDescriptor { | ||
name = "Compose" | ||
} | ||
} | ||
} | ||
|
||
kotlin { | ||
explicitApi() | ||
|
||
applyDefaultHierarchyTemplate() | ||
|
||
jvm { | ||
kotlin { | ||
jvmToolchain(11) | ||
} | ||
} | ||
|
||
js(IR) { | ||
browser() | ||
nodejs() | ||
} | ||
|
||
@OptIn(ExperimentalWasmDsl::class) | ||
wasmJs { | ||
browser() | ||
nodejs() | ||
binaries.executable() | ||
} | ||
|
||
androidTarget { | ||
@OptIn(ExperimentalKotlinGradlePluginApi::class) | ||
compilerOptions { | ||
jvmTarget.set(JvmTarget.JVM_11) | ||
} | ||
} | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { target -> | ||
target.binaries.framework { | ||
baseName = "crosslens-compose" | ||
} | ||
} | ||
|
||
macosX64() | ||
macosArm64() | ||
|
||
sourceSets { | ||
commonMain.dependencies { | ||
implementation(compose.runtime) | ||
implementation(compose.ui) | ||
|
||
implementation(libs.kotlinx.coroutines.core) | ||
} | ||
} | ||
} | ||
|
||
android { | ||
namespace = "dev.teogor.crosslens.compose" | ||
compileSdk = libs.versions.android.compileSdk.get().toInt() | ||
|
||
defaultConfig { | ||
minSdk = libs.versions.android.minSdk.get().toInt() | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(11) | ||
} | ||
} | ||
|
||
tasks.withType<KotlinJvmCompile>().configureEach { | ||
compilerOptions { | ||
jvmTarget.set(JvmTarget.JVM_11) | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...idMain/kotlin/dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.crosslens.compose.lifecycle | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.ContextWrapper | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.NonRestartableComposable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
|
||
private tailrec fun Context.getActivity(): Activity? = when (this) { | ||
is Activity -> this | ||
is ContextWrapper -> baseContext.getActivity() | ||
else -> null | ||
} | ||
|
||
/** | ||
* Retrieves the [ConfigurationStateMonitor] instance for checking configuration changes. | ||
* | ||
* @return An instance of [ConfigurationStateMonitor]. | ||
*/ | ||
@Composable | ||
@NonRestartableComposable | ||
public actual fun getConfigurationStateMonitor(): ConfigurationStateMonitor { | ||
val context = LocalContext.current | ||
return remember(context) { ConfigurationStateMonitor(context.getActivity()) } | ||
} | ||
|
||
/** | ||
* Monitors the state of configuration changes. | ||
* | ||
* This class provides functionality to determine if the application is currently | ||
* undergoing a configuration change, such as screen rotations or other system-level | ||
* changes that affect the application's state. | ||
*/ | ||
@Stable | ||
public actual class ConfigurationStateMonitor( | ||
private val activity: Activity? | ||
) { | ||
/** | ||
* Checks if a configuration change is currently ongoing. | ||
* | ||
* @return `true` if a configuration change is in progress; `false` otherwise. | ||
*/ | ||
public actual fun isChanging(): Boolean { | ||
return activity?.isChangingConfigurations ?: false | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...ppleMain/kotlin/dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor.apple.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.crosslens.compose.lifecycle | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.NonRestartableComposable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.runtime.remember | ||
|
||
private val configurationStateMonitor = ConfigurationStateMonitor() | ||
|
||
/** | ||
* Retrieves the [ConfigurationStateMonitor] instance for checking configuration changes. | ||
* | ||
* @return An instance of [ConfigurationStateMonitor]. | ||
*/ | ||
@Composable | ||
@NonRestartableComposable | ||
public actual fun getConfigurationStateMonitor(): ConfigurationStateMonitor { | ||
return remember { configurationStateMonitor } | ||
} | ||
|
||
/** | ||
* Monitors the state of configuration changes. | ||
* | ||
* This class provides functionality to determine if the application is currently | ||
* undergoing a configuration change, such as screen rotations or other system-level | ||
* changes that affect the application's state. | ||
*/ | ||
@Stable | ||
public actual class ConfigurationStateMonitor { | ||
/** | ||
* Checks if a configuration change is currently ongoing. | ||
* | ||
* @return `true` if a configuration change is in progress; `false` otherwise. | ||
*/ | ||
public actual fun isChanging(): Boolean = false | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...monMain/kotlin/dev/teogor/crosslens/compose/lifecycle/ConfigurationStateMonitor.common.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.crosslens.compose.lifecycle | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.NonRestartableComposable | ||
import androidx.compose.runtime.Stable | ||
|
||
/** | ||
* Retrieves the [ConfigurationStateMonitor] instance for checking configuration changes. | ||
* | ||
* @return An instance of [ConfigurationStateMonitor]. | ||
*/ | ||
@Composable | ||
@NonRestartableComposable | ||
public expect fun getConfigurationStateMonitor(): ConfigurationStateMonitor | ||
|
||
/** | ||
* Monitors the state of configuration changes. | ||
* | ||
* This class provides functionality to determine if the application is currently | ||
* undergoing a configuration change, such as screen rotations or other system-level | ||
* changes that affect the application's state. | ||
*/ | ||
@Stable | ||
public expect class ConfigurationStateMonitor { | ||
|
||
/** | ||
* Checks if a configuration change is currently ongoing. | ||
* | ||
* @return `true` if a configuration change is in progress; `false` otherwise. | ||
*/ | ||
public fun isChanging(): Boolean | ||
} |
Oops, something went wrong.