diff --git a/Sources/DemoApp/DemoViews/PlacementThatFitsDemo.swift b/Sources/DemoApp/DemoViews/PlacementThatFitsDemo.swift index 697eb37f..9ac78131 100644 --- a/Sources/DemoApp/DemoViews/PlacementThatFitsDemo.swift +++ b/Sources/DemoApp/DemoViews/PlacementThatFitsDemo.swift @@ -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") { diff --git a/Sources/Placement/Layouting/PlacementModifier.swift b/Sources/Placement/Layouting/PlacementModifier.swift index c8887266..55c4221c 100644 --- a/Sources/Placement/Layouting/PlacementModifier.swift +++ b/Sources/Placement/Layouting/PlacementModifier.swift @@ -47,6 +47,7 @@ struct PlacementModifier: ViewModifier { id: id, children: children ) + .allowsHitTesting(false) .overlay( content .background( diff --git a/Sources/Placement/PlacementThatFits/PlacementThatFitsChildModifier.swift b/Sources/Placement/PlacementThatFits/PlacementThatFitsChildModifier.swift index 65e4bee8..8eecf66c 100644 --- a/Sources/Placement/PlacementThatFits/PlacementThatFitsChildModifier.swift +++ b/Sources/Placement/PlacementThatFits/PlacementThatFitsChildModifier.swift @@ -17,7 +17,7 @@ struct PlacementThatFitsChildModifier: ViewModifier { if index == coordinator.indexToPlace { content } else { - content.hidden() + content.hidden().allowsHitTesting(false) } } } diff --git a/Sources/Placement/PlacementThatFits/PlacementThatFitsLayout.swift b/Sources/Placement/PlacementThatFits/PlacementThatFitsLayout.swift index a45a3c7e..b7491097 100644 --- a/Sources/Placement/PlacementThatFits/PlacementThatFitsLayout.swift +++ b/Sources/Placement/PlacementThatFits/PlacementThatFitsLayout.swift @@ -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 } diff --git a/Sources/PlacementTests/Layouts/CenterLayout.swift b/Sources/PlacementTests/Layouts/CenterLayout.swift index 9770fca1..b235ac71 100644 --- a/Sources/PlacementTests/Layouts/CenterLayout.swift +++ b/Sources/PlacementTests/Layouts/CenterLayout.swift @@ -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)