Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -669,21 +669,20 @@ private struct LeafLayoutEnvironment: StatefulRule {

func updateValue() {
let (env, envChanged) = $environment.changedValue()
let shouldReset: Bool
let changed: Bool
if !hasValue {
shouldReset = true
changed = true
} else if envChanged, tracker.hasDifferentUsedValues(env.plist) {
shouldReset = true
changed = true
} else {
shouldReset = false
}
if shouldReset {
tracker.reset()
value = EnvironmentValues(
environment.plist,
tracker: tracker
)
changed = false
}
guard changed else { return }
tracker.reset()
value = EnvironmentValues(
environment.plist,
tracker: tracker
)
}
}

Expand Down
49 changes: 49 additions & 0 deletions Sources/OpenSwiftUICore/Render/SymbolEffect.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SymbolEffect.swift
// OpenSwiftUICore
//
// Status: Empty

import OpenAttributeGraphShims

package struct _SymbolEffect: Equatable {

}

extension _SymbolEffect {
package struct Identified: Equatable {

}

package struct Phase: Equatable {
package init() {
// TODO
}
}
}

extension EnvironmentValues {
package var symbolEffects: [_SymbolEffect.Identified] {
get { _openSwiftUIUnimplementedFailure() }
set { _openSwiftUIUnimplementedFailure() }
}

package mutating func appendSymbolEffect(
_ effect: _SymbolEffect,
for identifier: Int
) {
_openSwiftUIUnimplementedFailure()
}
}

extension GraphicsImage {
mutating func updateSymbolEffects(
_ phase: inout _SymbolEffect.Phase,
environment: EnvironmentValues,
transaction: Attribute<Transaction>,
animationsDisabled: Bool
) -> ORBSymbolAnimator? {
_openSwiftUIUnimplementedWarning()
return nil
}
}
12 changes: 12 additions & 0 deletions Sources/OpenSwiftUICore/Shape/ShapeStyle/ForegroundStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Status: Complete
// ID: BEFE9363F68E039B4AB6422B8AA4535A (SwiftUICore)

package import OpenAttributeGraphShims

// MARK: - ForegroundStyleKey

private struct ForegroundStyleKey: EnvironmentKey {
Expand Down Expand Up @@ -40,6 +42,16 @@ extension EnvironmentValues {
}
}

extension CachedEnvironment.ID {
package static let foregroundStyle: CachedEnvironment.ID = .init()
}

extension _ViewInputs {
package var foregroundStyle: Attribute<AnyShapeStyle?> {
mapEnvironment(id: .foregroundStyle) { $0.foregroundStyle }
}
}

@available(OpenSwiftUI_v1_0, *)
extension ShapeStyle where Self == ForegroundStyle {
/// The foreground style in the current context.
Expand Down
12 changes: 12 additions & 0 deletions Sources/OpenSwiftUICore/Shape/Tint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Status: WIP
// ID: EB037BD7690CB8A700384AACA7B075E4 (SwiftUICore)

package import OpenAttributeGraphShims

// MARK: - View + tint ShapeStyle

@available(OpenSwiftUI_v4_0, *)
Expand Down Expand Up @@ -174,4 +176,14 @@ extension EnvironmentValues {
}
}

extension CachedEnvironment.ID {
package static let tintColor: CachedEnvironment.ID = .init()
}

extension _ViewInputs {
package var tintColor: Attribute<Color?> {
mapEnvironment(id: .tintColor) { $0.tintColor }
}
}

// MARK: - TintShapeStyle [TODO]
5 changes: 5 additions & 0 deletions Sources/OpenSwiftUICore/View/Image/GraphicsImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ package struct ResolvedVectorGlyph: Equatable {
package var flipsRightToLeft: Bool {
animator.flipsRightToLeft
}

package func isClear(styles: ShapeStyle.Pack) -> Bool {
_openSwiftUIUnimplementedWarning()
return false
}
}

