Skip to content

Commit a57e211

Browse files
committed
Update BaseViewList
1 parent 54315c4 commit a57e211

File tree

2 files changed

+136
-1
lines changed

2 files changed

+136
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// TransitionTraitKey.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for iOS 18.0
6+
// Status: WIP
7+
8+
@usableFromInline
9+
struct CanTransitionTraitKey: _ViewTraitKey {
10+
@inlinable
11+
static var defaultValue: Bool { false }
12+
}
13+
14+
@available(*, unavailable)
15+
extension CanTransitionTraitKey: Sendable {}
16+
17+
extension ViewTraitCollection {
18+
package var canTransition: Bool {
19+
get { self[CanTransitionTraitKey.self] }
20+
set { self[CanTransitionTraitKey.self] = newValue }
21+
}
22+
}

Sources/OpenSwiftUICore/View/Input/ViewList.swift

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ public struct TypedUnaryViewGenerator<V>: UnaryViewGenerator where V: View {
10931093
}
10941094
}
10951095

1096-
// MARK: - UnaryElements
1096+
// MARK: - UnaryElements [WIP]
10971097

10981098
private struct UnaryElements<Generator>: ViewList.Elements where Generator: UnaryViewGenerator {
10991099
var body: Generator
@@ -1135,6 +1135,17 @@ private struct UnaryElements<Generator>: ViewList.Elements where Generator: Unar
11351135
// MARK: - ViewListOutputs + Extension [TODO]
11361136

11371137
extension _ViewListOutputs {
1138+
private struct ApplyModifiers: Rule, AsyncAttribute {
1139+
@Attribute var base: any ViewList
1140+
let modifier: ListModifier
1141+
1142+
var value: any ViewList {
1143+
var value = base
1144+
modifier.apply(to: &value)
1145+
return value
1146+
}
1147+
}
1148+
11381149
private static func staticList(_ elements: any ViewList.Elements, inputs: _ViewListInputs, staticCount: Int) -> _ViewListOutputs {
11391150
preconditionFailure("TODO")
11401151
}
@@ -1184,6 +1195,108 @@ extension _ViewListOutputs {
11841195
}
11851196
}
11861197

1198+
// MARK: - BaseViewList
1199+
1200+
private struct BaseViewList: ViewList {
1201+
var elements: any Elements
1202+
var implicitID: Int
1203+
var traitKeys: ViewTraitKeys?
1204+
var traits: ViewTraitCollection
1205+
1206+
init(
1207+
elements: any Elements,
1208+
implicitID: Int,
1209+
canTransition: Bool,
1210+
stableIDScope: WeakAttribute<DisplayList.StableIdentityScope>?,
1211+
traitKeys: ViewTraitKeys?,
1212+
traits: ViewTraitCollection
1213+
) {
1214+
self.elements = elements
1215+
self.implicitID = implicitID
1216+
self.traitKeys = traitKeys
1217+
self.traits = traits
1218+
if canTransition {
1219+
self.traits.canTransition = true
1220+
}
1221+
if let stableIDScope {
1222+
self.traits[DisplayList.StableIdentityScope.self] = stableIDScope
1223+
}
1224+
}
1225+
1226+
func count(style: IteratorStyle) -> Int {
1227+
style.applyGranularity(to: elements.count)
1228+
}
1229+
1230+
func estimatedCount(style: IteratorStyle) -> Int {
1231+
style.applyGranularity(to: elements.count)
1232+
}
1233+
1234+
var viewIDs: ID.Views? {
1235+
ID._Views(
1236+
ID.ElementCollection(
1237+
id: ID(implicitID: implicitID),
1238+
count: elements.count),
1239+
isDataDependent: false
1240+
)
1241+
}
1242+
1243+
func applyNodes(
1244+
from start: inout Int,
1245+
style: IteratorStyle,
1246+
list: Attribute<any ViewList>?,
1247+
transform: inout SublistTransform,
1248+
to body: ApplyBody
1249+
) -> Bool {
1250+
let count = count(style: style)
1251+
guard start < count else {
1252+
start -= count
1253+
return true
1254+
}
1255+
let sublist = Sublist(
1256+
start: start,
1257+
count: count,
1258+
id: ViewList.ID(implicitID: implicitID),
1259+
elements: elements,
1260+
traits: traits,
1261+
list: list
1262+
)
1263+
defer { start = 0 }
1264+
return body(&start, style, .sublist(sublist), &transform)
1265+
}
1266+
1267+
func edit(forID id: ID, since transaction: TransactionID) -> Edit? {
1268+
nil
1269+
}
1270+
1271+
func firstOffset<OtherID>(forID id: OtherID, style: IteratorStyle) -> Int? where OtherID : Hashable {
1272+
nil
1273+
}
1274+
1275+
struct Init: Rule, AsyncAttribute, CustomStringConvertible {
1276+
let elements: any Elements
1277+
let implicitID: Int
1278+
let canTransition: Bool
1279+
let stableIDScope: WeakAttribute<DisplayList.StableIdentityScope>?
1280+
let traitKeys: ViewTraitKeys?
1281+
@OptionalAttribute var traits: ViewTraitCollection?
1282+
1283+
var value: any ViewList {
1284+
BaseViewList(
1285+
elements: elements,
1286+
implicitID: implicitID,
1287+
canTransition: canTransition,
1288+
stableIDScope: stableIDScope,
1289+
traitKeys: traitKeys,
1290+
traits: traits ?? .init()
1291+
)
1292+
}
1293+
1294+
var description: String {
1295+
"Elements [\(elements.count)]"
1296+
}
1297+
}
1298+
}
1299+
11871300
// MARK: - EmptyViewList
11881301

11891302
package struct EmptyViewList: ViewList {

0 commit comments

Comments
 (0)