From d6c1dfdf9d1076ec64333a73b80df0b6294ed5bd Mon Sep 17 00:00:00 2001 From: Markus Mueller Date: Thu, 22 Oct 2020 23:35:04 +0200 Subject: [PATCH 1/4] Adds SPM support Signed-off-by: Markus Mueller --- .../contents.xcworkspacedata | 7 +++++ Package.swift | 30 +++++++++++++++++++ Sources/{ => FXPageControl}/FXPageControl.h | 0 Sources/{ => FXPageControl}/FXPageControl.m | 0 Sources/{ => Resources}/ButtonCell.xib | 0 .../BarPagerTabStripViewController.swift | 0 Sources/{ => XLPagerTabStrip}/BarView.swift | 1 + ...ButtonBarPagerTabStripViewController.swift | 1 + ...ButtonBarPagerTabStripViewController.swift | 1 + .../{ => XLPagerTabStrip}/ButtonBarView.swift | 0 .../ButtonBarViewCell.swift | 0 .../{ => XLPagerTabStrip}/IndicatorInfo.swift | 1 + .../PagerTabStripBehaviour.swift | 0 .../PagerTabStripError.swift | 0 .../PagerTabStripViewController.swift | 1 + ...SegmentedPagerTabStripViewController.swift | 1 + .../SwipeDirection.swift | 0 .../TwitterPagerTabStripViewController.swift | 2 ++ 18 files changed, 45 insertions(+) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata create mode 100644 Package.swift rename Sources/{ => FXPageControl}/FXPageControl.h (100%) rename Sources/{ => FXPageControl}/FXPageControl.m (100%) rename Sources/{ => Resources}/ButtonCell.xib (100%) rename Sources/{ => XLPagerTabStrip}/BarPagerTabStripViewController.swift (100%) rename Sources/{ => XLPagerTabStrip}/BarView.swift (99%) rename Sources/{ => XLPagerTabStrip}/BaseButtonBarPagerTabStripViewController.swift (99%) rename Sources/{ => XLPagerTabStrip}/ButtonBarPagerTabStripViewController.swift (99%) rename Sources/{ => XLPagerTabStrip}/ButtonBarView.swift (100%) rename Sources/{ => XLPagerTabStrip}/ButtonBarViewCell.swift (100%) rename Sources/{ => XLPagerTabStrip}/IndicatorInfo.swift (99%) rename Sources/{ => XLPagerTabStrip}/PagerTabStripBehaviour.swift (100%) rename Sources/{ => XLPagerTabStrip}/PagerTabStripError.swift (100%) rename Sources/{ => XLPagerTabStrip}/PagerTabStripViewController.swift (99%) rename Sources/{ => XLPagerTabStrip}/SegmentedPagerTabStripViewController.swift (99%) rename Sources/{ => XLPagerTabStrip}/SwipeDirection.swift (100%) rename Sources/{ => XLPagerTabStrip}/TwitterPagerTabStripViewController.swift (99%) diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..fac0ab9a --- /dev/null +++ b/Package.swift @@ -0,0 +1,30 @@ +// swift-tools-version:5.3 + +import PackageDescription + +let package = Package( + name: "XLPagerTabStrip", + platforms: [ + .iOS(.v9) + ], + products: [ + .library( + name: "XLPagerTabStrip", + targets: ["XLPagerTabStrip"] + ) + ], + targets: [ + .target( + name: "FXPageControl", + publicHeadersPath: "." + ), + .target( + name: "XLPagerTabStrip", + dependencies: ["FXPageControl"], + exclude: ["Example", "XLPagerTabStrip"], + resources: [ + .process("ButtonCell.xib") + ] + ), + ] +) diff --git a/Sources/FXPageControl.h b/Sources/FXPageControl/FXPageControl.h similarity index 100% rename from Sources/FXPageControl.h rename to Sources/FXPageControl/FXPageControl.h diff --git a/Sources/FXPageControl.m b/Sources/FXPageControl/FXPageControl.m similarity index 100% rename from Sources/FXPageControl.m rename to Sources/FXPageControl/FXPageControl.m diff --git a/Sources/ButtonCell.xib b/Sources/Resources/ButtonCell.xib similarity index 100% rename from Sources/ButtonCell.xib rename to Sources/Resources/ButtonCell.xib diff --git a/Sources/BarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/BarPagerTabStripViewController.swift similarity index 100% rename from Sources/BarPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/BarPagerTabStripViewController.swift diff --git a/Sources/BarView.swift b/Sources/XLPagerTabStrip/BarView.swift similarity index 99% rename from Sources/BarView.swift rename to Sources/XLPagerTabStrip/BarView.swift index 1183524d..843b8bc3 100644 --- a/Sources/BarView.swift +++ b/Sources/XLPagerTabStrip/BarView.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit open class BarView: UIView { diff --git a/Sources/BaseButtonBarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/BaseButtonBarPagerTabStripViewController.swift similarity index 99% rename from Sources/BaseButtonBarPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/BaseButtonBarPagerTabStripViewController.swift index 68684ac4..1c78b267 100644 --- a/Sources/BaseButtonBarPagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/BaseButtonBarPagerTabStripViewController.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit open class BaseButtonBarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, UICollectionViewDataSource { diff --git a/Sources/ButtonBarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift similarity index 99% rename from Sources/ButtonBarPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift index 36e008d6..0804b2fd 100644 --- a/Sources/ButtonBarPagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit public enum ButtonBarItemSpec { diff --git a/Sources/ButtonBarView.swift b/Sources/XLPagerTabStrip/ButtonBarView.swift similarity index 100% rename from Sources/ButtonBarView.swift rename to Sources/XLPagerTabStrip/ButtonBarView.swift diff --git a/Sources/ButtonBarViewCell.swift b/Sources/XLPagerTabStrip/ButtonBarViewCell.swift similarity index 100% rename from Sources/ButtonBarViewCell.swift rename to Sources/XLPagerTabStrip/ButtonBarViewCell.swift diff --git a/Sources/IndicatorInfo.swift b/Sources/XLPagerTabStrip/IndicatorInfo.swift similarity index 99% rename from Sources/IndicatorInfo.swift rename to Sources/XLPagerTabStrip/IndicatorInfo.swift index 146eb9a5..e5fff108 100644 --- a/Sources/IndicatorInfo.swift +++ b/Sources/XLPagerTabStrip/IndicatorInfo.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit public struct IndicatorInfo { diff --git a/Sources/PagerTabStripBehaviour.swift b/Sources/XLPagerTabStrip/PagerTabStripBehaviour.swift similarity index 100% rename from Sources/PagerTabStripBehaviour.swift rename to Sources/XLPagerTabStrip/PagerTabStripBehaviour.swift diff --git a/Sources/PagerTabStripError.swift b/Sources/XLPagerTabStrip/PagerTabStripError.swift similarity index 100% rename from Sources/PagerTabStripError.swift rename to Sources/XLPagerTabStrip/PagerTabStripError.swift diff --git a/Sources/PagerTabStripViewController.swift b/Sources/XLPagerTabStrip/PagerTabStripViewController.swift similarity index 99% rename from Sources/PagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/PagerTabStripViewController.swift index 9aedb7d6..902706cf 100644 --- a/Sources/PagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/PagerTabStripViewController.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit // MARK: Protocols diff --git a/Sources/SegmentedPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/SegmentedPagerTabStripViewController.swift similarity index 99% rename from Sources/SegmentedPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/SegmentedPagerTabStripViewController.swift index cdd3fb14..f476de59 100644 --- a/Sources/SegmentedPagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/SegmentedPagerTabStripViewController.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit public struct SegmentedPagerTabStripSettings { diff --git a/Sources/SwipeDirection.swift b/Sources/XLPagerTabStrip/SwipeDirection.swift similarity index 100% rename from Sources/SwipeDirection.swift rename to Sources/XLPagerTabStrip/SwipeDirection.swift diff --git a/Sources/TwitterPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/TwitterPagerTabStripViewController.swift similarity index 99% rename from Sources/TwitterPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/TwitterPagerTabStripViewController.swift index c37215a2..a0ab540b 100644 --- a/Sources/TwitterPagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/TwitterPagerTabStripViewController.swift @@ -23,6 +23,8 @@ // THE SOFTWARE. import Foundation +import UIKit +import FXPageControl public struct TwitterPagerTabStripSettings { From a6dd2ea2c1b6cc9a074ad36776785f6c4683f005 Mon Sep 17 00:00:00 2001 From: Markus Mueller Date: Fri, 23 Oct 2020 11:29:46 +0200 Subject: [PATCH 2/4] Fixes resource loading Signed-off-by: Markus Mueller --- Package.swift | 6 +- ...ButtonBarPagerTabStripViewController.swift | 75 ++++++++++++------- .../Resources/ButtonCell.xib | 0 XLPagerTabStrip.podspec | 2 +- 4 files changed, 51 insertions(+), 32 deletions(-) rename Sources/{ => XLPagerTabStrip}/Resources/ButtonCell.xib (100%) diff --git a/Package.swift b/Package.swift index fac0ab9a..0a328eba 100644 --- a/Package.swift +++ b/Package.swift @@ -20,11 +20,7 @@ let package = Package( ), .target( name: "XLPagerTabStrip", - dependencies: ["FXPageControl"], - exclude: ["Example", "XLPagerTabStrip"], - resources: [ - .process("ButtonCell.xib") - ] + dependencies: ["FXPageControl"] ), ] ) diff --git a/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift index 0804b2fd..e9fd1eec 100644 --- a/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift @@ -25,6 +25,34 @@ import Foundation import UIKit + +extension Foundation.Bundle { + /// Returns the resource bundle associated with the current Swift module. + static var resourceBundle: Bundle = { + let candidates = [ + // Bundle should be present here when the package is linked into an App. + Bundle.main.resourceURL, + + // Bundle should be present here when the package is linked into a framework. + Bundle(for: ButtonBarViewCell.self).resourceURL, + + // For command-line tools. + Bundle.main.bundleURL, + ] + + for candidate in candidates { + let bundleNames = ["XLPagerTabStrip", "XLPagerTabStrip_XLPagerTabStrip"] + for name in bundleNames { + let bundlePath = candidate?.appendingPathComponent(name + ".bundle") + if let bundle = bundlePath.flatMap(Bundle.init(url:)) { + return bundle + } + } + } + fatalError("unable to find bundle named XLPagerTabStrip_XLPagerTabStrip") + }() +} + public enum ButtonBarItemSpec { case nibFile(nibName: String, bundle: Bundle?, width:((IndicatorInfo)-> CGFloat)) @@ -94,37 +122,32 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa open override func viewDidLoad() { super.viewDidLoad() - - var bundle = Bundle(for: ButtonBarViewCell.self) - if let resourcePath = bundle.path(forResource: "XLPagerTabStrip", ofType: "bundle") { - if let resourcesBundle = Bundle(path: resourcePath) { - bundle = resourcesBundle - } - } + + let bundle = Bundle.resourceBundle buttonBarItemSpec = .nibFile(nibName: "ButtonCell", bundle: bundle, width: { [weak self] (childItemInfo) -> CGFloat in - let label = UILabel() - label.translatesAutoresizingMaskIntoConstraints = false - label.font = self?.settings.style.buttonBarItemFont - label.text = childItemInfo.title - let labelSize = label.intrinsicContentSize - return labelSize.width + (self?.settings.style.buttonBarItemLeftRightMargin ?? 8) * 2 + let label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.font = self?.settings.style.buttonBarItemFont + label.text = childItemInfo.title + let labelSize = label.intrinsicContentSize + return labelSize.width + (self?.settings.style.buttonBarItemLeftRightMargin ?? 8) * 2 }) let buttonBarViewAux = buttonBarView ?? { - let flowLayout = UICollectionViewFlowLayout() - flowLayout.scrollDirection = .horizontal - let buttonBarHeight = settings.style.buttonBarHeight ?? 44 - let buttonBar = ButtonBarView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: buttonBarHeight), collectionViewLayout: flowLayout) - buttonBar.backgroundColor = .orange - buttonBar.selectedBar.backgroundColor = .black - buttonBar.autoresizingMask = .flexibleWidth - var newContainerViewFrame = containerView.frame - newContainerViewFrame.origin.y = buttonBarHeight - newContainerViewFrame.size.height = containerView.frame.size.height - (buttonBarHeight - containerView.frame.origin.y) - containerView.frame = newContainerViewFrame - return buttonBar - }() + let flowLayout = UICollectionViewFlowLayout() + flowLayout.scrollDirection = .horizontal + let buttonBarHeight = settings.style.buttonBarHeight ?? 44 + let buttonBar = ButtonBarView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: buttonBarHeight), collectionViewLayout: flowLayout) + buttonBar.backgroundColor = .orange + buttonBar.selectedBar.backgroundColor = .black + buttonBar.autoresizingMask = .flexibleWidth + var newContainerViewFrame = containerView.frame + newContainerViewFrame.origin.y = buttonBarHeight + newContainerViewFrame.size.height = containerView.frame.size.height - (buttonBarHeight - containerView.frame.origin.y) + containerView.frame = newContainerViewFrame + return buttonBar + }() buttonBarView = buttonBarViewAux if buttonBarView.superview == nil { diff --git a/Sources/Resources/ButtonCell.xib b/Sources/XLPagerTabStrip/Resources/ButtonCell.xib similarity index 100% rename from Sources/Resources/ButtonCell.xib rename to Sources/XLPagerTabStrip/Resources/ButtonCell.xib diff --git a/XLPagerTabStrip.podspec b/XLPagerTabStrip.podspec index 35b7ae61..fadc3afb 100644 --- a/XLPagerTabStrip.podspec +++ b/XLPagerTabStrip.podspec @@ -11,6 +11,6 @@ Pod::Spec.new do |s| s.requires_arc = true s.ios.source_files = 'Sources/**/*.{h,m,swift}' s.ios.frameworks = 'UIKit', 'Foundation' - s.resource_bundles = { 'XLPagerTabStrip' => ['Sources/ButtonCell.xib'] } + s.resource_bundles = { 'XLPagerTabStrip' => ['Sources/XLPagerTabStrip/Resources/ButtonCell.xib'] } s.swift_version = "5.0" end From 3e25677b3c076cf7ba972965ac8c494e03132dad Mon Sep 17 00:00:00 2001 From: Markus Mueller Date: Fri, 23 Oct 2020 12:35:31 +0200 Subject: [PATCH 3/4] Fixes crash when loading ButtonCell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disabled „Inherit Module From Target“ in ButtonCell.xib Signed-off-by: Markus Mueller --- Sources/XLPagerTabStrip/Resources/ButtonCell.xib | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Sources/XLPagerTabStrip/Resources/ButtonCell.xib b/Sources/XLPagerTabStrip/Resources/ButtonCell.xib index 7025bc70..94ca345f 100644 --- a/Sources/XLPagerTabStrip/Resources/ButtonCell.xib +++ b/Sources/XLPagerTabStrip/Resources/ButtonCell.xib @@ -1,17 +1,15 @@ - - - - + + - + - + @@ -19,7 +17,7 @@