Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to PlacementThatFits #11

Merged
merged 2 commits into from
Oct 11, 2023
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
15 changes: 12 additions & 3 deletions Sources/DemoApp/DemoViews/PlacementThatFitsDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ struct PlacementThatFitsDemo: View {
var body: some View {
ScrollView {
VStack(spacing: 20) {
PlacementThatFits(in: [.horizontal], prefersViewThatFits: false) {
Text("Some longer text that wont fit initially")
Text("Some text")
PlacementThatFits(prefersViewThatFits: false) {
Button("Some longer text that wont fit initially") {
print("tap index 0")
}.onAppear(perform: {
print("did appear index 0")
})
Button("A button") {
print("tap index 1")
}.onAppear(perform: {
print("did appear index 1")
})
}
.border(.red)
.frame(maxWidth: changeContainerWidth ? .infinity : 150)

Button("Change container width") {
Expand Down
1 change: 1 addition & 0 deletions Sources/Placement/Layouting/PlacementModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct PlacementModifier<L: PlacementLayout>: ViewModifier {
id: id,
children: children
)
.allowsHitTesting(false)
.overlay(
content
.background(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct PlacementThatFitsChildModifier: ViewModifier {
if index == coordinator.indexToPlace {
content
} else {
content.hidden()
content.hidden().allowsHitTesting(false)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ struct PlacementThatFitsLayout: PlacementLayout {
let size = subview.sizeThatFits(proposal)

if axes.contains(.horizontal) && axes.contains(.vertical) {
if size.width <= (proposal.width ?? 0) && size.height <= (proposal.height ?? 0) {
if size.width <= (proposal.width ?? .infinity) && size.height <= (proposal.height ?? .infinity) {
coordinator.indexToPlace = index
return size
}
} else if axes.contains(.horizontal) {
if size.width <= (proposal.width ?? 0) {
if size.width <= (proposal.width ?? .infinity) {
coordinator.indexToPlace = index
return size
}
} else if axes.contains(.vertical) {
if size.height <= (proposal.height ?? 0) {
if size.height <= (proposal.height ?? .infinity) {
coordinator.indexToPlace = index
return size
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/PlacementTests/Layouts/CenterLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public struct CenterLayout: PlacementLayout {
cache: inout ()
) {
for index in subviews.indices {
print(index)

let subview = subviews[index]
let dimension = subview.dimensions(in: proposal)

Expand Down
Loading