Skip to content

Commit acaa914

Browse files
dbiiDavid Bluestein II
andauthored
1419 tvOS LiveViewNative fixes (#1422)
* Updated to use hex.pm for live_view_native and live_view_native_swift_ui for the tutorial * Change Installation Guide link to Getting Started * #1419 Fixes in LiveViewNative for tvOS --------- Co-authored-by: David Bluestein II <[email protected]>
1 parent 33c62a5 commit acaa914

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

Sources/LiveViewNative/Stylesheets/AttributeReference.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public struct AttributeReference<Value: ParseableModifierValue & AttributeDecoda
8787

8888
switch body.base {
8989
case .translation:
90+
#if os(iOS) || os(macOS) || os(watchOS) || os(visionOS)
9091
guard let value = value as? DragGesture.Value,
9192
let member = body.member
9293
else { return defaultValue }
@@ -98,6 +99,9 @@ public struct AttributeReference<Value: ParseableModifierValue & AttributeDecoda
9899
default:
99100
return defaultValue
100101
}
102+
#else
103+
return defaultValue
104+
#endif
101105
case .magnification:
102106
#if os(iOS) || os(macOS)
103107
if #available(iOS 17.0, macOS 14.0, *) {

Sources/LiveViewNative/Stylesheets/ParseableTypes/AnyGesture+ParseableModifierValue.swift

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,13 @@ struct _AnyGesture: ParseableModifierValue {
208208
case .onEnded(let onEnded):
209209
return AnyGesture<Any>(gesture.onEnded({ value in
210210
Task {
211-
var eventValue: [String:Any]
211+
func sendEventValue(_ eventValue: [String:Any]) async throws {
212+
let eventValue = eventValue.merging(element.buildPhxValuePayload(), uniquingKeysWith: { $1 })
213+
try await onEnded.action(value: eventValue, in: context)
214+
}
215+
#if os(iOS) || os(macOS) || os(watchOS) || os(visionOS)
212216
if let drag = value as? DragGesture.Value {
213-
eventValue = [
217+
return try await sendEventValue([
214218
"translation": [
215219
"width": drag.translation.width,
216220
"height": drag.translation.height
@@ -235,44 +239,46 @@ struct _AnyGesture: ParseableModifierValue {
235239
"width": drag.velocity.width,
236240
"height": drag.velocity.height
237241
]
238-
]
239-
} else if let spatialTap = value as? SpatialTapGesture.Value {
240-
eventValue = [
242+
])
243+
}
244+
#endif
245+
#if os(iOS) || os(macOS) || os(watchOS) || os(visionOS)
246+
if let spatialTap = value as? SpatialTapGesture.Value {
247+
return try await sendEventValue([
241248
"location": [
242249
"x": spatialTap.location.x,
243250
"y": spatialTap.location.y
244251
]
245-
]
246-
} else {
247-
eventValue = [:]
248-
#if os(iOS) || os(macOS) || os(visionOS)
249-
if #available(iOS 17, macOS 14, *),
250-
let magnify = value as? MagnifyGesture.Value
251-
{
252-
eventValue = [
253-
"magnification": magnify.magnification,
254-
"startLocation": [
255-
"x": magnify.startLocation.x,
256-
"y": magnify.startLocation.y
257-
],
258-
"velocity": magnify.velocity
259-
]
260-
} else if #available(iOS 17, macOS 14, *),
261-
let rotate = value as? RotateGesture.Value
262-
{
263-
eventValue = [
264-
"rotation": rotate.rotation.radians,
265-
"startLocation": [
266-
"x": rotate.startLocation.x,
267-
"y": rotate.startLocation.y
268-
],
269-
"velocity": rotate.velocity
270-
]
271-
}
272-
#endif
252+
])
253+
}
254+
#endif
255+
256+
#if os(iOS) || os(macOS) || os(visionOS)
257+
if #available(iOS 17, macOS 14, *),
258+
let magnify = value as? MagnifyGesture.Value
259+
{
260+
return try await sendEventValue([
261+
"magnification": magnify.magnification,
262+
"startLocation": [
263+
"x": magnify.startLocation.x,
264+
"y": magnify.startLocation.y
265+
],
266+
"velocity": magnify.velocity
267+
])
268+
} else if #available(iOS 17, macOS 14, *),
269+
let rotate = value as? RotateGesture.Value
270+
{
271+
return try await sendEventValue([
272+
"rotation": rotate.rotation.radians,
273+
"startLocation": [
274+
"x": rotate.startLocation.x,
275+
"y": rotate.startLocation.y
276+
],
277+
"velocity": rotate.velocity
278+
])
273279
}
274-
eventValue.merge(element.buildPhxValuePayload(), uniquingKeysWith: { $1 })
275-
try await onEnded.action(value: eventValue, in: context)
280+
#endif
281+
return try await sendEventValue([:])
276282
}
277283
}).map({ $0 as Any }))
278284
case .exclusively(let exclusively):

0 commit comments

Comments
 (0)