Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [*] Improved large text support in the blog details header in My Sites. [#16521]
* [***] Block Editor: New Block: Reusable block. [https://github.com/wordpress-mobile/gutenberg-mobile/pull/3490]
* [***] Block Editor: Add reusable blocks to the block inserter menu. [https://github.com/wordpress-mobile/gutenberg-mobile/pull/3054]
* [*] Fixed a bug where the web version of the editor did not load when using an account created before December 2018. [#16586]

17.4
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
let blog = post.blog
let isJetpackSSOEnabled = (blog.jetpack?.isConnected ?? false) && (blog.settings?.jetpackSSOEnabled ?? false)

return blog.isHostedAtWPcom || (isJetpackSSOEnabled && blog.webEditor == .gutenberg)
return blog.isHostedAtWPcom || isJetpackSSOEnabled
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import WebKit
import Gutenberg

class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitAuthenticatable {
class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitAuthenticatable, NoResultsViewHost {
enum GutenbergWebError: Error {
case wrongEditorUrl(String?)
}
Expand All @@ -11,6 +11,7 @@ class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitA
private let url: URL
private let progressView = WebProgressView()
private let userId: String
let gutenbergReadySemaphore = DispatchSemaphore(value: 0)

init(with post: AbstractPost, block: Block) throws {
authenticator = GutenbergRequestAuthenticator(blog: post.blog)
Expand All @@ -35,8 +36,10 @@ class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitA
override func viewDidLoad() {
super.viewDidLoad()
addNavigationBarElements()
showLoadingMessage()
addProgressView()
startObservingWebView()
waitForGutenbergToLoad(fallback: showTroubleshootingInstructions)
}

deinit {
Expand Down Expand Up @@ -82,6 +85,10 @@ class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitA
override func onGutenbergReady() {
super.onGutenbergReady()
navigationItem.rightBarButtonItem?.isEnabled = true
DispatchQueue.main.async { [weak self] in
self?.hideNoResults()
self?.gutenbergReadySemaphore.signal()
}
}

private func loadCustomScript(named name: String, with argument: String? = nil) -> WKUserScript? {
Expand All @@ -104,6 +111,31 @@ class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitA
navigationItem.rightBarButtonItem?.isEnabled = false
}

private func showLoadingMessage() {
let title = NSLocalizedString("Loading the block editor.", comment: "Loading message shown while the Unsupported Block Editor is loading.")
let subtitle = NSLocalizedString("Please ensure the block editor is enabled on your site. If it is not enabled, it will not load.", comment: "Message asking users to make sure that the block editor is enabled on their site in order for the Unsupported Block Editor to load properly.")
configureAndDisplayNoResults(on: view, title: title, subtitle: subtitle, accessoryView: NoResultsViewController.loadingAccessoryView())
}

private func waitForGutenbergToLoad(fallback: @escaping () -> Void) {
DispatchQueue.global(qos: .background).async { [weak self] in
let timeout: TimeInterval = 15
// blocking call
if self?.gutenbergReadySemaphore.wait(timeout: .now() + timeout) == .timedOut {
DispatchQueue.main.async {
fallback()
}
}
}
}

private func showTroubleshootingInstructions() {
let title = NSLocalizedString("Unable to load the block editor right now.", comment: "Title message shown when the Unsupported Block Editor fails to load.")
let subtitle = NSLocalizedString("Please ensure the block editor is enabled on your site and try again.", comment: "Subtitle message shown when the Unsupported Block Editor fails to load. It asks users to verify that the block editor is enabled on their site before trying again.")
// This does nothing if the "no results" screen is not currently displayed, which is the intended behavior
updateNoResults(title: title, subtitle: subtitle, image: "cloud")
}

private func startObservingWebView() {
webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: [.new], context: nil)
}
Expand All @@ -123,6 +155,7 @@ extension GutenbergWebViewController {
override func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
super.webView(webView, didCommit: navigation)
if webView.url?.absoluteString.contains("reauth=1") ?? false {
hideNoResults()
removeCoverViewAnimated()
}
}
Expand Down