Skip to content

Commit e159cc3

Browse files
authored
Add AttributeReference to missing areas (#1181)
* Add AttributeReference to missing areas * Extend list to more SwiftUI types * Cleanup imports
1 parent 4d01691 commit e159cc3

File tree

10 files changed

+674
-661
lines changed

10 files changed

+674
-661
lines changed

Sources/LiveViewNative/ModifierStack.swift

Lines changed: 0 additions & 33 deletions
This file was deleted.

Sources/LiveViewNative/Stylesheets/Modifiers/Overrides/FocusScopeModifier.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,24 @@ import SwiftUI
99
import LiveViewNativeStylesheet
1010

1111
@ParseableExpression
12-
struct _FocusScopeModifier: ViewModifier {
13-
static let name = "focusScope"
14-
15-
@Environment(\.namespaces) private var namespaces
12+
struct _FocusScopeModifier<R: RootRegistry>: ViewModifier {
13+
static var name: String { "focusScope" }
14+
15+
let namespace: AttributeReference<String>
1616

17-
let namespace: String
17+
@ObservedElement private var element
18+
@LiveContext<R> private var context
19+
20+
@Environment(\.namespaces) private var namespaces
1821

1922
@available(watchOS 7.0,macOS 12.0,tvOS 14.0, *)
20-
init(_ namespace: String) {
23+
init(_ namespace: AttributeReference<String>) {
2124
self.namespace = namespace
2225
}
2326

2427
func body(content: Content) -> some View {
2528
#if os(watchOS) || os(macOS) || os(tvOS)
26-
content.focusScope(namespaces[namespace]!)
29+
content.focusScope(namespaces[namespace.resolve(on: element, in: context)]!)
2730
#else
2831
content
2932
#endif

Sources/LiveViewNative/Stylesheets/Modifiers/Overrides/PrefersDefaultFocusModifier.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,25 @@ struct _PrefersDefaultFocusModifier<R: RootRegistry>: ViewModifier {
1313
static var name: String { "prefersDefaultFocus" }
1414

1515
let prefersDefaultFocus: AttributeReference<Bool>
16-
let namespace: String
16+
let namespace: AttributeReference<String>
1717

1818
@ObservedElement private var element
1919
@LiveContext<R> private var context
2020
@Environment(\.namespaces) private var namespaces
2121

2222
@available(tvOS 14.0,macOS 12.0,watchOS 7.0, *)
23-
init(_ prefersDefaultFocus: AttributeReference<Swift.Bool>, in namespace: String) {
23+
init(_ prefersDefaultFocus: AttributeReference<Bool>, in namespace: AttributeReference<String>) {
2424
self.prefersDefaultFocus = prefersDefaultFocus
2525
self.namespace = namespace
2626
}
2727

2828
func body(content: Content) -> some View {
2929
#if os(tvOS) || os(macOS) || os(watchOS)
3030
content
31-
.prefersDefaultFocus(prefersDefaultFocus.resolve(on: element, in: context), in: namespaces[namespace]!)
31+
.prefersDefaultFocus(
32+
prefersDefaultFocus.resolve(on: element, in: context),
33+
in: namespaces[namespace.resolve(on: element, in: context)]!
34+
)
3235
#else
3336
content
3437
#endif

Sources/LiveViewNative/Stylesheets/Modifiers/Overrides/Rotation3DEffectModifier.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@ import LiveViewNativeStylesheet
1111
// manual implementation
1212
// `axis` is a tuple type, which cannot conform to `ParseableModifierValue`.
1313
@ParseableExpression
14-
struct _Rotation3DEffectModifier: ViewModifier {
15-
static let name = "rotation3DEffect"
14+
struct _Rotation3DEffectModifier<R: RootRegistry>: ViewModifier {
15+
static var name: String { "rotation3DEffect" }
1616

1717
let angle: Angle
1818
let axis: _3DAxis
1919
let anchor: UnitPoint
20-
let anchorZ: CGFloat
21-
let perspective: CGFloat
20+
let anchorZ: AttributeReference<CGFloat>
21+
let perspective: AttributeReference<CGFloat>
2222

23-
init(_ angle: Angle, axis: _3DAxis, anchor: UnitPoint = .center, anchorZ: CGFloat = 0, perspective: CGFloat = 1) {
23+
@ObservedElement private var element
24+
@LiveContext<R> private var context
25+
26+
init(
27+
_ angle: Angle,
28+
axis: _3DAxis,
29+
anchor: UnitPoint = .center,
30+
anchorZ: AttributeReference<CGFloat> = .init(storage: .constant(0)),
31+
perspective: AttributeReference<CGFloat> = .init(storage: .constant(1))
32+
) {
2433
self.angle = angle
2534
self.axis = axis
2635
self.anchor = anchor
@@ -33,8 +42,8 @@ struct _Rotation3DEffectModifier: ViewModifier {
3342
angle,
3443
axis: (x: axis.x, y: axis.y, z: axis.z),
3544
anchor: anchor,
36-
anchorZ: anchorZ,
37-
perspective: perspective
45+
anchorZ: anchorZ.resolve(on: element, in: context),
46+
perspective: perspective.resolve(on: element, in: context)
3847
)
3948
}
4049

Sources/LiveViewNative/Stylesheets/Modifiers/Overrides/SearchCompletionModifier.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,34 @@ import LiveViewNativeStylesheet
1111
// manual implementation
1212
// The `token` method requires a type conforming to `Identifiable`, which becomes ambiguous with `String`.
1313
@ParseableExpression
14-
struct _SearchCompletionModifier: ViewModifier {
15-
static let name = "searchCompletion"
14+
struct _SearchCompletionModifier<R: RootRegistry>: ViewModifier {
15+
static var name: String { "searchCompletion" }
1616

1717
enum Completion {
18-
case completion(String)
18+
case completion(AttributeReference<String>)
1919
#if os(iOS) || os(macOS) || os(visionOS)
2020
case token(Token)
2121
#endif
2222
}
2323
let completion: Completion
2424

25+
@ObservedElement private var element
26+
@LiveContext<R> private var context
27+
2528
#if os(iOS) || os(macOS) || os(visionOS)
2629
init(_ token: AtomString) {
2730
self.completion = .token(.init(id: token.value))
2831
}
2932
#endif
3033

31-
init(_ completion: String) {
34+
init(_ completion: AttributeReference<String>) {
3235
self.completion = .completion(completion)
3336
}
3437

3538
func body(content: Content) -> some View {
3639
switch completion {
3740
case .completion(let string):
38-
content.searchCompletion(string)
41+
content.searchCompletion(string.resolve(on: element, in: context))
3942
#if os(iOS) || os(macOS) || os(visionOS)
4043
case .token(let token):
4144
content.searchCompletion(token)

Sources/LiveViewNative/Stylesheets/Modifiers/Shapes/StrokeModifier.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,24 @@ import SwiftUI
99
import LiveViewNativeStylesheet
1010

1111
@ParseableExpression
12-
struct _StrokeModifier: ShapeFinalizerModifier {
13-
static let name = "stroke"
12+
struct _StrokeModifier<R: RootRegistry>: ShapeFinalizerModifier {
13+
static var name: String { "stroke" }
1414

1515
enum Storage {
16-
case _0(content: AnyShapeStyle, style: StrokeStyle, antialiased: Bool)
17-
case _1(content: AnyShapeStyle, lineWidth: CGFloat, antialiased: Bool)
16+
case _0(content: AnyShapeStyle, style: StrokeStyle, antialiased: AttributeReference<Bool>)
17+
case _1(content: AnyShapeStyle, lineWidth: AttributeReference<CGFloat>, antialiased: AttributeReference<Bool>)
1818
}
1919

2020
let storage: Storage
2121

22-
init(_ content: AnyShapeStyle, style: StrokeStyle, antialiased: Bool = true) {
22+
@ObservedElement private var element
23+
@LiveContext<R> private var context
24+
25+
init(_ content: AnyShapeStyle, style: StrokeStyle, antialiased: AttributeReference<Bool> = .init(storage: .constant(true))) {
2326
self.storage = ._0(content: content, style: style, antialiased: antialiased)
2427
}
2528

26-
init(_ content: AnyShapeStyle, lineWidth: CGFloat = 1, antialiased: Bool = true) {
29+
init(_ content: AnyShapeStyle, lineWidth: AttributeReference<CGFloat> = .init(storage: .constant(1)), antialiased: AttributeReference<Bool> = .init(storage: .constant(true))) {
2730
self.storage = ._1(content: content, lineWidth: lineWidth, antialiased: antialiased)
2831
}
2932

@@ -32,15 +35,15 @@ struct _StrokeModifier: ShapeFinalizerModifier {
3235
switch storage {
3336
case ._0(let content, let style, let antialiased):
3437
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) {
35-
shape.stroke(content, style: style, antialiased: antialiased)
38+
shape.stroke(content, style: style, antialiased: antialiased.resolve(on: element, in: context))
3639
} else {
3740
shape.stroke(content, style: style)
3841
}
3942
case ._1(let content, let lineWidth, let antialiased):
4043
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) {
41-
shape.stroke(content, lineWidth: lineWidth, antialiased: antialiased)
44+
shape.stroke(content, lineWidth: lineWidth.resolve(on: element, in: context), antialiased: antialiased.resolve(on: element, in: context))
4245
} else {
43-
shape.stroke(content, lineWidth: lineWidth)
46+
shape.stroke(content, lineWidth: lineWidth.resolve(on: element, in: context))
4447
}
4548
}
4649
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Angle.swift
3+
//
4+
//
5+
// Created by Carson Katri on 12/14/23.
6+
//
7+
8+
import SwiftUI
9+
import LiveViewNativeCore
10+
11+
extension Angle: AttributeDecodable {
12+
public init(from attribute: LiveViewNativeCore.Attribute?) throws {
13+
self.init(degrees: try Double.init(from: attribute))
14+
}
15+
}

0 commit comments

Comments
 (0)