Skip to content

Commit e67721e

Browse files
committed
feat:Add documentation
1 parent f151af8 commit e67721e

9 files changed

Lines changed: 24 additions & 41 deletions

File tree

lifecycletracker/src/androidMain/kotlin/com/multiplatform/lifecyle/AndroidLifecycleEventObserver.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import com.multiplatform.lifecycle.LifecycleEvent
66
import com.multiplatform.lifecycle.LifecycleTracker
77

88
/**
9-
* Created By Kevin Zou On 2024/2/22
9+
* An observer for Android lifecycle events.
1010
*/
11-
class AndroidLifecycleEventObserver(private val lifecycleTracker: LifecycleTracker) : DefaultLifecycleObserver {
11+
class AndroidLifecycleEventObserver(private val lifecycleTracker: LifecycleTracker) :
12+
DefaultLifecycleObserver {
1213
override fun onCreate(owner: LifecycleOwner) {
1314
super.onCreate(owner)
1415
lifecycleTracker.handleLifecycleEvent(LifecycleEvent.OnCreateEvent)
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.multiplatform.lifecycle
22

33
/**
4-
* Created By Kevin Zou On 2024/2/26
4+
* A class that has an Android-like lifecycle.
55
*/
66
abstract class Lifecycle {
77
/**
@@ -14,28 +14,18 @@ abstract class Lifecycle {
1414
*
1515
* @param observer The observer to notify.
1616
*/
17-
abstract fun addObserver(observer: LifecycleObserver)
17+
abstract fun addObserver(observer: LifecycleObserver)
1818

1919
/**
2020
* Removes the given observer from the observers list.
21-
*
22-
* If this method is called while a state change is being dispatched,
23-
*
24-
* * If the given observer has not yet received that event, it will not receive it.
25-
* * If the given observer has more than 1 method that observes the currently dispatched
26-
* event and at least one of them received the event, all of them will receive the event and
27-
* the removal will happen afterwards.
28-
*
29-
*
3021
* @param observer The observer to be removed.
3122
*/
32-
abstract fun removeObserver(observer: LifecycleObserver)
23+
abstract fun removeObserver(observer: LifecycleObserver)
3324

3425
/**
3526
* Returns the current state of the Lifecycle.
3627
*
3728
* @return The current state of the Lifecycle.
3829
*/
39-
abstract val currentState: State
40-
41-
}
30+
abstract val currentState: State
31+
}

lifecycletracker/src/commonMain/kotlin/com.multiplatform.lifecycle/LifecycleEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.multiplatform.lifecycle
22

33
/**
4-
* Created By Kevin Zou On 2024/2/22
4+
* Lifecycle events. These events can be used by developers to listen to the lifecycle of the application.
55
*/
66
sealed class LifecycleEvent {
77
data object OnCreateEvent : LifecycleEvent()

lifecycletracker/src/commonMain/kotlin/com.multiplatform.lifecycle/LifecycleObserver.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.multiplatform.lifecycle
22

33
/**
4-
* Created By Kevin Zou On 2024/2/22
4+
* A lifecycle tracker that can be used to track the lifecycle of a component.
55
*/
66
interface LifecycleObserver {
77
fun onEvent(event: LifecycleEvent) {

lifecycletracker/src/commonMain/kotlin/com.multiplatform.lifecycle/LifecycleState.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.multiplatform.lifecycle
22

3-
/**
4-
* Created By Kevin Zou On 2024/2/26
5-
*/
6-
73
/**
84
* Lifecycle states. You can consider the states as the nodes in a graph and
95
* [LifecycleEvent]s as the edges between these nodes.
@@ -59,7 +55,9 @@ enum class State {
5955
* Resumed state for a LifecycleOwner. For an [android.app.Activity], this state
6056
* is reached after [onResume][android.app.Activity.onResume] is called.
6157
*/
62-
RESUMED;
58+
RESUMED,
59+
60+
;
6361

6462
/**
6563
* Compares if this State is greater or equal to the given `state`.
@@ -70,4 +68,4 @@ enum class State {
7068
fun isAtLeast(state: State): Boolean {
7169
return compareTo(state) >= 0
7270
}
73-
}
71+
}

lifecycletracker/src/commonMain/kotlin/com.multiplatform.lifecycle/LifecycleTracker.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.multiplatform.lifecycle
22

33
/**
4-
* Created By Kevin Zou On 2024/2/22
4+
* A lifecycle tracker that can be used to track the lifecycle of the application.
55
*/
6-
open class LifecycleTracker: Lifecycle() {
6+
open class LifecycleTracker : Lifecycle() {
77
/**
88
* Current state
99
*/
@@ -34,11 +34,7 @@ open class LifecycleTracker: Lifecycle() {
3434

3535
override var currentState: State
3636
get() = state
37-
/**
38-
* Moves the Lifecycle to the given state and dispatches necessary events to the observers.
39-
*
40-
* @param state new state
41-
*/
37+
4238
set(state) {
4339
moveToState(state)
4440
}

lifecycletracker/src/commonMain/kotlin/com.multiplatform.lifecycle/LifecyleCompositionLocals.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ package com.multiplatform.lifecycle
22

33
import androidx.compose.runtime.staticCompositionLocalOf
44

5-
/**
6-
* Created By Kevin Zou On 2024/2/27
7-
*/
85
/**
96
* The CompositionLocal containing the current [LifecycleTracker].
107
*/
11-
val LocalLifecycleTracker = staticCompositionLocalOf<LifecycleTracker> {
12-
noLocalProvidedFor("LocalLifecycleTracker")
13-
}
8+
val LocalLifecycleTracker =
9+
staticCompositionLocalOf<LifecycleTracker> {
10+
noLocalProvidedFor("LocalLifecycleTracker")
11+
}
1412

1513
private fun noLocalProvidedFor(name: String): Nothing {
1614
error("CompositionLocal $name not present")
17-
}
15+
}

lifecycletracker/src/iosMain/kotlin/com.multiplatform.lifecyle/LifecycleComposeUIVCDelegate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import platform.UIKit.UIApplicationWillResignActiveNotification
1414
import platform.UIKit.UIApplicationWillTerminateNotification
1515

1616
/**
17-
* Created By Kevin Zou On 2024/2/22
17+
* A delegate for handling iOS lifecycle events in a Compose UI View Controller.
1818
*/
1919
class LifecycleComposeUIVCDelegate(private val lifecycleTracker: LifecycleTracker) :
2020
ComposeUIViewControllerDelegate {

lifecycletracker/src/iosMain/kotlin/com.multiplatform.lifecyle/NSLifecycleListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import platform.Foundation.NSNotification
88
import platform.darwin.NSObject
99

1010
/**
11-
* Created By Kevin Zou On 2024/2/26
11+
* A listener for iOS lifecycle events.
1212
*/
1313
@Suppress("unused")
1414
@OptIn(BetaInteropApi::class)

0 commit comments

Comments
 (0)