From 18f5f5a56ca3c237f791c8831ee09de69d6cccf6 Mon Sep 17 00:00:00 2001 From: shem Date: Fri, 8 May 2020 17:27:19 +0200 Subject: [PATCH] [NM-279] Empty pages aren't shown in nimble (#111) * [NM-279] Empty pages aren't shown in nimble * rename PageDocument method 'onPageLoad' to 'onPageDidLoad' --- .../InterfaceBuilder/Sources/PageDocument.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Plugins/InterfaceBuilder/InterfaceBuilder/Sources/PageDocument.swift b/Plugins/InterfaceBuilder/InterfaceBuilder/Sources/PageDocument.swift index e9682d4d..2c17a01d 100644 --- a/Plugins/InterfaceBuilder/InterfaceBuilder/Sources/PageDocument.swift +++ b/Plugins/InterfaceBuilder/InterfaceBuilder/Sources/PageDocument.swift @@ -45,6 +45,7 @@ public final class PageDocument: NimbleDocument, SVGDocumentProtocol { public override func read(from url: URL, ofType typeName: String) throws { adapter.load(url.path) + onPageDidLoad() } public override func data(ofType typeName: String) throws -> Data { @@ -55,6 +56,15 @@ public final class PageDocument: NimbleDocument, SVGDocumentProtocol { } return "".data(using: .utf8)! } + + private func onPageDidLoad() { + if let size = adapter.page?.size { + if size.width == 0 || size.height == 0 { + size.width = 320 + size.height = 480 + } + } + } } extension PageDocument: Document { @@ -78,11 +88,7 @@ extension PageDocument: CreatableDocument { public static func createUntitledDocument() -> Document? { let doc = PageDocument() doc.adapter.loadTemplatePage() - - if let size = doc.adapter.page?.size { - size.width = 320 - size.height = 480 - } + doc.onPageDidLoad() return doc }