Skip to content

Commit ceaf9a8

Browse files
committed
feat:NSLifecycleListener
1 parent 7e361dd commit ceaf9a8

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.multiplatform.lifecyle
2+
3+
import com.multiplatform.lifecycle.LifecycleEvent
4+
import com.multiplatform.lifecycle.LifecycleTracker
5+
import kotlinx.cinterop.BetaInteropApi
6+
import kotlinx.cinterop.ObjCAction
7+
import platform.Foundation.NSNotification
8+
import platform.darwin.NSObject
9+
10+
/**
11+
* Created By Kevin Zou On 2024/2/26
12+
*/
13+
@Suppress("unused")
14+
@OptIn(BetaInteropApi::class)
15+
class NSLifecycleListener(private val lifecycleTracker: LifecycleTracker) : NSObject() {
16+
17+
@ObjCAction
18+
fun willEnterForeground(arg: NSNotification) {
19+
lifecycleTracker.notifyListeners(LifecycleEvent.OnStartEvent)
20+
}
21+
22+
@ObjCAction
23+
fun didBecomeActive(arg: NSNotification) {
24+
lifecycleTracker.notifyListeners(LifecycleEvent.OnResumeEvent)
25+
}
26+
27+
@ObjCAction
28+
fun willResignActive(arg: NSNotification) {
29+
lifecycleTracker.notifyListeners(LifecycleEvent.OnPauseEvent)
30+
}
31+
32+
@ObjCAction
33+
fun didEnterBackground(arg: NSNotification) {
34+
lifecycleTracker.notifyListeners(LifecycleEvent.OnStopEvent)
35+
}
36+
37+
@ObjCAction
38+
fun willTerminate(arg: NSNotification) {
39+
lifecycleTracker.notifyListeners(LifecycleEvent.OnDestroyEvent)
40+
}
41+
}

0 commit comments

Comments
 (0)