slackhq / PanModal

An elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.
MIT License
3.69k stars 533 forks source link

PanScrollable of scrollView in WKWebView does not working #12

Closed k-lpmg closed 5 years ago

k-lpmg commented 5 years ago

Description

PanScrollable of scrollView in WKWebView does not working.

What type of issue is this? (place an x in one of the [ ])

Requirements (place an x in each of the [ ])


Bug Report

Reproducible in:

PanModal version: 1.2

iOS version: 12.1

Steps to reproduce:

  1. I create simple WebViewController that implemented PanModalPresentable
    
    import UIKit
    import WebKit

import PanModal

final class WebViewController: UIViewController {

private let webView: WKWebView = {
    let webView = WKWebView()
    webView.translatesAutoresizingMaskIntoConstraints = false
    webView.allowsBackForwardNavigationGestures = true
    return webView
}()

override func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(webView)
    webView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
    webView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
    webView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
    webView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true

    loadWeb()
}

private func loadWeb() {
    let request = URLRequest(url: URL(string: "https://github.com/slackhq/PanModal/blob/master/README.md")!)
    webView.load(request)
}

}

extension WebViewController: PanModalPresentable {

var panScrollable: UIScrollView? {
    return webView.scrollView
}

}

2. PresentPanModal WebViewController
``` swift
let controller = WebViewController()
presentPanModal(controller)

Expected result:

PanScrollable panModal webView.

Actual result:

Height is zero.

Attachments:

  1. Default setting.

  2. Add longFormHeight for default height is zero. But, panScrollable is not working.

    
    extension WebViewController: PanModalPresentable {
    
    var panScrollable: UIScrollView? {
        return webView.scrollView
    }
    
    var longFormHeight: PanModalHeight {
        return .maxHeight
    }

}


<img src="https://user-images.githubusercontent.com/15151687/55142933-0fd8ac80-5181-11e9-86de-7fe72fff1832.gif" width="220" height="470">
ste57 commented 5 years ago

Hi @k-lpmg, thanks for bringing this to our attention and the repro steps, it was helpful in getting down to the root of the issue.

The bug is caused when the scrollView contentSize is .zero at the time of the webView loading the request and the panModal initialization. There are two straight forward ways to fix this:

1) Set allowsExtendedPanScrolling to true:

var allowsExtendedPanScrolling: Bool {
    return true
}

or

2) Call PanModalSetNeedsLayoutUpdate() once the request has finished:

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    panModalSetNeedsLayoutUpdate()
}
k-lpmg commented 5 years ago

Hi @tun57 I applied it according to your answer and it worked. Thanks!