Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Removed SnapKit and SwiftIconFont Dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenTiigi committed Oct 27, 2018
1 parent da6e0c1 commit 489758d
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 201 deletions.
2 changes: 0 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
github "SvenTiigi/FlyoverKit" == 1.2.2
github "SnapKit/SnapKit" == 4.2.0
github "0x73/SwiftIconFont" == 2.9.1
2 changes: 0 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
github "0x73/SwiftIconFont" "2.9.1"
github "SnapKit/SnapKit" "4.2.0"
github "SvenTiigi/FlyoverKit" "1.2.2"
2 changes: 0 additions & 2 deletions STLocationRequest.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ Pod::Spec.new do |s|
s.source_files = 'STLocationRequest/**/*'
s.frameworks = 'UIKit', 'MapKit'
s.dependency 'FlyoverKit', '1.2.2'
s.dependency 'SnapKit', '4.2.0'
s.dependency 'SwiftIconFont', '2.9.1'
end
58 changes: 29 additions & 29 deletions STLocationRequest.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import FlyoverKit
import MapKit
import UIKit
import SwiftIconFont

// MARK: Configuration

Expand Down Expand Up @@ -69,8 +68,6 @@ public extension STLocationRequestController {

/// The Location Symbol which will be displayed in the middle of the STLocationRequestController
public var locationSymbol: LocationSymbol = (
icon: .fontAwesome(code: "locationarrow"),
size: 150,
color: .white,
hidden: false
)
Expand Down Expand Up @@ -137,8 +134,6 @@ public extension STLocationRequestController.Configuration {

/// The LocationSymbol Configuration Type
typealias LocationSymbol = (
icon: SymbolIcon,
size: CGFloat,
color: UIColor,
hidden: Bool
)
Expand All @@ -151,63 +146,3 @@ public extension STLocationRequestController.Configuration {
)

}

// MARK: SymbolIcon

public extension STLocationRequestController.Configuration {

/// The SymbolIcon Enumeration
enum SymbolIcon {
/// FontAwesome
case fontAwesome(code: String)
/// Iconic
case iconic(code: String)
/// Ionicon
case ionicon(code: String)
/// Octicon
case octicon(code: String)
/// Themify
case themify(code: String)
/// MapIcon
case mapIcon(code: String)
/// MaterialIcon
case materialIcon(code: String)
}

}

// MARK: SymbolIcon.RawRepresentable

extension STLocationRequestController.Configuration.SymbolIcon: RawRepresentable {

/// The raw type that can be used to represent all values of the conforming
public typealias RawValue = (font: Fonts, icon: String?)

/// Creates a new instance with the specified raw value.
public init?(rawValue: RawValue) {
// Return nil as no initialization via rawValue is supported
return nil
}

/// /// The corresponding value of the raw type.
public var rawValue: RawValue {
/// Switch on self
switch self {
case .fontAwesome(let code):
return (.fontAwesome, String.fontAwesomeIcon(code))
case .iconic(code: let code):
return (.iconic, String.fontIconicIcon(code))
case .ionicon(code: let code):
return (.ionicon, String.fontIonIcon(code))
case .octicon(code: let code):
return (.octicon, String.fontOcticon(code))
case .themify(code: let code):
return (.themify, String.fontThemifyIcon(code))
case .mapIcon(code: let code):
return (.mapIcon, String.fontMapIcon(code))
case .materialIcon(code: let code):
return (.materialIcon, String.fontMaterialIcon(code))
}
}

}
129 changes: 59 additions & 70 deletions STLocationRequest/Controller/STLocationRequestController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import FlyoverKit
import MapKit
import UIKit
import SnapKit
import SwiftIconFont

/// STLocationRequest is a UIViewController-Extension which is used
/// to request the User-Location, at the very first time, in a simple and elegent way.
Expand Down Expand Up @@ -91,17 +89,22 @@ public class STLocationRequestController: UIViewController {
}()

/// Location Symbol Label
private lazy var locationSymbolLabel: UILabel = {
let label = UILabel()
label.isHidden = self.configuration.locationSymbol.hidden
label.font = UIFont.icon(
from: self.configuration.locationSymbol.icon.rawValue.font,
ofSize: self.configuration.locationSymbol.size
private lazy var locationSymbolLabel: UIImageView = {
let view = UIImageView()
view.contentMode = .center
let image = UIImage(
named: "LocationSymbol.png",
in: Bundle(for: type(of: self)),
compatibleWith: nil
)
label.text = self.configuration.locationSymbol.icon.rawValue.icon
label.textColor = self.configuration.locationSymbol.color
label.textAlignment = .center
return label
if self.configuration.locationSymbol.color == .white {
view.image = image
} else {
let templateImage = image?.withRenderingMode(.alwaysTemplate)
view.image = templateImage
view.tintColor = self.configuration.locationSymbol.color
}
return view
}()

/// The pulse effect
Expand Down Expand Up @@ -173,8 +176,8 @@ public class STLocationRequestController: UIViewController {
self.locationSymbolLabel,
self.allowButton,
self.notNowButton].forEach(self.view.addSubview)
// Layout subview
self.layoutSubviews()
// Add Constraints
self.addConstraints()
// Add layers
self.view.layer.insertSublayer(self.pulseEffect, below: self.locationSymbolLabel.layer)
// Check orientation
Expand All @@ -190,74 +193,60 @@ public class STLocationRequestController: UIViewController {
self.cleanUp()
}

var frame: CGRect {
return self.view.frame
}

/// ViewDidLayoutSubviews
public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// Recenter pulseEffect Layer
self.pulseEffect.position = self.view.center
// Set MapView to full frame size
self.flyoverMapView.frame = self.view.frame
}

/// ViewWillTransition toSize
override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
override public func viewWillTransition(to size: CGSize,
with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
self.checkOrientation()
}

// MARK: Layout

/// Layout Subviews
private func layoutSubviews() {
// MapView
self.flyoverMapView.snp.makeConstraints { (make) in
make.edges.equalTo(self.view)
}
// TitleLabel
self.titleLabel.snp.makeConstraints { (make) in
if #available(iOS 11.0, *) {
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(15)
} else {
make.top.equalTo(self.view).offset(15)
}
if #available(iOS 11.0, *) {
make.width.equalTo(self.view.safeAreaLayoutGuide.snp.width)
} else {
make.width.equalTo(self.view)
}
}
// NotNowButton
self.notNowButton.snp.makeConstraints { (make) in
if #available(iOS 11.0, *) {
make.left.equalTo(self.view.safeAreaLayoutGuide.snp.left).offset(15)
make.right.equalTo(self.view.safeAreaLayoutGuide.snp.right).inset(15)
} else {
make.left.right.equalTo(self.view).offset(15).inset(15)
}
make.height.equalTo(60)
make.bottom.equalTo(self.view).inset(30)
}
// AllowButton
self.allowButton.snp.makeConstraints { (make) in
make.bottom.equalTo(self.notNowButton.snp.top).offset(-10)
if #available(iOS 11.0, *) {
make.left.equalTo(self.view.safeAreaLayoutGuide.snp.left).offset(15)
make.right.equalTo(self.view.safeAreaLayoutGuide.snp.right).inset(15)
} else {
make.left.right.equalTo(self.view).offset(15).inset(15)
}
make.height.equalTo(60)
}
// LocationSymbolLabel
self.locationSymbolLabel.snp.makeConstraints { (make) in
make.top.equalTo(self.titleLabel.snp.bottom).offset(10)
if #available(iOS 11.0, *) {
make.left.equalTo(self.view.safeAreaLayoutGuide.snp.left)
make.right.equalTo(self.view.safeAreaLayoutGuide.snp.right)
} else {
make.left.right.equalTo(self.view)
}
make.centerY.centerX.equalTo(self.view)
make.bottom.equalTo(self.allowButton.snp.top).offset(-10)
}
// MARK: Constraints

