Skip to content

Commit

Permalink
Remove bundle resources (reimplemented in code) to support Swift Pack…
Browse files Browse the repository at this point in the history
…age Manager (#1976)

* Remove chevron resources, draw them in code instead (or use SFSymbols if running iOS 13 or later)

* Add Package.swift
  • Loading branch information
AndrewBennet authored and mats-claassen committed Jan 22, 2020
1 parent 2046ebf commit 88c156b
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 22 deletions.
13 changes: 0 additions & 13 deletions Eureka.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
51729DF61B9A4F5E004A00EB /* Eureka.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51729DEB1B9A4F5E004A00EB /* Eureka.framework */; };
51729E671B9A5FA5004A00EB /* Eureka.h in Headers */ = {isa = PBXBuildFile; fileRef = 51729E661B9A5FA5004A00EB /* Eureka.h */; settings = {ATTRIBUTES = (Public, ); }; };
798C5ADA1EF1E35600A21F52 /* SwipeActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 798C5AD91EF1E35600A21F52 /* SwipeActions.swift */; };
8690E4BE1CFDE062004CDB1C /* Eureka.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8690E4BD1CFDE062004CDB1C /* Eureka.bundle */; };
8FCCF8EF20A24085004793A0 /* DoublePickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FCCF8EE20A24085004793A0 /* DoublePickerRow.swift */; };
8FCCF8F120A32613004793A0 /* TriplePickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FCCF8F020A32613004793A0 /* TriplePickerRow.swift */; };
8FCCF92320A473E7004793A0 /* DoublePickerInputRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FCCF92220A473E7004793A0 /* DoublePickerInputRow.swift */; };
Expand Down Expand Up @@ -186,7 +185,6 @@
51729DFC1B9A4F5E004A00EB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../Tests/Info.plist; sourceTree = "<group>"; };
51729E661B9A5FA5004A00EB /* Eureka.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Eureka.h; path = Source/Eureka.h; sourceTree = SOURCE_ROOT; };
798C5AD91EF1E35600A21F52 /* SwipeActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeActions.swift; sourceTree = "<group>"; };
8690E4BD1CFDE062004CDB1C /* Eureka.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Eureka.bundle; sourceTree = "<group>"; };
8FCCF8EE20A24085004793A0 /* DoublePickerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoublePickerRow.swift; sourceTree = "<group>"; };
8FCCF8F020A32613004793A0 /* TriplePickerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TriplePickerRow.swift; sourceTree = "<group>"; };
8FCCF92220A473E7004793A0 /* DoublePickerInputRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoublePickerInputRow.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -353,7 +351,6 @@
2859CD901C7CF1FD0002982F /* Core */,
2859CD971C7CF2020002982F /* Rows */,
287E7D7C1D62552C0065F4DE /* Validations */,
8690E4BC1CFDE02A004CDB1C /* Resources */,
51729E661B9A5FA5004A00EB /* Eureka.h */,
51729DF01B9A4F5E004A00EB /* Info.plist */,
28B12FD41BA0E83C00F27A23 /* Assets.xcassets */,
Expand Down Expand Up @@ -385,15 +382,6 @@
path = Tests;
sourceTree = "<group>";
};
8690E4BC1CFDE02A004CDB1C /* Resources */ = {
isa = PBXGroup;
children = (
8690E4BD1CFDE062004CDB1C /* Eureka.bundle */,
);
name = Resources;
path = Source/Resources;
sourceTree = SOURCE_ROOT;
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -490,7 +478,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8690E4BE1CFDE062004CDB1C /* Eureka.bundle in Resources */,
28B12FD51BA0E83C00F27A23 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
21 changes: 21 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swift-tools-version:5.0
import PackageDescription

let package = Package(
name: "Eureka",
platforms: [.iOS(.v9)],
products: [
.library(name: "Eureka", targets: ["Eureka"])
],
targets: [
.target(
name: "Eureka",
path: "Source"
),
.testTarget(
name: "EurekaTests",
dependencies: ["Eureka"],
path: "Tests"
)
]
)
56 changes: 47 additions & 9 deletions Source/Core/NavigationAccessoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,58 @@ open class NavigationAccessoryView: UIToolbar, NavigationAccessory {
super.init(coder: aDecoder)
}

private func initializeChevrons() {
var bundle = Bundle(for: NavigationAccessoryView.classForCoder())
if let resourcePath = bundle.path(forResource: "Eureka", ofType: "bundle") {
if let resourcesBundle = Bundle(path: resourcePath) {
bundle = resourcesBundle
}
private func drawChevron(pointingRight: Bool) -> UIImage? {
// Hardcoded chevron size
let width = 12
let height = 20

// Begin the image context, with which we are going to draw a chevron
UIGraphicsBeginImageContextWithOptions(CGSize(width: width, height: height), false, 0.0)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
defer {
UIGraphicsEndImageContext()
}

// The chevron looks like > or <. This can be drawn with 3 points; the Y coordinates of the points
// are independant of whether it is to be pointing left or right; the X coordinates will depend, as follows.
// The 1s are to ensure that the point of the chevron does not sit exactly on the edge of the frame, which
// would slightly truncate the point.
let chevronPointXCoordinate, chevronTailsXCoordinate: Int
if pointingRight {
chevronPointXCoordinate = width - 1
chevronTailsXCoordinate = 1
} else {
chevronPointXCoordinate = 1
chevronTailsXCoordinate = width - 1
}

var imageLeftChevron = UIImage(named: "back-chevron", in: bundle, compatibleWith: nil)
var imageRightChevron = UIImage(named: "forward-chevron", in: bundle, compatibleWith: nil)
// Draw the lines and return the image
context.setLineWidth(1.5)
context.setLineCap(.square)
context.strokeLineSegments(between: [
CGPoint(x: chevronTailsXCoordinate, y: 0),
CGPoint(x: chevronPointXCoordinate, y: height / 2),
CGPoint(x: chevronPointXCoordinate, y: height / 2),
CGPoint(x: chevronTailsXCoordinate, y: height)
])

return UIGraphicsGetImageFromCurrentImageContext()
}

private func initializeChevrons() {
var imageLeftChevron, imageRightChevron: UIImage?
if #available(iOS 13.0, *) {
// If we have access to SFSymbols, use the system chevron images, rather than faffing around with our own
imageLeftChevron = UIImage(systemName: "chevron.left")
imageRightChevron = UIImage(systemName: "chevron.right")
} else {
imageLeftChevron = drawChevron(pointingRight: false)
imageRightChevron = drawChevron(pointingRight: true)
}

// RTL language support
imageLeftChevron = imageLeftChevron?.imageFlippedForRightToLeftLayoutDirection()
imageRightChevron = imageRightChevron?.imageFlippedForRightToLeftLayoutDirection()


previousButton = UIBarButtonItem(image: imageLeftChevron, style: .plain, target: self, action: #selector(didTapPrevious))
nextButton = UIBarButtonItem(image: imageRightChevron, style: .plain, target: self, action: #selector(didTapNext))
Expand Down
Binary file removed Source/Resources/Eureka.bundle/[email protected]
Binary file not shown.
Binary file removed Source/Resources/Eureka.bundle/[email protected]
Binary file not shown.
Binary file removed Source/Resources/Eureka.bundle/[email protected]
Binary file not shown.
Binary file removed Source/Resources/Eureka.bundle/[email protected]
Binary file not shown.
Binary file removed Source/Resources/Eureka.bundle/[email protected]
Binary file not shown.
Binary file removed Source/Resources/Eureka.bundle/[email protected]
Binary file not shown.

0 comments on commit 88c156b

Please sign in to comment.