From 4aa2ae61ebf82dc97c5f9c63dc2feb7cce6251f0 Mon Sep 17 00:00:00 2001 From: Andre Stenvall Date: Tue, 5 Dec 2017 13:44:24 +0100 Subject: [PATCH 01/12] Added viewReuseGroup to layouts --- Sources/Layout.swift | 8 ++++++++ Sources/Layouts/BaseLayout.swift | 7 ++++++- Sources/Layouts/InsetLayout.swift | 3 ++- Sources/Layouts/LabelLayout.swift | 3 ++- Sources/Layouts/SizeLayout.swift | 3 ++- Sources/Layouts/StackLayout.swift | 3 ++- Sources/Layouts/TextViewLayout.swift | 3 ++- Sources/Views/StackView.swift | 1 + 8 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Sources/Layout.swift b/Sources/Layout.swift index c4a0af00..9aae9674 100644 --- a/Sources/Layout.swift +++ b/Sources/Layout.swift @@ -105,6 +105,14 @@ public protocol Layout { then that view will be reused for the new layout. If there is more than one view with the same viewReuseId, then an arbitrary one will be reused. */ var viewReuseId: String? { get } + + + /** + An identifier that specifies the type view content + + Use this identifier enable view reuse between layouts that produce same kind of views. + */ + var viewReuseGroup: String? { get } } public extension Layout { diff --git a/Sources/Layouts/BaseLayout.swift b/Sources/Layouts/BaseLayout.swift index e4fc5b09..014ac2a4 100644 --- a/Sources/Layouts/BaseLayout.swift +++ b/Sources/Layouts/BaseLayout.swift @@ -23,6 +23,10 @@ open class BaseLayout { /// It is used to identify which views should be reused when animating from one layout to another. open let viewReuseId: String? + /// An identifier for layouts that produce same view + /// It is used to identify if view can be reused for another layout + open let viewReuseGroup: String? + /// A configuration block that is run on the main thread after the view is created. open let config: ((V) -> Void)? @@ -30,10 +34,11 @@ open class BaseLayout { return config != nil } - public init(alignment: Alignment, flexibility: Flexibility, viewReuseId: String? = nil, config: ((V) -> Void)?) { + public init(alignment: Alignment, flexibility: Flexibility, viewReuseId: String? = nil, viewReuseGroup: String? = nil, config: ((V) -> Void)?) { self.alignment = alignment self.flexibility = flexibility self.viewReuseId = viewReuseId + self.viewReuseGroup = viewReuseGroup self.config = config } diff --git a/Sources/Layouts/InsetLayout.swift b/Sources/Layouts/InsetLayout.swift index bf92a13a..493a4455 100644 --- a/Sources/Layouts/InsetLayout.swift +++ b/Sources/Layouts/InsetLayout.swift @@ -20,11 +20,12 @@ open class InsetLayout: BaseLayout, ConfigurableLayout { public init(insets: EdgeInsets, alignment: Alignment = Alignment.fill, viewReuseId: String? = nil, + viewReuseGroup: String? = nil, sublayout: Layout, config: ((V) -> Void)? = nil) { self.insets = insets self.sublayout = sublayout - super.init(alignment: alignment, flexibility: sublayout.flexibility, viewReuseId: viewReuseId, config: config) + super.init(alignment: alignment, flexibility: sublayout.flexibility, viewReuseId: viewReuseId, viewReuseGroup: viewReuseGroup, config: config) } public convenience init(inset: CGFloat, diff --git a/Sources/Layouts/LabelLayout.swift b/Sources/Layouts/LabelLayout.swift index b1fa4ccb..ceaae167 100644 --- a/Sources/Layouts/LabelLayout.swift +++ b/Sources/Layouts/LabelLayout.swift @@ -23,12 +23,13 @@ open class LabelLayout: BaseLayout