react-native-unistyles 3.0.0-alpha.23 → 3.0.0-alpha.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,14 @@
|
|
1
1
|
#if os(iOS)
|
2
2
|
|
3
3
|
import Foundation
|
4
|
+
import Combine
|
4
5
|
import NitroModules
|
5
6
|
|
6
7
|
typealias CxxListener = (Array<UnistyleDependency>) -> Void
|
7
8
|
|
8
9
|
class NativeIOSPlatform: HybridNativePlatformSpec {
|
9
10
|
var miniRuntime: UnistylesNativeMiniRuntime?
|
11
|
+
var cancellables = Set<AnyCancellable>()
|
10
12
|
|
11
13
|
var listeners: Array<CxxListener> = []
|
12
14
|
var hybridContext = margelo.nitro.HybridContext()
|
@@ -2,16 +2,18 @@ import Foundation
|
|
2
2
|
|
3
3
|
extension NativeIOSPlatform {
|
4
4
|
func setupPlatformListeners() {
|
5
|
-
NotificationCenter.default.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
NotificationCenter.default.publisher(for: NSNotification.Name("RCTWindowFrameDidChangeNotification"))
|
6
|
+
// add small delay (10ms) to make sure all values are up ot date
|
7
|
+
// we MUST call it on current thread, otherwise random crashes occurs
|
8
|
+
.delay(for: .milliseconds(10), scheduler: RunLoop.current)
|
9
|
+
.sink { [weak self] notification in
|
10
|
+
self?.onWindowChange(notification)
|
11
|
+
}
|
12
|
+
.store(in: &cancellables)
|
11
13
|
}
|
12
14
|
|
13
15
|
func removePlatformListeners() {
|
14
|
-
|
16
|
+
cancellables.removeAll()
|
15
17
|
}
|
16
18
|
|
17
19
|
func registerPlatformListener(callback: @escaping (CxxListener)) throws {
|
@@ -24,18 +26,16 @@ extension NativeIOSPlatform {
|
|
24
26
|
|
25
27
|
@objc func onWindowChange(_ notification: Notification) {
|
26
28
|
// add small delay (10ms) to make sure all values are up ot date
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
self.emitCxxEvent(dependencies: changedDependencies)
|
38
|
-
}
|
29
|
+
guard let currentMiniRuntime = self.miniRuntime else {
|
30
|
+
return
|
31
|
+
}
|
32
|
+
|
33
|
+
let newMiniRuntime = self.buildMiniRuntime()
|
34
|
+
let changedDependencies = UnistylesNativeMiniRuntime.diff(lhs: currentMiniRuntime, rhs: newMiniRuntime)
|
35
|
+
|
36
|
+
if (changedDependencies.count > 0) {
|
37
|
+
self.miniRuntime = newMiniRuntime
|
38
|
+
self.emitCxxEvent(dependencies: changedDependencies)
|
39
39
|
}
|
40
40
|
}
|
41
41
|
}
|