extension GraphicsImage {
Expand Down
179 changes: 175 additions & 4 deletions Sources/OpenSwiftUICore/View/Image/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// OpenSwiftUICore
//
// Audited for 6.5.4
// Status: Blocked by Image + View
// Status: Complete
// ID: BE2D783904D422377BBEBAC3C942583C (SwiftUICore)

package import OpenAttributeGraphShims
Expand Down Expand Up @@ -162,7 +162,7 @@ package protocol ImageProvider: Equatable {
func resolveNamedImage(in context: ImageResolutionContext) -> Image.NamedResolved?
}

// MARK: - Image + View [WIP]
// MARK: - Image + View

package protocol ImageStyleProtocol {
static func _makeImageView(view: _GraphValue<Image>, inputs: _ViewInputs) -> _ViewOutputs
Expand All @@ -174,8 +174,179 @@ extension Image: View, UnaryView, PrimitiveView {
package static let defaultValue: Stack<any ImageStyleProtocol.Type> = .empty
}

nonisolated public static func _makeView(view: _GraphValue<Image>, inputs: _ViewInputs) -> _ViewOutputs {
_openSwiftUIUnimplementedFailure()
nonisolated public static func _makeView(
view: _GraphValue<Self>,
inputs: _ViewInputs
) -> _ViewOutputs {
var newInputs = inputs
guard let style = newInputs.popLast(Style.self) else {
let flags = inputs.archivedView.flags
var options: ImageResolutionContext.Options = []
if flags.contains(.isArchived) {
options.formUnion([.isArchived, .preservesVectors])
if flags.contains(.assetCatalogRefences) {
options.formUnion(.useCatalogReferences)
}
}
if inputs.base.animationsDisabled {
options.formUnion(.animationsDisabled)
}
if newInputs.usingGraphicsRenderer, !flags.contains(.isArchived) {
options.formUnion(.preservesVectors)
}
var outputs = _ViewOutputs()
makeImageViewChild(
newInputs.imageAccessibilityProvider,
image: view.value,
options: options,
inputs: inputs,
outputs: &outputs
)
if let representation = inputs.requestedNamedImageRepresentation,
representation.shouldMakeRepresentation(inputs: inputs) {
let context = Attribute(
MakeRepresentableContext(
image: view.value,
environment: inputs.environment
)
)
representation.makeRepresentation(
inputs: inputs,
context: context,
outputs: &outputs
)
}
return outputs
}
return style._makeImageView(view: view, inputs: newInputs)
}

nonisolated private static func makeImageViewChild<P>(
_ type: P.Type,
image: Attribute<Image>,
options: ImageResolutionContext.Options,
inputs: _ViewInputs,
outputs: inout _ViewOutputs
) where P: ImageAccessibilityProvider {
let child = Attribute(
ImageViewChild<P>(
view: image,
environment: inputs.environment,
transaction: inputs.transaction,
position: inputs.position,
size: inputs.size,
transform: inputs.transform,
options: options,
parentID: inputs.scrapeableParentID,
symbolAnimator: nil,
symbolEffects: .init()
)
)
child.flags = [
.transactional,
inputs.isScrapeable ? .scrapeable : []
]
outputs = P.Body.makeDebuggableView(view: .init(child), inputs: inputs)
}

private struct MakeRepresentableContext: Rule, AsyncAttribute {
@Attribute var image: Image
@Attribute var environment: EnvironmentValues

var value: PlatformNamedImageRepresentableContext {
PlatformNamedImageRepresentableContext(
image: image,
environment: environment
)
}
}

private struct ImageViewChild<P>: StatefulRule, AsyncAttribute, ScrapeableAttribute where P: ImageAccessibilityProvider {
@Attribute var view: Image
@Attribute var environment: EnvironmentValues
@Attribute var transaction: Transaction
@Attribute var position: CGPoint
@Attribute var size: ViewSize
@Attribute var transform: ViewTransform
let options: ImageResolutionContext.Options
let parentID: ScrapeableID
let tracker: PropertyList.Tracker
var symbolAnimator: ORBSymbolAnimator?
var symbolEffects: _SymbolEffect.Phase

init(
view: Attribute<Image>,
environment: Attribute<EnvironmentValues>,
transaction: Attribute<Transaction>,
position: Attribute<CGPoint>,
size: Attribute<ViewSize>,
transform: Attribute<ViewTransform>,
options: ImageResolutionContext.Options,
parentID: ScrapeableID,
symbolAnimator: ORBSymbolAnimator?,
symbolEffects: _SymbolEffect.Phase
) {
self._view = view
self._environment = environment
self._transaction = transaction
self._position = position
self._size = size
self._transform = transform
self.options = options
self.parentID = parentID
self.tracker = .init()
self.symbolAnimator = symbolAnimator
self.symbolEffects = symbolEffects
}

typealias Value = P.Body

mutating func updateValue() {
let (view, viewChanged) = $view.changedValue()
let changed: Bool
if viewChanged {
changed = true
} else {
let (environment, environmentChanged) = $environment.changedValue()
if environmentChanged, tracker.hasDifferentUsedValues(environment.plist) {
changed = true
} else {
changed = !hasValue
}
}
guard changed else { return }
tracker.reset()
tracker.initializeValues(from: environment.plist)
let newEnvironment = EnvironmentValues(environment.plist, tracker: tracker)
var resolutionContext = ImageResolutionContext(
environment: newEnvironment,
textStyle: nil,
transaction: .init($transaction)
)
resolutionContext.symbolAnimator = symbolAnimator
resolutionContext.options.formUnion(options)
var resolved = view.resolve(in: resolutionContext)
symbolAnimator = resolved.image.updateSymbolEffects(
&symbolEffects,
environment: newEnvironment,
transaction: $transaction,
animationsDisabled: options.contains(.animationsDisabled)
)

value = P.makeView(image: view, resolved: resolved)
}

static func scrapeContent(from ident: AnyAttribute) -> ScrapeableContent.Item? {
let child = ident.info.body.assumingMemoryBound(to: ImageViewChild.self)[]
return ScrapeableContent.Item(
.image(child.view, child.environment),
ids: .none,
child.parentID,
position: child.$position,
size: child.$size,
transform: child.$transform
)
}
}
}

Expand Down
Loading
Loading