Skip to content

Instantly share code, notes, and snippets.

View Arrlindii's full-sized avatar

Arlind Aliu Arrlindii

View GitHub Profile
func configureKeyboardListeners() {
NotificationCenter.default.addObserver(forName: Notification.Name.UIKeyboardWillShow, object: nil, queue: nil) { notification in
let keyboardFrame = notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! CGRect
let keyboardHeight: CGFloat = keyboardFrame.height
self.scrollView.contentInset.bottom = keyboardHeight
self.scrollView.scrollIndicatorInsets.bottom = keyboardHeight
}
NotificationCenter.default.addObserver(forName: Notification.Name.UIKeyboardWillHide, object: nil, queue: nil) { notification in
self.scrollView.contentInset.bottom = 0
self.scrollView.scrollIndicatorInsets.bottom = 0
func bindKeyboardEvents() -> Disposable {
let observable =
Observable.from([
NotificationCenter.default.rx.notification(Notification.Name.UIKeyboardWillShow) .map { notification in
let keyboardFrame = notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! CGRect
let keyboardHeight: CGFloat = keyboardFrame.height
return keyboardHeight
},
NotificationCenter.default.rx.notification(Notification.Name.UIKeyboardWillHide) .map { _ in CGFloat(0) }])
.merge()
func viewDidLoad() {
super.viewDidLoad()
scrollView.bindKeyboardEvents().disposed(by: disposeBag)
}
extension UIScrollView {
func loadNextPageObservable() -> Observable<Void> {
return rx.contentOffset
.skipWhile {
$0.y < self.frame.size.height
}.map { contentOffset -> Bool in
let padding = CGFloat(20.0)
return contentOffset.y + self.frame.size.height + padding > self.contentSize.height
}.distinctUntilChanged().map { shouldLoad in
if shouldLoad {
scrollView.loadNextPageObservable().subscribe(onNext: {
//Code that calls network service to perform specific request
}).disposed(by: disposeBag)
func configureDateTextField() {
let datePickerView:UIDatePicker = UIDatePicker()
datePickerView.datePickerMode = UIDatePickerMode.Date
dateTextField.inputView = datePickerView
datePickerView.addTarget(self, action: #selector(ViewController.datePickerValueChanged), forControlEvents: UIControlEvents.ValueChanged)
}
func datePickerValueChanged(sender: UIDatePicker) {
let dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = medium
class DateTextField: UITextField {
var selectedDate: Date?
private let disposeBag = DisposeBag()
override func awakeFromNib() {
super.awakeFromNib()
let datePicker = UIDatePicker()
inputView = datePicker
datePicker.rx.value.asObservable().subscribe(onNext: { date in
self.selectedDate = date
view.rx
.anyGesture(.tap(), .swipe([.up, .down]))
.when(.recognized)
.subscribe(onNext: { _ in
//dismiss presented photo
})
.disposed(by: disposeBag)
//
// CustomExtensions.swift
// Pods-AARxSwiftExtensions
//
// Created by Arlind on 8/12/18.
//
import UIKit
import RxSwift
import CoreLocation
typealias Memento = NSDictionary
protocol MementoConvertible {
var memento: Memento { get }
init?(memento: Memento)
}
struct FormState {
private enum Keys {
static let name = "mainForm.name"