Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")]),

Expand Down
9 changes: 9 additions & 0 deletions Sources/SkipAndroidBridge/Observation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#if SKIP_BRIDGE

import SwiftJNI
import SkipModel
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
Expand Down Expand Up @@ -67,11 +68,18 @@ private final class BridgeObservationSupport: @unchecked Sendable {

public func access<Subject, Member>(_ subject: Subject, keyPath: KeyPath<Subject, Member>) {
let index = Java_init(forKeyPath: keyPath)
lock.wait()
let transaction = lastMutationTransactions[index]
lock.signal()
StateTracking.recordMutationRead(transaction)
Java_access(index)
}

public func willSet<Subject, Member>(_ subject: Subject, keyPath: KeyPath<Subject, Member>) {
let index = Java_init(forKeyPath: keyPath)
lock.wait()
lastMutationTransactions[index] = StateTracking.currentMutationTransaction
lock.signal()
Java_update(index)
}

Expand Down Expand Up @@ -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] {
Expand Down