FloatingPanel icon indicating copy to clipboard operation
FloatingPanel copied to clipboard

static UIHostingController content shifting with when added as a child view

Open Papanek opened this issue 4 years ago • 4 comments

Description

When using a SwiftUI UIHostingController as the content view controller, the .static content is displayed under the handle and then shifts when swiping up to the max position

When the content mode is .static the view position is incorrect until swiped up to the max position When the content mode is .fitToBounds the view position is correct from the start

Start Simulator Screen Shot - iPhone 12 - 2021-04-22 at 09 34 59

Swipe up Simulator Screen Shot - iPhone 12 - 2021-04-22 at 09 35 20

Expected behavior

The view is displayed at the top because there is no padding

Actual behavior

The view is displayed under the handle with extra padding that disappears after moving the content to full position

Steps to reproduce

  1. Run the below code example with fpc.contentMode = .static
  2. Swipe up to max position
  3. See content move to overlap under the handle
  4. Run code example with fpc.contentMode = .fitToBounds
  5. See content overlapping with the handle
import UIKit
import FloatingPanel
import SwiftUI

struct SwiftUIViewTest: View {
    var body: some View {
        VStack{
            Text("Hello, World!")
            Spacer()
            Text("Hello, World!")
        }
    }
}

class ViewController: UIViewController, FloatingPanelControllerDelegate {
    var fpc: FloatingPanelController!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        self.view.backgroundColor = UIColor.blue
        
        fpc = FloatingPanelController()
        
        fpc.contentMode = .static
        //fpc.contentMode = .fitToBounds

        // Assign self as the delegate of the controller.
        fpc.delegate = self // Optional

        // Set a content view controller.
        let contentVC = UIHostingController(rootView: SwiftUIViewTest())
        fpc.set(contentViewController: contentVC)

        // Track a scroll view(or the siblings) in the content view controller.
        // fpc.track(scrollView: contentVC.tableView)

        // Add and show the views managed by the `FloatingPanelController` object to self.view.
        fpc.addPanel(toParent: self)
    }
}

Environment

Library version 2.3.0

Installation method Swift Package Manager

iOS version(s) 14.4

Xcode version Version 12.4 (12D4e)

Papanek avatar Apr 21 '21 16:04 Papanek

This issue should be renamed as .static UIHostingController content shifting with when added as a child view.

To work around .static content shifting, presenting as modal displays the content overlapping with the grabber and then you can add padding to position it to under the grabber

Papanek avatar Apr 22 '21 13:04 Papanek

Something is conflicting with the safe area layout constraints

Papanek avatar Apr 22 '21 14:04 Papanek

I figured out the root cause. That is the safe are. So this issue is resolved by edgesIgnoringSafeArea view modifier.

struct SwiftUIViewTest: View {
    var body: some View {
        VStack{
            Text("Hello, World!")
            Spacer()
            Text("Hello, World!")
        }.edgesIgnoringSafeArea([.top])
    }
}

scenee avatar Apr 29 '21 07:04 scenee

This seems related to an issue brought up here: https://twitter.com/b3ll/status/1193747288302075906?s=20 Additionally, a more fleshed out fix (see: hack) is here: https://defagos.github.io/swiftui_collection_part3/

There's also a radar issue opened for this: https://openradar.appspot.com/FB8176223

dafurman avatar Nov 09 '21 00:11 dafurman