Skip to content

Commit

Permalink
Add HoverEffect options to HoverEffectComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
carson-katri committed Jul 25, 2024
1 parent cc5727e commit 846600c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// HoverEffectComponent.swift
//
//
// Created by Carson Katri on 6/12/24.
//

import LiveViewNative
import RealityKit
import SwiftUI

extension HoverEffectComponent {
init(from element: ElementNode, in context: ComponentContentBuilder<some ComponentRegistry>.Context<some RootRegistry>) throws {
if #available(visionOS 2, *) {
switch element.attributeValue(for: "hoverEffect") {
case "spotlight":
self.init(
.spotlight(.init(
color: (try? element.attributeValue(Color.self, for: "color")).flatMap(UIColor.init),
strength: (try? element.attributeValue(Float.self, for: "strength")) ?? 1
))
)
case "highlight":
self.init(
.highlight(.init(
color: (try? element.attributeValue(Color.self, for: "color")).flatMap(UIColor.init),
strength: (try? element.attributeValue(Float.self, for: "strength")) ?? 1
))
)
default:
self.init()
}
} else {
self.init()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct ComponentContentBuilder<Components: ComponentRegistry>: ComponentRegistry
case .collisionComponent:
return [try CollisionComponent(from: element, in: context)]
case .hoverEffectComponent:
return [HoverEffectComponent()]
return [try HoverEffectComponent(from: element, in: context)]
}
case .custom:
return try Self.build([element.node], with: Components.self, in: context)
Expand Down

0 comments on commit 846600c

Please sign in to comment.