Skip to content

Commit

Permalink
Add warning in readme on how to use "constraintless" views
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Jul 5, 2024
1 parent 4b8e5f4 commit cace6ec
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension PageControllerView.Coordinator {
* - Returns: the view controller for the given identifier
* - Remark: This could involve looking up the identifier in a dictionary or storyboard
* - Remark: Displays the `ViewController` in the page-controller
* - Remark: We can also use NSViewcontroller and a NSHostingView
* - Remark: We can also use `NSViewcontroller` and a `NSHostingView
* - Fixme: ⚠️️ doc each line, use copilot
* - Fixme: ⚠️️ ref pageController instead of parent?
* - Parameters:
Expand All @@ -55,12 +55,7 @@ extension PageControllerView.Coordinator {
// Swift.print("viewControllerForIdentifier \(identifier)")
let rootView: some View = AnyView(parent.makeView(identifier)) // ⚠️️ We can probably find a better way than using AnyView
let hostingController = NSHostingController(rootView: rootView)
// hostingController.view.translatesAutoresizingMaskIntoConstraints = false
hostingController.view.autoresizingMask = [.height, .width] // this is the key to make the swiftuiu view work on init and when window is resized
// NSLayoutConstraint.activate([
// hostingController.view.centerXAnchor.constraint(equalTo: pageController.view.centerXAnchor),
// hostingController.view.centerYAnchor.constraint(equalTo: pageController.view.centerYAnchor)
// ])
return hostingController
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extension PageControllerView {
blendingMode: .behindWindow, // Set the blending mode of the effect view to behindWindow
frame: .zero // Set the frame of the effect view to the specified frame
) // Design element
// pageController.view.translatesAutoresizingMaskIntoConstraints = false
pageController.view.autoresizingMask = [.height, .width] // Resizes on window resize etc
pageController.delegate = context.coordinator // Informs the class on page id activity
pageController.arrangedObjects = dataSource // Array(0..<4).map { String($0) } // The number of items in this array must be equal to the number of view controllers you want to display inside the page controller. So if you wanted to display three view controllers in the page controller, you might create an array with three arbitrarily named items like this:
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Here is an example of how to use the `PageControllerView` in a SwiftUI view:
> [!NOTE]
> Swiping does not work properly in Xcode preview canvas. To see the swipe effect, build and run the app target for macOS.
> [!WARNING]
> To align page views to a constraintless envitronment add the pageview to a ZStack that has .ignoresSafeArea() with a clear Rectangle that has idealWidth and idealHeight set to .inifinite.
```swift
#if os(macOS)
@main
Expand Down

0 comments on commit cace6ec

Please sign in to comment.