Skip to content

Commit

Permalink
sredio aval
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar Otasevic committed Sep 7, 2024
1 parent bf33ec4 commit 804d7cc
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 586 deletions.
56 changes: 56 additions & 0 deletions Sources/ViewInspection/Elements/ReflectionElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,59 @@ protocol ReflectionElement {
init(node: ReflectionNode)
static func isValid(_ node: ReflectionNode) -> Bool
}

protocol TypeDerivedElement: ReflectionElement {
associatedtype RelatedType
}

extension TypeDerivedElement {
static var typeInfo: TypeInfo { TypeInfo(type: RelatedType.self) }
}

protocol CastableTypeDerivedElement: TypeDerivedElement {
var castValue: RelatedType { get }
}

extension CastableTypeDerivedElement {
var castValue: RelatedType { CastingUtils.memoryCast(node.object) }
}

struct SameBaseElement<T>: TypeDerivedElement {
let node: ReflectionNode
typealias RelatedType = T
static func isValid(_ node: ReflectionNode) -> Bool { node.typeInfo.baseTypename == typeInfo.baseTypename }
}

protocol ModifierDerivedElement: ReflectionElement {
static func makeModifiedContent() -> Any
}

extension ModifierDerivedElement {
static func isValid(_ node: ReflectionNode) -> Bool {
let modChild = ReflectionNode(object: makeModifiedContent()).children[1]
return node.typeInfo.typename == modChild.typeInfo.typename
}
}

struct SameTypeElement<T>: CastableTypeDerivedElement {
let node: ReflectionNode
typealias RelatedType = T
static func isValid(_ node: ReflectionNode) -> Bool { node.object is T }
}

struct ClosureElement<T>: CastableTypeDerivedElement {
let node: ReflectionNode
typealias RelatedType = T
static func isValid(_ node: ReflectionNode) -> Bool { node.typeInfo.typename.hasSuffix(typeInfo.typename) }
}

struct SomeClosureElement: ReflectionElement {
let node: ReflectionNode
static func isValid(_ node: ReflectionNode) -> Bool {
node.typeInfo.typename.contains("->")
}

func cast<T>(_ t: T.Type = T.self) -> T {
CastingUtils.memoryCast(node.object, T.self)
}
}
67 changes: 67 additions & 0 deletions Sources/ViewInspection/Elements/TestElement.Gesture.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import SwiftUI

extension TestElement {
enum Gesture {
typealias _AnyGesture = SameBaseElement<AnyGesture<Never>>

@available(tvOS, unavailable)
typealias _DragGesture = SameTypeElement<DragGesture>

typealias _ExclusiveGesture = SameBaseElement<ExclusiveGesture<Never, Never>>

typealias _GestureStateGesture = SameBaseElement<GestureStateGesture<Never, Never>>

@available(tvOS 14.0, *)
typealias _LongPressGesture = SameTypeElement<LongPressGesture>

@available(iOS, introduced: 13.0, deprecated: 100000.0, renamed: "MagnifyGesture")
@available(macOS, introduced: 10.15, deprecated: 100000.0, renamed: "MagnifyGesture")
@available(watchOS, unavailable)
@available(tvOS, unavailable)
@available(visionOS, introduced: 1.0, deprecated: 100000.0, renamed: "MagnifyGesture")
typealias _MagnificationGesture = SameTypeElement<MagnificationGesture>

@available(iOS 17.0, macOS 14.0, *)
@available(watchOS, unavailable)
@available(tvOS, unavailable)
typealias _MagnifyGesture = SameTypeElement<MagnifyGesture>

@available(iOS 17.0, macOS 14.0, *)
@available(watchOS, unavailable)
@available(tvOS, unavailable)
typealias _RotateGesture = SameTypeElement<RotateGesture>

@available(iOS, introduced: 13.0, deprecated: 100000.0, renamed: "RotateGesture")
@available(macOS, introduced: 10.15, deprecated: 100000.0, renamed: "RotateGesture")
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, introduced: 1.0, deprecated: 100000.0, renamed: "RotateGesture")
typealias _RotationGesture = SameTypeElement<RotationGesture>

typealias _SequenceGesture = SameBaseElement<SequenceGesture<Never, Never>>

typealias _SimultaneousGesture = SameBaseElement<SimultaneousGesture<Never, Never>>

#if swift(>=6.0)
@available(iOS 18.0, macOS 15.0, watchOS 11.0, *)
@available(tvOS, unavailable)
typealias _SpatialEventGesture = SameTypeElement<SpatialEventGesture>
#endif

@available(iOS 16.0, macOS 13.0, watchOS 9.0, *)
@available(tvOS, unavailable)
typealias _SpatialTapGesture = SameTypeElement<SpatialTapGesture>

@available(tvOS 16.0, *)
typealias _TapGesture = SameTypeElement<TapGesture>

#if swift(>=6.0)
@available(macOS 15.0, *)
@available(iOS, unavailable)
@available(watchOS, unavailable)
@available(tvOS, unavailable)
@available(visionOS, unavailable)
typealias _WindowDragGesture = SameTypeElement<WindowDragGesture>
#endif
}
}
Loading

0 comments on commit 804d7cc

Please sign in to comment.