Skip to content

Commit

Permalink
release(0.5.0): migrated to swiftpm / sbPickerSelector Swift
Browse files Browse the repository at this point in the history
  • Loading branch information
CedricGatay committed Nov 16, 2020
1 parent 0c834c1 commit beb2459
Show file tree
Hide file tree
Showing 14 changed files with 524 additions and 47 deletions.
25 changes: 25 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "SnapKit",
"repositoryURL": "https://github.com/SnapKit/SnapKit.git",
"state": {
"branch": null,
"revision": "d458564516e5676af9c70b4f4b2a9178294f1bc6",
"version": "5.0.1"
}
},
{
"package": "UIKitExtensions",
"repositoryURL": "https://github.com/code-troopers/UIKitExtensions",
"state": {
"branch": null,
"revision": "d5a267e7958bc838d06678503d8dbee83d86bc7d",
"version": "0.3.0"
}
}
]
},
"version": 1
}
29 changes: 29 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "iOSFormUtils",
platforms: [
.iOS(.v10)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "iOSFormUtils",
targets: ["iOSFormUtils"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/code-troopers/UIKitExtensions", .upToNextMajor(from: "0.3.0")),
.package(url: "https://github.com/SnapKit/SnapKit.git", .upToNextMajor(from: "5.0.1"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "iOSFormUtils",
dependencies: ["UIKitExtensions", "SnapKit"]),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ open class DateDropDown: DropDown {

override open func loadView() {
super.loadView()

picker.pickerType = .date
picker = SBPickerSwiftSelector(mode: .dateDefault)
/*
picker.pickerType = .date
picker.onlyDayPicker = true
picker.datePickerType = .onlyDay
*/
}
}
46 changes: 22 additions & 24 deletions iOSFormUtils/DropDown.swift → Sources/iOSFormUtils/DropDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import SBPickerSelector
import UIKit
import UIKitExtensions
import SnapKit
Expand Down Expand Up @@ -46,7 +45,7 @@ open class DropDown: OwnView {
}
public var dataSource: DropDownDataSource!

var picker: SBPickerSelector = SBPickerSelector.picker()
var picker: SBPickerSwiftSelector? //FIXME CG = SBPickerSwiftSelector.picker()
var values: [String]!
var currentTextField: TextInput!
public var selectedIndex: Int!
Expand All @@ -63,7 +62,7 @@ open class DropDown: OwnView {
self.addSubview(self.titleTextField)

rightIcon = UIImageView(frame: CGRect())
rightIcon.contentMode = UIViewContentMode.center
rightIcon.contentMode = UIView.ContentMode.center
self.addSubview(rightIcon)

mainButton = UIButton(type: .custom)
Expand All @@ -88,12 +87,11 @@ open class DropDown: OwnView {
self.layoutIfNeeded()
self.layoutSubviews()

picker.delegate = self
picker.pickerType = SBPickerSelectorType.text
picker.doneButtonTitle = "OK"
picker.doneButton?.tintColor = mainColor
picker.cancelButtonTitle = "Annuler"
picker.cancelButton?.tintColor = mainColor
picker = SBPickerSwiftSelector(mode: .text)
picker?.doneButton?.title = "OK"
picker?.doneButton?.tintColor = mainColor
picker?.cancelButton?.title = "Annuler"
picker?.cancelButton?.tintColor = mainColor

updateUI()

Expand All @@ -109,8 +107,8 @@ open class DropDown: OwnView {

func updateUI() {
if let _ = dataSource, let _ = uiDataSource {
picker.doneButton?.tintColor = uiDataSource.getButtonsColor()
picker.cancelButton?.tintColor = uiDataSource.getButtonsColor()
picker?.doneButton?.tintColor = uiDataSource.getButtonsColor()
picker?.cancelButton?.tintColor = uiDataSource.getButtonsColor()

if let existingPlaceholder = dataSource.placeholderKeyForDropDown(self) {
updatePlaceholderWithValue(existingPlaceholder)
Expand All @@ -126,18 +124,18 @@ open class DropDown: OwnView {
titleTextField.attributedPlaceholder = NSAttributedString(
string: value,
attributes: [
NSForegroundColorAttributeName: self.uiDataSource.getPlaceholderColor(),
NSFontAttributeName: UIFont(name: self.uiDataSource.getFontName(), size: self.uiDataSource.getFontSize())!
NSAttributedString.Key.foregroundColor: self.uiDataSource.getPlaceholderColor(),
NSAttributedString.Key.font: UIFont(name: self.uiDataSource.getFontName(), size: self.uiDataSource.getFontSize())!
]
)
}

func updateSelectedIndex(_ newIndex: Int) {
selectedIndex = newIndex
picker.pickerView.selectRow(selectedIndex, inComponent: 0, animated: true)
if let data: [String] = picker.pickerData as? [String] {
picker?.pickerView.selectRow(selectedIndex, inComponent: 0, animated: true)
if let data: [String] = picker?.data as? [String] {
pickerSelector(picker, selectedValue: data[selectedIndex], index: selectedIndex)
picker.pickerView(picker.pickerView, didSelectRow: selectedIndex, inComponent: 0)
picker!.pickerView.delegate?.pickerView?(picker!.pickerView, didSelectRow: selectedIndex, inComponent: 0)
}
}

Expand All @@ -155,7 +153,7 @@ open class DropDown: OwnView {
offset = 1
}

picker.pickerData = values
picker?.data = values
if let dataSourceSelectedIndex: Int = itsDataSource.selectedIndexForDropDown(self) {
updateSelectedIndex(dataSourceSelectedIndex + offset)
}
Expand All @@ -167,15 +165,15 @@ open class DropDown: OwnView {
if let textField = currentTextField {
textField.resignFirstResponder()
}
picker.showPickerOver(itsDataSource.controllerForDropDownDisplaying(self))
picker?.present(into: itsDataSource.controllerForDropDownDisplaying(self))
}
}

func mainButtonTouched(_ sender: AnyObject) {
@objc func mainButtonTouched(_ sender: AnyObject) {
presentDropDown()
}

func textFieldBecameFirstResponder(_ notification: Notification) {
@objc func textFieldBecameFirstResponder(_ notification: Notification) {
if let textField: TextInput = notification.object as? TextInput {
if textField != titleTextField {
currentTextField = textField
Expand All @@ -186,8 +184,8 @@ open class DropDown: OwnView {
}
}

extension DropDown: SBPickerSelectorDelegate {
public func pickerSelector(_ selector: SBPickerSelector!, selectedValue value: String!, index idx: Int) {
extension DropDown /*: SBPickerSelectorDelegate */{
public func pickerSelector(_ selector: SBPickerSwiftSelector!, selectedValue value: String!, index idx: Int) {
let required = (nil != dataSource && !dataSource.isRequired(self))
var offset = 0
if (required && 0 != idx) || !required {
Expand All @@ -212,8 +210,8 @@ extension DropDown: SBPickerSelectorDelegate {
}
}

public func pickerSelector(_ selector: SBPickerSelector!, dateSelected date: Date!) {
if .date == picker.pickerType {
public func pickerSelector(_ selector: SBPickerSwiftSelector!, dateSelected date: Date!) {
if SBPickerSwiftSelector.Mode.dateDefault == picker?.pickerMode {
if let _ = date {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = self.dateFormat
Expand Down
16 changes: 8 additions & 8 deletions iOSFormUtils/Form.swift → Sources/iOSFormUtils/Form.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ open class Form: UIScrollView {
NotificationCenter.default.addObserver(
self,
selector: #selector(Form.keyboardShown(_:)),
name: NSNotification.Name.UIKeyboardDidShow,
name: UIResponder.keyboardDidShowNotification,
object: nil
)

NotificationCenter.default.addObserver(
self,
selector: #selector(Form.keyboardHidden(_:)),
name: NSNotification.Name.UIKeyboardDidHide,
name: UIResponder.keyboardDidHideNotification,
object: nil
)

Expand Down Expand Up @@ -204,7 +204,7 @@ open class Form: UIScrollView {
- Parameter notification: the received notification.
*/
func textFieldReturnedFired(_ notification: Notification) {
@objc func textFieldReturnedFired(_ notification: Notification) {
if let textfield = notification.object as? TextInput {
if isLastInput(textfield) {
textfield.stopEditing()
Expand All @@ -225,7 +225,7 @@ open class Form: UIScrollView {
- Parameter notification: the received notification.
*/
func textFieldResignedFirstResponderFired(_ notification: Notification) {
@objc func textFieldResignedFirstResponderFired(_ notification: Notification) {
resetScrollingZone()
}

Expand All @@ -234,9 +234,9 @@ open class Form: UIScrollView {
- Parameter notification: the received notification
*/
func keyboardShown(_ notification: Notification) {
@objc func keyboardShown(_ notification: Notification) {
let info = (notification as NSNotification).userInfo!
let value: AnyObject = info[UIKeyboardFrameEndUserInfoKey]! as AnyObject
let value: AnyObject = info[UIResponder.keyboardFrameEndUserInfoKey]! as AnyObject

let rawFrame = value.cgRectValue
let keyboardFrame = self.convert(rawFrame!, from: nil)
Expand All @@ -248,7 +248,7 @@ open class Form: UIScrollView {
}
}

func keyboardHidden(_ notification: Notification) {
@objc func keyboardHidden(_ notification: Notification) {
resetScrollingZone()
}

Expand All @@ -257,7 +257,7 @@ open class Form: UIScrollView {
- Parameter notification: the received notification
*/
func textFieldBecameFirstResponder(_ notification: Notification) {
@objc func textFieldBecameFirstResponder(_ notification: Notification) {
if let textfield = notification.object as? TextInput {
currentInput = textfield
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class ImagePicker: UIButton {
}
}

func selfTouched(_ sender: Any) {
@objc func selfTouched(_ sender: Any) {
if let _ = dataSource {
dataSource.controllerForDisplaying().present(actionSheet, animated: true)
} else {
Expand All @@ -82,8 +82,8 @@ public class ImagePicker: UIButton {
}

extension ImagePicker: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
if let _ = delegate {
self.selectedImage = pickedImage
delegate.imagePicker(self, selectedImage: pickedImage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Nicolas LELOUP on 18/09/2015.
// Copyright © 2015 Nicolas LELOUP - Buzznative. All rights reserved.
//
import UIKit

// MARK: Constants
let tfBecameFirstResponderNotifName = "textFieldBecameFirstResponder"
Expand Down Expand Up @@ -105,7 +106,7 @@ extension TextInput: UITextFieldDelegate {

public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if let _ = limit, "" != string {
return textField.text!.characters.count < limit
return textField.text!.count < limit
}

return true
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension TextInput: ValidatedTextInput {
if let _ = validationDataSource {
switch validationDataSource.validationTypeForInput(self) {
case .NotBlank :
if (0 < self.text!.characters.count) {
if (0 < self.text!.count) {
return true
}
case .Email :
Expand Down

0 comments on commit beb2459

Please sign in to comment.