From 17da8faa6eb7e4fab31d978ae545e7e6ca943111 Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Mon, 13 Jul 2020 11:17:17 -0400 Subject: [PATCH 1/3] Adds helper method and data for creating base layouts for Gutenberg Modal Layour Picker --- .../GutenbergLayouts.swift | 113 ++++++++++++++++++ packages/react-native-editor/ios/Podfile.lock | 4 +- 2 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 packages/react-native-bridge/GutenbergLayouts.swift diff --git a/packages/react-native-bridge/GutenbergLayouts.swift b/packages/react-native-bridge/GutenbergLayouts.swift new file mode 100644 index 00000000000000..192d76529f46e0 --- /dev/null +++ b/packages/react-native-bridge/GutenbergLayouts.swift @@ -0,0 +1,113 @@ +import Foundation + +struct GutenbergPageLayouts { + let layouts: [GutenbergLayout] + let categories: [GutenbergLayoutCategory] +} + +struct GutenbergLayout { + let slug: String + let title: String + let preview: String + let categories: [GutenbergLayoutCategory] +} + +struct GutenbergLayoutCategory { + let slug: String + let title: String + let description: String + let emoji: String +} + +class GutenbergPageLayoutFactory { + + //MARK: - Factory Method + + /// Creates a a default set of Page Layout templates to be used on for creating starter pages layouts. + /// - Returns: A default `GutenbergPageLayouts` object that contains a default set of layouts and categories + static func makeDefaultPageLayouts() -> GutenbergPageLayouts { + let defaultLayouts = makeDefaultLayouts() + let defaultCategories = makeDefaultCategories() + return GutenbergPageLayouts(layouts: defaultLayouts, categories: defaultCategories) + } + + + //MARK: - Define Categories + private static var aboutCategory: GutenbergLayoutCategory { + GutenbergLayoutCategory(slug: "about", + title: NSLocalizedString("About", comment: "Category name for page templates"), + description: NSLocalizedString("About pages", comment: "Category description for page templates"), + emoji: "👋") + } + + private static var blogCategory: GutenbergLayoutCategory { + GutenbergLayoutCategory(slug: "blog", + title: NSLocalizedString("Blog", comment: "Category name for page templates"), + description: NSLocalizedString("Blog pages", comment: "Category description for page templates"), + emoji: "📰") + } + + private static var contactCategory: GutenbergLayoutCategory { + GutenbergLayoutCategory(slug: "contact", + title: NSLocalizedString("Contact", comment: "Category name for page templates"), + description: NSLocalizedString("Contact pages", comment: "Category description for page templates"), + emoji: "📫") + } + + private static var portfolioCategory: GutenbergLayoutCategory { + GutenbergLayoutCategory(slug: "portfolio", + title: NSLocalizedString("Portfolio", comment: "Category name for page templates"), + description: NSLocalizedString("Portfolio pages", comment: "Category description for page templates"), + emoji: "🎨") + } + + private static var servicesCategory: GutenbergLayoutCategory { + GutenbergLayoutCategory(slug: "services", + title: NSLocalizedString("Services", comment: "Category name for page templates"), + description: NSLocalizedString("Services pages", comment: "Category description for page templates"), + emoji: "🔧") + } + + private static var teamCategory: GutenbergLayoutCategory { + GutenbergLayoutCategory(slug: "team", + title: NSLocalizedString("Team", comment: "Category name for page templates"), + description: NSLocalizedString("Team pages", comment: "Category description for page templates"), + emoji: "👥") + } + + /// Creates a a default set of Categories templates to be used on for creating starter pages layouts. + private static func makeDefaultCategories() -> [GutenbergLayoutCategory] { + return [aboutCategory, blogCategory, contactCategory, portfolioCategory, servicesCategory, teamCategory] + } + + //MARK: - Define layouts + /// Creates a a default set of Layout meta data to be used on for creating starter pages layouts. + private static func makeDefaultLayouts() -> [GutenbergLayout] { + return [ + GutenbergLayout(slug: "about", + title: NSLocalizedString("About", comment: "About page type template title"), + preview: "https://headstartdata.files.wordpress.com/2020/01/about-2.png", + categories: [aboutCategory]), + GutenbergLayout(slug: "blog", + title: NSLocalizedString("Blog", comment: "Blog page type template title"), + preview: "https://headstartdata.files.wordpress.com/2019/06/blog-4.png", + categories: [blogCategory]), + GutenbergLayout(slug: "contact", + title: NSLocalizedString("Contact", comment: "Contact page type template title"), + preview: "https://headstartdata.files.wordpress.com/2019/06/contact-2.png", + categories: [contactCategory]), + GutenbergLayout(slug: "portfolio", + title: NSLocalizedString("Portfolio", comment: "Portfolio page type template title"), + preview: "https://headstartdata.files.wordpress.com/2019/06/portfolio-2.png", + categories: [portfolioCategory]), + GutenbergLayout(slug: "services", + title: NSLocalizedString("Services", comment: "Services page type template title"), + preview: "https://headstartdata.files.wordpress.com/2019/06/services-2.png", + categories: [servicesCategory]), + GutenbergLayout(slug: "team", + title: NSLocalizedString("Team", comment: "Team page type template title"), + preview: "https://headstartdata.files.wordpress.com/2020/03/team.png", + categories: [teamCategory]) + ] + } +} diff --git a/packages/react-native-editor/ios/Podfile.lock b/packages/react-native-editor/ios/Podfile.lock index 4a4bb42057c8c1..629c95f386b95e 100644 --- a/packages/react-native-editor/ios/Podfile.lock +++ b/packages/react-native-editor/ios/Podfile.lock @@ -21,7 +21,7 @@ PODS: - DoubleConversion - glog - glog (0.3.5) - - Gutenberg (8.5.0): + - Gutenberg (8.5.1): - React (= 0.61.5) - React-CoreModules (= 0.61.5) - React-RCTImage (= 0.61.5) @@ -377,7 +377,7 @@ SPEC CHECKSUMS: FBReactNativeSpec: 118d0d177724c2d67f08a59136eb29ef5943ec75 Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51 glog: 1f3da668190260b06b429bb211bfbee5cd790c28 - Gutenberg: c5583ab0c80c08e17e40c27ae2ec14a244acf8f5 + Gutenberg: 04a90a71ab9a5e61b9dd185270dec12dff3c2777 RCTRequired: b153add4da6e7dbc44aebf93f3cf4fcae392ddf1 RCTTypeSafety: 9aa1b91d7f9310fc6eadc3cf95126ffe818af320 React: b6a59ef847b2b40bb6e0180a97d0ca716969ac78 From fce015d3e808dae878276991e2689fbc3f06fe8a Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Mon, 13 Jul 2020 14:15:30 -0400 Subject: [PATCH 2/3] Move Gutenberg Layout file to match existing folder structure --- packages/react-native-bridge/{ => ios}/GutenbergLayouts.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/react-native-bridge/{ => ios}/GutenbergLayouts.swift (100%) diff --git a/packages/react-native-bridge/GutenbergLayouts.swift b/packages/react-native-bridge/ios/GutenbergLayouts.swift similarity index 100% rename from packages/react-native-bridge/GutenbergLayouts.swift rename to packages/react-native-bridge/ios/GutenbergLayouts.swift From 6ef9a46f81ffd23d432ad2956fdbe957e70de032 Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Tue, 14 Jul 2020 16:04:42 -0400 Subject: [PATCH 3/3] Expose methods in the iOS Gutenberg pod --- .../ios/GutenbergLayouts.swift | 57 ++++++++++++++----- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/packages/react-native-bridge/ios/GutenbergLayouts.swift b/packages/react-native-bridge/ios/GutenbergLayouts.swift index 192d76529f46e0..f32ab8c5132982 100644 --- a/packages/react-native-bridge/ios/GutenbergLayouts.swift +++ b/packages/react-native-bridge/ios/GutenbergLayouts.swift @@ -1,31 +1,58 @@ import Foundation -struct GutenbergPageLayouts { - let layouts: [GutenbergLayout] - let categories: [GutenbergLayoutCategory] +public struct GutenbergPageLayouts { + public let layouts: [GutenbergLayout] + public let categories: [GutenbergLayoutCategory] + + /// Contains a map of layouts based on their Category slug + private let groupedLayouts: [String: [GutenbergLayout]] + + + public init(layouts: [GutenbergLayout], categories: [GutenbergLayoutCategory]) { + self.layouts = layouts + self.categories = categories + groupedLayouts = GutenbergPageLayouts.groupLayouts(layouts) + } + + static func groupLayouts(_ layouts: [GutenbergLayout]) -> [String:[GutenbergLayout]] { + + var groupedLayouts = [String:[GutenbergLayout]]() + + layouts.forEach { (layout) in + var group = groupedLayouts[layout.slug] ?? [GutenbergLayout]() + group.append(layout) + groupedLayouts.updateValue(group, forKey: layout.slug) + } + + return groupedLayouts + } + + public func layouts(forCategory slug: String) -> [GutenbergLayout] { + return groupedLayouts[slug] ?? [] + } } -struct GutenbergLayout { - let slug: String - let title: String - let preview: String - let categories: [GutenbergLayoutCategory] +public struct GutenbergLayout { + public let slug: String + public let title: String + public let preview: String + public let categories: [GutenbergLayoutCategory] } -struct GutenbergLayoutCategory { - let slug: String - let title: String - let description: String - let emoji: String +public struct GutenbergLayoutCategory { + public let slug: String + public let title: String + public let description: String + public let emoji: String } -class GutenbergPageLayoutFactory { +public class GutenbergPageLayoutFactory { //MARK: - Factory Method /// Creates a a default set of Page Layout templates to be used on for creating starter pages layouts. /// - Returns: A default `GutenbergPageLayouts` object that contains a default set of layouts and categories - static func makeDefaultPageLayouts() -> GutenbergPageLayouts { + public static func makeDefaultPageLayouts() -> GutenbergPageLayouts { let defaultLayouts = makeDefaultLayouts() let defaultCategories = makeDefaultCategories() return GutenbergPageLayouts(layouts: defaultLayouts, categories: defaultCategories)