diff --git a/Package.swift b/Package.swift index 349eeb8..3ff955c 100644 --- a/Package.swift +++ b/Package.swift @@ -12,6 +12,7 @@ let package = Package( dependencies: [ .package(url: "https://source.skip.tools/skip.git", from: "1.2.34"), .package(url: "https://source.skip.tools/skip-foundation.git", from: "1.3.1"), + .package(url: "https://github.com/tifroz/skip-model.git", branch: "withanimation-global-scope-fix"), .package(url: "https://source.skip.tools/swift-jni.git", "0.0.0"..<"2.0.0"), .package(url: "https://source.skip.tools/skip-bridge.git", "0.0.0"..<"2.0.0"), .package(url: "https://source.skip.tools/swift-android-native.git", from: "1.4.1") @@ -21,6 +22,7 @@ let package = Package( .product(name: "SkipBridge", package: "skip-bridge"), .product(name: "SwiftJNI", package: "swift-jni"), .product(name: "SkipFoundation", package: "skip-foundation"), + .product(name: "SkipModel", package: "skip-model"), .product(name: "AndroidNative", package: "swift-android-native", condition: .when(platforms: [.android])), ], plugins: [.plugin(name: "skipstone", package: "skip")]), diff --git a/Sources/SkipAndroidBridge/Observation.swift b/Sources/SkipAndroidBridge/Observation.swift index d7314b2..f6e4d0b 100644 --- a/Sources/SkipAndroidBridge/Observation.swift +++ b/Sources/SkipAndroidBridge/Observation.swift @@ -3,6 +3,7 @@ #if SKIP_BRIDGE import SwiftJNI +import SkipModel #if canImport(FoundationEssentials) import FoundationEssentials #else @@ -67,11 +68,18 @@ private final class BridgeObservationSupport: @unchecked Sendable { public func access(_ subject: Subject, keyPath: KeyPath) { let index = Java_init(forKeyPath: keyPath) + lock.wait() + let transaction = lastMutationTransactions[index] + lock.signal() + StateTracking.recordMutationRead(transaction) Java_access(index) } public func willSet(_ subject: Subject, keyPath: KeyPath) { let index = Java_init(forKeyPath: keyPath) + lock.wait() + lastMutationTransactions[index] = StateTracking.currentMutationTransaction + lock.signal() Java_update(index) } @@ -135,6 +143,7 @@ private final class BridgeObservationSupport: @unchecked Sendable { private let lock = DispatchSemaphore(value: 1) private var indexes: [AnyKeyPath: Int] = [:] + private var lastMutationTransactions: [Int: StateMutationTransaction] = [:] private func index(forKeyPath keyPath: AnyKeyPath) -> Int { if let index = indexes[keyPath] {