Skip to content

Commit

Permalink
Merge branch 'v2.2' into merge-v2.2-into-v2.2-compose-experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
arkivanov committed Nov 17, 2023
2 parents 1c38749 + f1c6152 commit e18a776
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 167 deletions.
8 changes: 4 additions & 4 deletions decompose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ kotlin {
setupSourceSets {
val android by bundle()
val nonAndroid by bundle()
val native by bundle()
val nonNative by bundle()
val darwin by bundle()
val itvos by bundle()
val js by bundle()
val nonJs by bundle()

(nonAndroid + native + nonNative + nonJs) dependsOn common
(nonAndroid + darwin + nonNative + nonJs) dependsOn common
(allSet - android) dependsOn nonAndroid
(allSet - nativeSet) dependsOn nonNative
(allSet - js) dependsOn nonJs
(nativeSet + darwin) dependsOn native
darwinSet dependsOn darwin
(iosSet + tvosSet) dependsOn itvos
(darwinSet - iosSet - tvosSet + itvos) dependsOn darwin

all {
languageSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ internal class Relay<T>(
private val isMainThreadCheckEnabled: Boolean = false,
) {

init {
ensureNeverFrozen()
}

private val lock = Lock()
private val queue = ArrayDeque<T>()
private var isDraining = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ fun Any.hashString(): String =

internal expect val KClass<*>.uniqueName: String?

internal expect fun Any.ensureNeverFrozen()

internal val Lifecycle.isDestroyed: Boolean get() = state == Lifecycle.State.DESTROYED
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.arkivanov.decompose.value

import com.arkivanov.decompose.Lock
import com.arkivanov.decompose.ensureNeverFrozen
import com.arkivanov.decompose.synchronized

/**
Expand All @@ -12,10 +11,6 @@ fun <T : Any> MutableValue(initialValue: T): MutableValue<T> = MutableValueImpl(

private class MutableValueImpl<T : Any>(initialValue: T) : MutableValue<T>() {

init {
ensureNeverFrozen()
}

private val lock = Lock()
private var _value: T = initialValue
private var isEmitting = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.arkivanov.decompose.backhandler

import com.arkivanov.decompose.ensureNeverFrozen
import com.arkivanov.essenty.backhandler.BackCallback
import com.arkivanov.essenty.backhandler.BackDispatcher

internal class TestBackDispatcher : BackDispatcher {

init {
ensureNeverFrozen()
}

private var set = emptySet<BackCallback>()
val size: Int get() = set.size

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.arkivanov.decompose.lifecycle

import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.essenty.lifecycle.Lifecycle
import com.arkivanov.essenty.lifecycle.LifecycleRegistry
import com.arkivanov.essenty.lifecycle.destroy
import com.arkivanov.essenty.lifecycle.pause
import com.arkivanov.essenty.lifecycle.resume
import com.arkivanov.essenty.lifecycle.start
import com.arkivanov.essenty.lifecycle.stop
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ObjCAction
import platform.Foundation.NSNotificationCenter
import platform.Foundation.NSNotificationName
import platform.Foundation.NSSelectorFromString
import platform.UIKit.UIApplicationDidBecomeActiveNotification
import platform.UIKit.UIApplicationDidEnterBackgroundNotification
import platform.UIKit.UIApplicationWillEnterForegroundNotification
import platform.UIKit.UIApplicationWillResignActiveNotification
import platform.UIKit.UIApplicationWillTerminateNotification

/**
* An implementation of [Lifecycle] that follows the [UIApplication][platform.UIKit.UIApplication] lifecycle notifications.
*/
@ExperimentalDecomposeApi
class ApplicationLifecycle private constructor(
private val lifecycle: LifecycleRegistry,
) : Lifecycle by lifecycle {

constructor() : this(lifecycle = LifecycleRegistry())

init {
addObserver(name = UIApplicationWillEnterForegroundNotification, selectorName = "willEnterForeground")
addObserver(name = UIApplicationDidBecomeActiveNotification, selectorName = "didBecomeActive")
addObserver(name = UIApplicationWillResignActiveNotification, selectorName = "willResignActive")
addObserver(name = UIApplicationDidEnterBackgroundNotification, selectorName = "didEnterBackground")
addObserver(name = UIApplicationWillTerminateNotification, selectorName = "willTerminate")
}

@OptIn(ExperimentalForeignApi::class)
private fun addObserver(name: NSNotificationName, selectorName: String) {
NSNotificationCenter.defaultCenter.addObserver(
name = name,
`object` = null,
observer = this,
selector = NSSelectorFromString(selectorName),
)
}

@Suppress("unused")
@OptIn(BetaInteropApi::class)
@ObjCAction
fun willEnterForeground() {
lifecycle.start()
}

@Suppress("unused")
@OptIn(BetaInteropApi::class)
@ObjCAction
fun didBecomeActive() {
lifecycle.resume()
}

@Suppress("unused")
@OptIn(BetaInteropApi::class)
@ObjCAction
fun willResignActive() {
lifecycle.pause()
}

@Suppress("unused")
@OptIn(BetaInteropApi::class)
@ObjCAction
fun didEnterBackground() {
lifecycle.stop()
}

@OptIn(BetaInteropApi::class)
@ObjCAction
fun willTerminate() {
lifecycle.destroy()
}
}

This file was deleted.

This file was deleted.

10 changes: 5 additions & 5 deletions deps.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[versions]

decompose = "2.2.0-compose-experimental-alpha04"
kotlin = "1.9.10"
essenty = "1.3.0-alpha03"
parcelizeDarwin = "0.2.2"
kotlin = "1.9.20"
essenty = "1.3.0-alpha04"
parcelizeDarwin = "0.2.3"
reaktive = "1.2.3"
junit = "4.13.2"
jetbrainsCompose = "1.5.1"
jetbrainsCompose = "1.5.10"
jetbrainsKotlinWrappers = "1.0.0-pre.608"
jetbrainsKotlinxCoroutines = "1.6.4"
jetbrainsKotlinxSerialization = "1.6.0"
jetbrainsBinaryCompatibilityValidator = "0.13.2"
jetpackCompose = "1.5.0"
jetpackComposeCompiler = "1.5.3"
jetpackComposeCompiler = "1.5.4"
androidGradle = "8.0.2"
androidMaterial = "1.6.1"
androidPlay = "1.10.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ public final class com/arkivanov/decompose/extensions/compose/jetbrains/pages/Pa
public final class com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation$Default : com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation {
public static final field $stable I
public static final field INSTANCE Lcom/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation$Default;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation$Disabled : com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation {
public static final field $stable I
public static final field INSTANCE Lcom/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation$Disabled;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/arkivanov/decompose/extensions/compose/jetbrains/stack/ChildrenKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ public final class com/arkivanov/decompose/extensions/compose/jetbrains/pages/Pa
public final class com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation$Default : com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation {
public static final field $stable I
public static final field INSTANCE Lcom/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation$Default;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation$Disabled : com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation {
public static final field $stable I
public static final field INSTANCE Lcom/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesScrollAnimation$Disabled;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/arkivanov/decompose/extensions/compose/jetbrains/stack/ChildrenKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.arkivanov.decompose.ExperimentalDecomposeApi
@ExperimentalDecomposeApi
sealed interface PagesScrollAnimation {

object Disabled : PagesScrollAnimation
object Default : PagesScrollAnimation
data object Disabled : PagesScrollAnimation
data object Default : PagesScrollAnimation
class Custom(val spec: AnimationSpec<Float>) : PagesScrollAnimation
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.parallel=true
org.gradle.caching=true
systemProp.org.gradle.internal.publish.checksums.insecure=true
kotlin.mpp.androidSourceSetLayoutVersion=2
org.jetbrains.compose.experimental.uikit.enabled=true
kotlin.mpp.applyDefaultHierarchyTemplate=false
org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.jscanvas.enabled=true

Expand Down
70 changes: 17 additions & 53 deletions sample/app-ios/app-ios/app_iosApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,40 @@ struct app_iosApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self)
var appDelegate: AppDelegate

private var rootHolder: RootHolder { appDelegate.getRootHolder() }

var body: some Scene {
WindowGroup {
RootView(rootHolder.root)
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
LifecycleRegistryExtKt.resume(rootHolder.lifecycle)
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)) { _ in
LifecycleRegistryExtKt.pause(rootHolder.lifecycle)
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in
LifecycleRegistryExtKt.stop(rootHolder.lifecycle)
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willTerminateNotification)) { _ in
LifecycleRegistryExtKt.destroy(rootHolder.lifecycle)
}
RootView(appDelegate.root)
}
}
}

class AppDelegate: NSObject, UIApplicationDelegate {
private var rootHolder: RootHolder?

private var stateKeeper = StateKeeperDispatcherKt.StateKeeperDispatcher(savedState: nil)

lazy var root: RootComponent = DefaultRootComponent(
componentContext: DefaultComponentContext(
lifecycle: ApplicationLifecycle(),
stateKeeper: stateKeeper,
instanceKeeper: nil,
backHandler: nil
),
featureInstaller: DefaultFeatureInstaller.shared,
deepLink: DefaultRootComponentDeepLinkNone.shared,
webHistoryController: nil
)

func application(_ application: UIApplication, shouldSaveSecureApplicationState coder: NSCoder) -> Bool {
let savedState = rootHolder!.stateKeeper.save()
CodingKt.encodeParcelable(coder, value: savedState, key: "savedState")
CodingKt.encodeParcelable(coder, value: stateKeeper.save(), key: "savedState")
return true
}

func application(_ application: UIApplication, shouldRestoreSecureApplicationState coder: NSCoder) -> Bool {
do {
let savedState = try CodingKt.decodeParcelable(coder, key: "savedState") as! ParcelableParcelableContainer
rootHolder = RootHolder(savedState: savedState)
stateKeeper = StateKeeperDispatcherKt.StateKeeperDispatcher(savedState: savedState)
return true
} catch {
return false
}
}

fileprivate func getRootHolder() -> RootHolder {
if (rootHolder == nil) {
rootHolder = RootHolder(savedState: nil)
}

return rootHolder!
}
}

private class RootHolder {
let lifecycle: LifecycleRegistry
let stateKeeper: StateKeeperDispatcher
let root: RootComponent

init(savedState: ParcelableParcelableContainer?) {
lifecycle = LifecycleRegistryKt.LifecycleRegistry()
stateKeeper = StateKeeperDispatcherKt.StateKeeperDispatcher(savedState: savedState)

root = DefaultRootComponent(
componentContext: DefaultComponentContext(
lifecycle: lifecycle,
stateKeeper: stateKeeper,
instanceKeeper: nil,
backHandler: nil
),
featureInstaller: DefaultFeatureInstaller.shared,
deepLink: DefaultRootComponentDeepLinkNone.shared,
webHistoryController: nil
)

LifecycleRegistryExtKt.create(lifecycle)
}
}
Loading

0 comments on commit e18a776

Please sign in to comment.