Skip to content

Commit d339cae

Browse files
committed
fix: OBCollectionView non-lazy orthogonal size calculation error fixed.
1 parent 8a489c6 commit d339cae

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

Sources/OBCalendar/OBCollectionView.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public struct OBCollectionView<Content: View, DataType>: View {
136136
gridItem: gridItem
137137
)
138138
modifyCellSizePreferenceForVGridItem(
139-
view: spacerView,
139+
view: alignedSpacer,
140140
contentIndex: 0
141141
)
142142
.frame(
@@ -178,7 +178,7 @@ public struct OBCollectionView<Content: View, DataType>: View {
178178
gridItem: gridItem
179179
)
180180
modifyCellSizePreferenceForHGridItem(
181-
view: spacerView,
181+
view: alignedSpacer,
182182
contentIndex: 0
183183
)
184184
.frame(
@@ -224,7 +224,8 @@ public struct OBCollectionView<Content: View, DataType>: View {
224224
}
225225
)
226226
.onPreferenceChange(SizePreferenceKey.self) { value in
227-
nonLazyOrthogonalSizes[contentIndex] = value
227+
let current = nonLazyOrthogonalSizes[contentIndex]
228+
nonLazyOrthogonalSizes[contentIndex] = max(current, value)
228229
}
229230
}
230231

@@ -243,7 +244,8 @@ public struct OBCollectionView<Content: View, DataType>: View {
243244
}
244245
)
245246
.onPreferenceChange(SizePreferenceKey.self) { value in
246-
nonLazyOrthogonalSizes[contentIndex] = value
247+
let current = nonLazyOrthogonalSizes[contentIndex]
248+
nonLazyOrthogonalSizes[contentIndex] = max(current, value)
247249
}
248250
}
249251
}
@@ -294,11 +296,12 @@ public struct OBCollectionView<Content: View, DataType>: View {
294296
gridItems: [.init(), .init(), .init()],
295297
gridSpacing: 8
296298
) { item, index, scrollProxy in
297-
let text: String = index == 0
298-
? "hello world"
299+
let text: String = index == 1
300+
? "hello world hello world hello world hello world"
299301
: "hello"
300302

301303
Text(text)
304+
.fixedSize(horizontal: false, vertical: true)
302305
.background(Color.red)
303306
}
304307
.background(Color.yellow)
@@ -324,14 +327,11 @@ public struct OBCollectionView<Content: View, DataType>: View {
324327

325328
#Preview("Vertical non-lazy less item") {
326329
OBCollectionView(
327-
data: Array(1...100)
330+
data: Array(1...2),
331+
gridItems: Array(repeating: .init(), count: 3)
328332
) { data, index, scrollProxy in
329-
Text("\(data)")
330-
.id(data)
331-
.onTapGesture {
332-
withAnimation {
333-
scrollProxy?.scrollTo(1)
334-
}
335-
}
333+
Text("Lorem ipsum dolor sit amet.")
334+
.background(Color.red)
335+
.fixedSize(horizontal: false, vertical: true)
336336
}
337337
}

0 commit comments

Comments
 (0)