Skip to content
Merged
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
5 changes: 3 additions & 2 deletions Sources/OpenSwiftUICore/Event/Gesture/AnyGesture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,17 @@ private struct AnyGestureInfo<V>: StatefulRule {
) -> Value {
let childGraph = Subgraph(graph: parentSubgraph.graph)
parentSubgraph.addChild(childGraph)
let info = attribute
return childGraph.apply {
var childInputs = inputs
childInputs.copyCaches()
childInputs.resetSeed = Attribute(AnyResetSeed<V>(
resetSeed: inputs.resetSeed,
info: attribute
info: info
))
let childOutputs = storage.makeChild(
uniqueId: uniqueId,
container: attribute,
container: info,
inputs: childInputs
)
outputs.attachIndirectOutputs(childOutputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ private struct DurationPhase<BodyValue>: ResettableGestureRule {
if let start {
elapsed = time - start
} else {
let childPhase = childPhase
if childPhase.isActive || modifier.trackFromEventStart {
start = time
elapsed = .zero
Expand Down
61 changes: 18 additions & 43 deletions Sources/OpenSwiftUICore/Event/Gesture/EventListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,12 @@ private struct EventListenerPhase<Event>: ResettableGestureRule, CustomStringCon
value = Value(phase: .possible(nil), trackingID: nil, failureReason: nil)
}

// TBA
mutating func updateValue() {
guard resetIfNeeded() else {
return
}

var matchedEventID: EventID?
var matchedEvent: Event?
var matchedEvent: (any EventType)?
var failureReason: FailureReason?

for (eventID, rawEvent) in events {
guard rawEvent.binding != nil else {
if trackingID == eventID {
Expand All @@ -114,45 +110,31 @@ private struct EventListenerPhase<Event>: ResettableGestureRule, CustomStringCon
}
continue
}

if !allowsIncompleteEventSequences {
if trackingID != eventID && rawEvent.phase != .began {
if trackingID != nil, listener.ignoresOtherEvents {
continue
if trackingID == nil || !listener.ignoresOtherEvents {
failureReason = .eventArrivedMidstream
break
}
failureReason = .eventArrivedMidstream
break
}
}

guard let event = Event(rawEvent) else {
guard Event(rawEvent) != nil else {
if trackingID != nil, listener.ignoresOtherEvents {
continue
}
failureReason = .unexpectedEvent
break
}

if let trackingID {
guard trackingID == eventID else {
if listener.ignoresOtherEvents {
continue
}
if trackingID != eventID && !listener.ignoresOtherEvents {
failureReason = .multipleMatchingEvents
break
}
} else {
trackingID = eventID
}

guard matchedEvent == nil else {
failureReason = .multipleMatchingEvents
break
}
matchedEventID = eventID
matchedEvent = event
matchedEvent = rawEvent
}

guard failureReason == nil else {
value = Value(
phase: .failed,
Expand All @@ -161,8 +143,7 @@ private struct EventListenerPhase<Event>: ResettableGestureRule, CustomStringCon
)
return
}

guard var matchedEvent, let matchedEventID else {
guard var matchedEvent else {
guard !hasValue else {
return
}
Expand All @@ -173,37 +154,31 @@ private struct EventListenerPhase<Event>: ResettableGestureRule, CustomStringCon
)
return
}

if !preconvertedEventLocations {
var events = [matchedEventID: matchedEvent]
let resolvedTransform = Graph.withoutUpdate { transform }
let resolvedPosition = Graph.withoutUpdate { position }
let convertedTransform = resolvedTransform.withPosition(resolvedPosition)
let convertedTransform = Graph.withoutUpdate { transform.withPosition(position) }
let trackingID = trackingID!
var events = [trackingID: matchedEvent]
defaultConvertEventLocations(&events) { points in
convertedTransform.convert(
ViewTransform.Conversion.globalToSpace(.local),
points: &points
)
}
matchedEvent = events[matchedEventID] ?? matchedEvent
matchedEvent = events[trackingID]!
}
guard let event = Event(matchedEvent) else {
return
}

switch matchedEvent.phase {
case .began:
value = Value(
phase: .possible(matchedEvent),
trackingID: trackingID,
failureReason: nil
)
case .active:
case .began, .active:
value = Value(
phase: .active(matchedEvent),
phase: .active(event),
trackingID: trackingID,
failureReason: nil
)
case .ended:
value = Value(
phase: .ended(matchedEvent),
phase: .ended(event),
trackingID: trackingID,
failureReason: nil
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/Event/Gesture/Map2Gesture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct Map2Gesture<InputValue, Content, OutputValue>: GestureModifier where Cont
inputs: inputs
)
let phase = Attribute(Map2Phase(
body: modifier[offset: { .of(&$0.body) }].value,
body: modifier[\.body].value,
phase1: outputs1.phase,
phase2: outputs2.phase,
resetSeed: inputs.resetSeed,
Expand Down
Loading
Loading