Skip to content

Commit bb0ae7a

Browse files
committed
Add non-Darwin placeholder types and platform failure helper
- OGFPlaceholderTypes.swift: placeholder protocols for OGFGestureNode, OGFGestureNodeDelegate, OGFGestureNodeContainer, OGFGestureNodeCoordinator on non-Darwin platforms - OGFGestureFunctions.swift: add #else block with placeholder implementations calling _openGesturesPlatformUnimplementedFailure - Logging.swift: add _openGesturesPlatformUnimplementedFailure helper
1 parent a4bb549 commit bb0ae7a

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

Sources/OpenGestures/Extension/OGFGestureFunctions.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ public func ogfGestureComponentControllerSetNode(
3636
preconditionFailure("")
3737
}
3838

39+
#else
40+
41+
public func OGFGestureNodeDefaultValue() -> Any {
42+
()
43+
}
44+
45+
public func OGFGestureNodeCreateDefault(_ key: Int) -> any OGFGestureNode {
46+
_openGesturesPlatformUnimplementedFailure()
47+
}
48+
49+
public func OGFGestureNodeCoordinatorCreate(
50+
_ willUpdateHandler: (() -> Void)?,
51+
_ didUpdateHandler: (() -> Void)?
52+
) -> any OGFGestureNodeCoordinator {
53+
_openGesturesPlatformUnimplementedFailure()
54+
}
55+
56+
public func OGFGestureComponentControllerSetNode(
57+
_ controller: AnyObject,
58+
_ node: (any OGFGestureNode)?
59+
) {
60+
_openGesturesPlatformUnimplementedFailure()
61+
}
62+
63+
public func OGFGestureFailureTypeIsTerminated(_ type: OGFGestureFailureType) -> Bool {
64+
ogfGestureFailureTypeIsTerminated(type: type)
65+
}
66+
3967
#endif
4068

4169
@_cdecl("OGFGestureFailureTypeIsTerminated")
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// OGFPlaceholderTypes.swift
3+
// OpenGestures
4+
//
5+
// Placeholder protocol definitions for non-Darwin platforms where
6+
// the ObjC protocols from COpenGestures are not available.
7+
8+
#if !canImport(ObjectiveC)
9+
10+
public protocol OGFGestureNode: AnyObject {
11+
// weak in ObjC
12+
// Swift protocols can't express weak without @objc,
13+
/*weak*/ var delegate: (any OGFGestureNodeDelegate)? { get set }
14+
/*weak*/ var container: (any OGFGestureNodeContainer)? { get set }
15+
var coordinator: (any OGFGestureNodeCoordinator)? { get set }
16+
var phase: OGFGesturePhase { get }
17+
var isBlocked: Bool { get }
18+
var identifier: String { get }
19+
var tag: String? { get set }
20+
var isDisabled: Bool { get set }
21+
var disallowExclusionWithUnresolvedFailureRequirements: Bool { get set }
22+
var platformKey: Int { get }
23+
var failureReason: (any Error)? { get }
24+
25+
func abort() throws
26+
func addRelation(type: OGFGestureRelationType, role: OGFGestureRelationRole, relatedNode: any OGFGestureNode)
27+
func ensureUpdated() throws
28+
func fail(reason: Any?, error: inout (any Error)?) throws
29+
func removeRelation(type: OGFGestureRelationType, role: OGFGestureRelationRole, relatedNode: any OGFGestureNode)
30+
func setTracking(_ tracking: Bool, eventsWithIdentifiers identifiers: [Any])
31+
func update(value: Any?, isFinal: Bool) throws
32+
}
33+
34+
public protocol OGFGestureNodeDelegate: AnyObject {
35+
func gestureNode(_ node: any OGFGestureNode, didUpdatePhase phase: OGFGesturePhase)
36+
func gestureNode(_ node: any OGFGestureNode, roleForRelationType type: OGFGestureRelationType, relatedNode: any OGFGestureNode) -> Any?
37+
func gestureNodeShouldActivate(_ node: any OGFGestureNode) -> Bool
38+
func gestureNodeWillUnblock(_ node: any OGFGestureNode)
39+
40+
// optional in ObjC
41+
// Swift protocols can't express optional without @objc,
42+
// so we provide default empty implementations below.
43+
/*optional*/ func gestureNode(_ node: any OGFGestureNode, didEnqueuePhase phase: OGFGesturePhase)
44+
/*optional*/ func gestureNodeWillAbort(_ node: any OGFGestureNode)
45+
}
46+
47+
extension OGFGestureNodeDelegate {
48+
public func gestureNode(_ node: any OGFGestureNode, didEnqueuePhase phase: OGFGesturePhase) {}
49+
public func gestureNodeWillAbort(_ node: any OGFGestureNode) {}
50+
}
51+
52+
public protocol OGFGestureNodeContainer: AnyObject {
53+
func indexOfGestureNode(_ node: any OGFGestureNode) -> Int
54+
func isDeeperThanContainer(_ container: any OGFGestureNodeContainer, referenceNode: any OGFGestureNode) -> Bool
55+
func isDescendantOfContainer(_ container: any OGFGestureNodeContainer, referenceNode: any OGFGestureNode) -> Bool
56+
}
57+
58+
public protocol OGFGestureNodeCoordinator: AnyObject {
59+
var nodes: [any OGFGestureNode] { get }
60+
var willUpdateHandler: (() -> Void)? { get set }
61+
var willProcessUpdateQueueHandler: (() -> Void)? { get set }
62+
var didUpdateHandler: (() -> Void)? { get set }
63+
64+
func enqueueUpdatesForNodes(_ nodes: [any OGFGestureNode], inBlock block: ([any OGFGestureNode]) -> Void, reason: String)
65+
func hasUnresolvedFailureDependenciesForNode(_ node: any OGFGestureNode) -> Bool
66+
func updateWithNodes(_ nodes: [any OGFGestureNode], reason: String, updateHandler: ([any OGFGestureNode]) -> Void)
67+
func failureDependentsForNode(_ node: any OGFGestureNode) -> [any OGFGestureNode]
68+
func processUpdatesWithReason(_ reason: String)
69+
}
70+
71+
#endif

Sources/OpenGestures/Logging.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ package func preconditionFailure(_ message: @autoclosure () -> String, file: Sta
1414
package func preconditionFailure(_ message: @autoclosure () -> String) -> Never {
1515
preconditionFailure(message(), file: #fileID, line: #line)
1616
}
17+
18+
// MARK: - Platform Unimplemented
19+
20+
@_transparent
21+
package func _openGesturesPlatformUnimplementedFailure(
22+
_ function: String = #function,
23+
file: StaticString = #fileID,
24+
line: UInt = #line
25+
) -> Never {
26+
preconditionFailure("Unimplemented for this platform yet", file: file, line: line)
27+
}

0 commit comments

Comments
 (0)