diff --git a/Source/Turbo/Visitable/VisitableView.swift b/Source/Turbo/Visitable/VisitableView.swift index f0adc362..162469c1 100644 --- a/Source/Turbo/Visitable/VisitableView.swift +++ b/Source/Turbo/Visitable/VisitableView.swift @@ -24,7 +24,10 @@ open class VisitableView: UIView { open func activateWebView(_ webView: WKWebView, forVisitable visitable: Visitable) { self.webView = webView self.visitable = visitable - addSubview(webView) + // For behaviour like UINavigationBar.prefersLargeTitles or + // TabBarMinimize to work the scrollable view shoud be the + // first child in the hierarchy from the moment it is added. + insertSubview(webView, at: 0) addFillConstraints(for: webView) installRefreshControl() showOrHideWebView() diff --git a/Tests/Turbo/VisitableViewControllerTests.swift b/Tests/Turbo/VisitableViewControllerTests.swift index a3bcb3ca..d971d234 100644 --- a/Tests/Turbo/VisitableViewControllerTests.swift +++ b/Tests/Turbo/VisitableViewControllerTests.swift @@ -47,6 +47,30 @@ class VisitableViewControllerTests: XCTestCase { XCTAssertEqual(viewController.initialVisitableURL, originalURL) XCTAssertEqual(viewController.currentVisitableURL, overriddenURL) } + + func test_webview_is_first_child_during_loading() { + XCTAssertEqual(viewController.visitableView.subviews.first, viewController.visitableView.activityIndicatorView) + + viewController.visitableView.activateWebView(webView, forVisitable: viewController) + + XCTAssertEqual(viewController.visitableView.subviews.first, webView) + XCTAssertEqual(viewController.visitableView.subviews.last, viewController.visitableView.activityIndicatorView) + } + + func test_webview_is_first_child_on_restore() { + XCTAssertEqual(viewController.visitableView.subviews.first, viewController.visitableView.activityIndicatorView) + + viewController.showVisitableScreenshot() + viewController.visitableView.activateWebView(webView, forVisitable: viewController) + + XCTAssertEqual(viewController.visitableView.subviews.count, 3) + XCTAssertEqual(viewController.visitableView.subviews.first, viewController.visitableView.webView) + + viewController.hideVisitableScreenshot() + + XCTAssertEqual(viewController.visitableView.subviews.count, 2) + XCTAssertEqual(viewController.visitableView.subviews.first, viewController.visitableView.webView) + } } final class WebViewSpy: WKWebView {