/// Add Constraints
private func addConstraints() {
// TitleLabel Constraints
NSLayoutConstraint.activate(on: self.titleLabel, [
self.titleLabel.topAnchor.constraint(equalTo: self.anchor.topAnchor, constant: 15),
self.titleLabel.leadingAnchor.constraint(equalTo: self.anchor.leadingAnchor),
self.titleLabel.trailingAnchor.constraint(equalTo: self.anchor.trailingAnchor),
self.titleLabel.widthAnchor.constraint(equalTo: self.anchor.widthAnchor)
])
// NotNowButton Constraints
NSLayoutConstraint.activate(on: self.notNowButton, [
self.notNowButton.leadingAnchor.constraint(equalTo: self.anchor.leadingAnchor, constant: 15),
self.notNowButton.trailingAnchor.constraint(equalTo: self.anchor.trailingAnchor, constant: -15),
self.notNowButton.heightAnchor.constraint(equalToConstant: 60),
self.notNowButton.bottomAnchor.constraint(equalTo: self.anchor.bottomAnchor, constant: -30)
])
// AllowButton Constraints
NSLayoutConstraint.activate(on: self.allowButton, [
self.allowButton.bottomAnchor.constraint(equalTo: self.notNowButton.topAnchor, constant: -10),
self.allowButton.leadingAnchor.constraint(equalTo: self.anchor.leadingAnchor, constant: 15),
self.allowButton.trailingAnchor.constraint(equalTo: self.anchor.trailingAnchor, constant: -15),
self.allowButton.heightAnchor.constraint(equalToConstant: 60)
])
// LocationSymbolLabel Constraints
NSLayoutConstraint.activate(on: self.locationSymbolLabel, [
self.locationSymbolLabel.topAnchor.constraint(equalTo: self.titleLabel.bottomAnchor, constant: 10),
self.locationSymbolLabel.leadingAnchor.constraint(equalTo: self.anchor.leadingAnchor),
self.locationSymbolLabel.trailingAnchor.constraint(equalTo: self.anchor.trailingAnchor),
self.locationSymbolLabel.centerXAnchor.constraint(equalTo: self.anchor.centerXAnchor),
self.locationSymbolLabel.centerYAnchor.constraint(equalTo: self.anchor.centerYAnchor),
self.locationSymbolLabel.bottomAnchor.constraint(equalTo: self.allowButton.topAnchor, constant: -10)
])
}

}
Expand Down
45 changes: 45 additions & 0 deletions STLocationRequest/Extensions/Anchor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Anchor.swift
// STLocationRequest
//
// Created by Sven Tiigi on 25.10.18.
// Copyright © 2018 Sven Tiigi. All rights reserved.
//

