From 9cc238a8bc4c375c31fed7f69b7434f090bee347 Mon Sep 17 00:00:00 2001 From: Lazar Otasevic <> Date: Sat, 7 Sep 2024 18:23:00 +0400 Subject: [PATCH] gesture --- apple_gesture.py | 55 +++++++++++++++++++++++++++++++ apple.py => apple_view.py | 2 +- gesture.swift | 63 ++++++++++++++++++++++++++++++++++++ generics.swift => view.swift | 0 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 apple_gesture.py rename apple.py => apple_view.py (95%) create mode 100644 gesture.swift rename generics.swift => view.swift (100%) diff --git a/apple_gesture.py b/apple_gesture.py new file mode 100644 index 0000000..fd98908 --- /dev/null +++ b/apple_gesture.py @@ -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', + 'Publisher': 'AnyPublisher', + '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) + + + + + diff --git a/apple.py b/apple_view.py similarity index 95% rename from apple.py rename to apple_view.py index 035ef81..0033b5e 100644 --- a/apple.py +++ b/apple_view.py @@ -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) diff --git a/gesture.swift b/gesture.swift new file mode 100644 index 0000000..2d68959 --- /dev/null +++ b/gesture.swift @@ -0,0 +1,63 @@ +@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) +typealias _AnyGesture = SameBaseElement> + +@available(iOS 13.0, macOS 10.15, watchOS 6.0, *) +@available(tvOS, unavailable) +typealias _DragGesture = SameTypeElement + +@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) +typealias _ExclusiveGesture = SameBaseElement> + +@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) +typealias _GestureStateGesture = SameBaseElement> + +@available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 14.0, *) +typealias _LongPressGesture = SameTypeElement + +@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 + +@available(iOS 17.0, macOS 14.0, *) +@available(watchOS, unavailable) +@available(tvOS, unavailable) +typealias _MagnifyGesture = SameTypeElement + +@available(iOS 17.0, macOS 14.0, *) +@available(watchOS, unavailable) +@available(tvOS, unavailable) +typealias _RotateGesture = SameTypeElement + +@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 + +@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) +typealias _SequenceGesture = SameBaseElement> + +@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) +typealias _SimultaneousGesture = SameBaseElement> + +@available(visionOS 1.0, iOS 18.0, macOS 15.0, watchOS 11.0, *) +@available(tvOS, unavailable) +typealias _SpatialEventGesture = SameTypeElement + +@available(iOS 16.0, macOS 13.0, watchOS 9.0, visionOS 1.0, *) +@available(tvOS, unavailable) +typealias _SpatialTapGesture = SameTypeElement + +@available(iOS 13.0, macOS 10.15, tvOS 16.0, watchOS 6.0, *) +typealias _TapGesture = SameTypeElement + +@available(macOS 15.0, *) +@available(iOS, unavailable) +@available(watchOS, unavailable) +@available(tvOS, unavailable) +@available(visionOS, unavailable) +typealias _WindowDragGesture = SameTypeElement \ No newline at end of file diff --git a/generics.swift b/view.swift similarity index 100% rename from generics.swift rename to view.swift