Skip to content

Commit

Permalink
fix: OBCollectionView non-lazy orthogonal size calculation error fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtktsl committed Oct 2, 2024
1 parent 8a489c6 commit d339cae
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Sources/OBCalendar/OBCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public struct OBCollectionView<Content: View, DataType>: View {
gridItem: gridItem
)
modifyCellSizePreferenceForVGridItem(
view: spacerView,
view: alignedSpacer,
contentIndex: 0
)
.frame(
Expand Down Expand Up @@ -178,7 +178,7 @@ public struct OBCollectionView<Content: View, DataType>: View {
gridItem: gridItem
)
modifyCellSizePreferenceForHGridItem(
view: spacerView,
view: alignedSpacer,
contentIndex: 0
)
.frame(
Expand Down Expand Up @@ -224,7 +224,8 @@ public struct OBCollectionView<Content: View, DataType>: View {
}
)
.onPreferenceChange(SizePreferenceKey.self) { value in
nonLazyOrthogonalSizes[contentIndex] = value
let current = nonLazyOrthogonalSizes[contentIndex]
nonLazyOrthogonalSizes[contentIndex] = max(current, value)
}
}

Expand All @@ -243,7 +244,8 @@ public struct OBCollectionView<Content: View, DataType>: View {
}
)
.onPreferenceChange(SizePreferenceKey.self) { value in
nonLazyOrthogonalSizes[contentIndex] = value
let current = nonLazyOrthogonalSizes[contentIndex]
nonLazyOrthogonalSizes[contentIndex] = max(current, value)
}
}
}
Expand Down Expand Up @@ -294,11 +296,12 @@ public struct OBCollectionView<Content: View, DataType>: View {
gridItems: [.init(), .init(), .init()],
gridSpacing: 8
) { item, index, scrollProxy in
let text: String = index == 0
? "hello world"
let text: String = index == 1
? "hello world hello world hello world hello world"
: "hello"

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

#Preview("Vertical non-lazy less item") {
OBCollectionView(
data: Array(1...100)
data: Array(1...2),
gridItems: Array(repeating: .init(), count: 3)
) { data, index, scrollProxy in
Text("\(data)")
.id(data)
.onTapGesture {
withAnimation {
scrollProxy?.scrollTo(1)
}
}
Text("Lorem ipsum dolor sit amet.")
.background(Color.red)
.fixedSize(horizontal: false, vertical: true)
}
}

0 comments on commit d339cae

Please sign in to comment.