Skip to content

Commit

Permalink
gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar Otasevic committed Sep 7, 2024
1 parent 4d8dd8e commit 9cc238a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
55 changes: 55 additions & 0 deletions apple_gesture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import requests
import json

url = 'https://developer.apple.com/tutorials/data/documentation/swiftui/gesture.json'
response = requests.get(url)
doc = response.json()
identifiers = doc['relationshipsSections'][0]['identifiers']
gestures = [x.split("/")[-1] for x in identifiers]

with open('parsed.json', 'r') as file:
structs = json.load(file)

preferedTypes = {
'View' : 'Never',
'Shape': 'Circle',
'InsettableShape': 'Circle',
'Hashable': 'Int',
'RandomAccessCollection': 'Array<Never>',
'Publisher': 'AnyPublisher<Void,Never>',
'TimelineSchedule': 'AnimationTimelineSchedule',
}

output = []
for struct in structs:
name = struct['name']

if not name in gestures:
continue

lines = struct.get('availabilities', [])
generics = struct.get('generics')
if generics is None:
t = f'typealias _{name} = SameTypeElement<{name}>'
else:
conditions = struct.get('conditions', {})
arr = [conditions.get(gen, ['Never'])[-1] for gen in generics]
arr = [preferedTypes.get(x, 'Never') for x in arr]
gen = ",".join(arr)
t = f"typealias _{name} = SameBaseElement<{name}<{gen}>>"

lines.append(t)

output.append(lines)

strings = ["\n".join(lines) for lines in output]

content = "\n\n".join(strings)

with open('gesture.swift', 'w', encoding='utf-8') as f:
f.write(content)





2 changes: 1 addition & 1 deletion apple.py → apple_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

content = "\n\n".join(strings)

with open('generics.swift', 'w', encoding='utf-8') as f:
with open('view.swift', 'w', encoding='utf-8') as f:
f.write(content)


Expand Down
63 changes: 63 additions & 0 deletions gesture.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
typealias _AnyGesture = SameBaseElement<AnyGesture<Never>>

@available(iOS 13.0, macOS 10.15, watchOS 6.0, *)
@available(tvOS, unavailable)
typealias _DragGesture = SameTypeElement<DragGesture>

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
typealias _ExclusiveGesture = SameBaseElement<ExclusiveGesture<Never,Never>>

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
typealias _GestureStateGesture = SameBaseElement<GestureStateGesture<Never,Never>>

@available(iOS 13.0, macOS 10.15, watchOS 6.0, 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>

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
typealias _SequenceGesture = SameBaseElement<SequenceGesture<Never,Never>>

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
typealias _SimultaneousGesture = SameBaseElement<SimultaneousGesture<Never,Never>>

@available(visionOS 1.0, iOS 18.0, macOS 15.0, watchOS 11.0, *)
@available(tvOS, unavailable)
typealias _SpatialEventGesture = SameTypeElement<SpatialEventGesture>

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

@available(iOS 13.0, macOS 10.15, tvOS 16.0, watchOS 6.0, *)
typealias _TapGesture = SameTypeElement<TapGesture>

@available(macOS 15.0, *)
@available(iOS, unavailable)
@available(watchOS, unavailable)
@available(tvOS, unavailable)
@available(visionOS, unavailable)
typealias _WindowDragGesture = SameTypeElement<WindowDragGesture>
File renamed without changes.

0 comments on commit 9cc238a

Please sign in to comment.