From 2740217b57cb6f9f47730649eb4ee0662b29d1e0 Mon Sep 17 00:00:00 2001 From: Jinwoo Kim Date: Wed, 5 Jan 2022 00:00:11 +0900 Subject: [PATCH] Added support for UICollectionViewLayout Decoration View --- .../UICollectionViewLayout+Reusable.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Sources/View/UICollectionViewLayout+Reusable.swift diff --git a/Sources/View/UICollectionViewLayout+Reusable.swift b/Sources/View/UICollectionViewLayout+Reusable.swift new file mode 100644 index 0000000..2c20332 --- /dev/null +++ b/Sources/View/UICollectionViewLayout+Reusable.swift @@ -0,0 +1,30 @@ +/********************************************* + * + * This code is under the MIT License (MIT) + * + * Copyright (c) 2016 AliSoftware + * + *********************************************/ + +#if canImport(UIKit) +import UIKit + +public extension UICollectionReusableView { + static var elementKind: String { + return String(describing: self) + } +} + +public extension UICollectionViewLayout { + final func register(decorationViewType: T.Type) + where T: Reusable & NibLoadable { + self.register(decorationViewType.nib, forDecorationViewOfKind: decorationViewType.elementKind) + } + + final func register(decorationViewType: T.Type) + where T: Reusable { + self.register(decorationViewType.self, forDecorationViewOfKind: decorationViewType.elementKind) + } +} + +#endif