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
2 changes: 2 additions & 0 deletions ios/Sources/GutenbergKit/Sources/EditorConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public struct EditorConfiguration {
public mutating func updateEditorSettings(_ settings: [String: Any]?) {
self.editorSettings = settings
}

public static let `default` = EditorConfiguration()
}

public struct WebViewGlobal {
Expand Down
16 changes: 12 additions & 4 deletions ios/Sources/GutenbergKit/Sources/EditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ public final class EditorViewController: UIViewController, GutenbergEditorContro
public var editorURL: URL?

private var cancellables: [AnyCancellable] = []
private var isWarmupMode = false

/// Warmup mode preloads resources into memory to make the UI transition seamless when displaying the editor for the first time
///
private let isWarmupMode: Bool

/// Initalizes the editor with the initial content (Gutenberg).
public init(configuration: EditorConfiguration = .init()) {
public convenience init(configuration: EditorConfiguration = .default) {
self.init(configuration: configuration, isWarmupMode: false)
}

init(configuration: EditorConfiguration = .default, isWarmupMode: Bool = false) {
self.configuration = configuration
self.controller = GutenbergEditorController(configuration: configuration)

Expand All @@ -43,6 +50,8 @@ public final class EditorViewController: UIViewController, GutenbergEditorContro
self.webView = GBWebView(frame: .zero, configuration: config)
self.webView.scrollView.keyboardDismissMode = .interactive

self.isWarmupMode = isWarmupMode

super.init(nibName: nil, bundle: nil)
}

Expand Down Expand Up @@ -330,8 +339,7 @@ public final class EditorViewController: UIViewController, GutenbergEditorContro
/// Calls this at any moment before showing the actual editor. The warmup
/// shaves a couple of hundred milliseconds off the first load.
public static func warmup() {
let editorViewController = EditorViewController()
editorViewController.isWarmupMode = true
let editorViewController = EditorViewController(isWarmupMode: true)
_ = editorViewController.view // Trigger viewDidLoad

// Retain for 5 seconds and let it prefetch stuff
Expand Down