import Foundation

protocol Anchor {

var topAnchor: NSLayoutYAxisAnchor { get }

var bottomAnchor: NSLayoutYAxisAnchor { get }

var leadingAnchor: NSLayoutXAxisAnchor { get }

var trailingAnchor: NSLayoutXAxisAnchor { get }

var widthAnchor: NSLayoutDimension { get }

var heightAnchor: NSLayoutDimension { get }

var centerXAnchor: NSLayoutXAxisAnchor { get }

var centerYAnchor: NSLayoutYAxisAnchor { get }

}

extension UIView: Anchor {}

extension UILayoutGuide: Anchor {}

extension UIViewController {

var anchor: Anchor {
if #available(iOS 11.0, *) {
return self.view.safeAreaLayoutGuide
} else {
return self.view
}
}

}
18 changes: 18 additions & 0 deletions STLocationRequest/Extensions/NSLayoutConstraint+Activate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// NSLayoutConstraint+Activate.swift
// STLocationRequest
//
// Created by Sven Tiigi on 25.10.18.
// Copyright © 2018 Sven Tiigi. All rights reserved.
//

import Foundation

extension NSLayoutConstraint {

static func activate(on view: UIView, _ constraints: [NSLayoutConstraint]) {
view.translatesAutoresizingMaskIntoConstraints = false
self.activate(constraints)
}

}
2 changes: 1 addition & 1 deletion STLocationRequest/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.2.3</string>
<string>3.2.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
Binary file added STLocationRequest/Resources/LocationSymbol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions STLocationRequestExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>STLocationRequest</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>STLocationRequest</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -17,11 +17,15 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.2.3</string>
<string>3.2.2</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationAlwaysUsageDescription</key>
<string>We need your location for some awesome features</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location for some awesome features</string>
<key>UILaunchStoryboardName</key>
<string>Launch Screen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand All @@ -34,10 +38,6 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>We need your location for some awesome features</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location for some awesome features</string>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
Loading

0 comments on commit 489758d

Please sign in to comment.