Skip to content

Commit 28977dd

Browse files
authored
Update IDView implementation (#570)
1 parent df0e50d commit 28977dd

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

Sources/OpenSwiftUICore/Layout/Dynamic/DynamicContainer.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,10 @@ struct DynamicContainerInfo<Adapter>: StatefulRule, AsyncAttribute, ObservedAttr
533533
var reusedIndex = -1
534534
var foundMatch = false
535535
for index in target ..< count {
536-
let inforItem = info.items[index].for(Adapter.self)
537-
guard inforItem.item.matchesIdentity(of: item) else {
538-
if reusedIndex < 0, inforItem.phase == nil {
539-
reusedIndex = inforItem.item.canBeReused(by: item) ? index : reusedIndex
536+
let infoItem = info.items[index].for(Adapter.self)
537+
guard infoItem.item.matchesIdentity(of: item) else {
538+
if reusedIndex < 0, infoItem.phase == nil {
539+
reusedIndex = infoItem.item.canBeReused(by: item) ? index : reusedIndex
540540
}
541541
continue
542542
}
@@ -545,8 +545,8 @@ struct DynamicContainerInfo<Adapter>: StatefulRule, AsyncAttribute, ObservedAttr
545545
info.items.swapAt(target, index)
546546
changed = true
547547
}
548-
inforItem.item = item
549-
if inforItem.phase != .identity {
548+
infoItem.item = item
549+
if infoItem.phase != .identity {
550550
unremoveItem(at: target)
551551
changed = true
552552
}
@@ -695,9 +695,9 @@ struct DynamicContainerInfo<Adapter>: StatefulRule, AsyncAttribute, ObservedAttr
695695
mutating func eraseItem(at index: Int) {
696696
let phase = info.items[index].phase
697697
switch phase {
698-
case .identity, nil:
698+
case .willAppear, nil:
699699
preconditionFailure("")
700-
case .willAppear:
700+
case .identity:
701701
break
702702
case .didDisappear:
703703
info.removedCount &-= 1

Sources/OpenSwiftUICore/Render/OpacityEffect.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,18 @@
44

55
extension AnyTransition {
66
// FIXME
7-
public static let opacity: AnyTransition = .identity
7+
public static let opacity: AnyTransition = .init(OpacityTransition())
8+
}
9+
10+
extension View {
11+
func opacity(_ value: Double) -> some View {
12+
// FIXME
13+
modifier(EmptyModifier())
14+
}
15+
}
16+
17+
struct OpacityTransition: Transition {
18+
func body(content: Content, phase: TransitionPhase) -> some View {
19+
content.opacity(1)
20+
}
821
}

Sources/OpenSwiftUICore/View/DynamicView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,12 @@ private struct DynamicViewList<V>: StatefulRule, AsyncAttribute where V: Dynamic
237237
}
238238

239239
func bindID(_ id: inout ViewList.ID) {
240-
id.bind(explicitID: id, owner: owner, isUnary: isUnary, reuseID: Int(bitPattern: ObjectIdentifier(Int.self)))
240+
id.bind(
241+
explicitID: self.id,
242+
owner: owner,
243+
isUnary: isUnary,
244+
reuseID: Int(bitPattern: ObjectIdentifier(Int.self))
245+
)
241246
}
242247
}
243248
}

Sources/OpenSwiftUICore/View/IDView.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// IDView.swift
33
// OpenSwiftUICore
44
//
5-
// Audited for 6.0.87
5+
// Audited for 6.5.4
66
// Status: Complete
77
// ID: D4C7BC89F06A89A4754FA9F578FD2C57 (SwiftUI)
88
// ID: ADF2FC9997986A8A2C672C0F3AA33367 (SwiftUICore)
@@ -11,6 +11,7 @@ package import OpenAttributeGraphShims
1111

1212
// MARK: - IDView
1313

14+
@available(OpenSwiftUI_v1_0, *)
1415
@usableFromInline
1516
@frozen
1617
package struct IDView<Content, ID>: View where Content: View, ID: Hashable {
@@ -42,6 +43,7 @@ extension View {
4243
///
4344
/// When the proxy value specified by the `id` parameter changes, the
4445
/// identity of the view — for example, its state — is reset.
46+
@available(OpenSwiftUI_v1_0, *)
4547
@inlinable
4648
nonisolated public func id<ID>(_ id: ID) -> some View where ID: Hashable {
4749
return IDView(self, id: id)
@@ -50,19 +52,19 @@ extension View {
5052

5153
// MARK: - IDView + makeView implementation
5254

55+
@available(OpenSwiftUI_v1_0, *)
5356
extension IDView {
5457
@usableFromInline
5558
package static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
56-
// FIXME: makeImplicitRoot is not implemented yet
57-
// if _SemanticFeature_v2.isEnabled {
58-
// return makeImplicitRoot(view: view, inputs: inputs)
59-
// } else {
59+
if _SemanticFeature_v2.isEnabled {
60+
return makeImplicitRoot(view: view, inputs: inputs)
61+
} else {
6062
let id = view.value[offset: { .of(&$0.id) }]
6163
let phase = IDPhase(id: id, phase: inputs.viewPhase, lastID: nil, delta: 0)
6264
var inputs = inputs
6365
inputs.viewPhase = Attribute(phase)
6466
return Content.makeDebuggableView(view: view[offset: { .of(&$0.content)}], inputs: inputs)
65-
// }
67+
}
6668
}
6769
}
6870

@@ -87,7 +89,7 @@ private struct IDPhase<ID>: StatefulRule, AsyncAttribute where ID: Hashable {
8789
typealias Value = _GraphInputs.Phase
8890

8991
mutating func updateValue() {
90-
if lastID != id{
92+
if lastID != id {
9193
if lastID != nil {
9294
delta &+= 1
9395
}
@@ -101,12 +103,14 @@ private struct IDPhase<ID>: StatefulRule, AsyncAttribute where ID: Hashable {
101103

102104
// MARK: - IDView + makeViewList implementation
103105

106+
@available(OpenSwiftUI_v1_0, *)
104107
extension IDView {
105108
@usableFromInline
106109
package static func _makeViewList(view: _GraphValue<Self>, inputs: _ViewListInputs) -> _ViewListOutputs {
107110
makeDynamicViewList(metadata: (), view: view, inputs: inputs)
108111
}
109112

113+
@available(OpenSwiftUI_v2_0, *)
110114
@usableFromInline
111115
package static func _viewListCount(inputs: _ViewListCountInputs) -> Int? {
112116
Content._viewListCount(inputs: inputs)

Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/AppearanceActionModifierCompatibilityTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ struct AppearanceActionModifierCompatibilityTests {
5454
}
5555
}
5656
Helper.result += "A"
57+
Helper.result += toggle ? "T" : "F"
5758
}
5859
.onDisappear {
5960
Helper.result += "D"
61+
Helper.result += toggle ? "T" : "F"
6062
}
6163
.id(toggle)
6264
}
@@ -69,7 +71,6 @@ struct AppearanceActionModifierCompatibilityTests {
6971
)
7072
)
7173
}
72-
73-
await #expect(Helper.result == "AADD")
74+
await #expect(Helper.result == "AFATDTDT")
7475
}
7576
}

0 commit comments

Comments
 (0)