From 21e5272594f98fe97e0732af4c6c162f838493b6 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 3 Jan 2021 12:13:46 +0300 Subject: [PATCH 01/13] Update .gitignore --- .gitignore | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 0316453..9b5cd2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,32 @@ -.DS_Store +# Xcode + sourcekitten-output.json docs/ -/.build -/Packages /*.xcodeproj **/xcuserdata **/xcshareddata -Pods/ -Carthage/ -Examples/**/Podfile.lock *.xcconfig *.framework.zip -.idea/ + +# CocoaPods + +Pods/ +Examples/**/Podfile.lock + +# Carthage + +Carthage/ + +# Various + +.DS_Store + +# Swift Package Manager + +.build/ +Packages/ +.swiftpm + +# AppCode + +.idea/ \ No newline at end of file From 87a91e590ac8dfbf6a455a0a0be2a131b99800ce Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 3 Jan 2021 12:23:59 +0300 Subject: [PATCH 02/13] Updated RxSwift to 6.0 --- Cartfile | 2 +- Cartfile.resolved | 2 +- Example/Podfile.lock | 58 ++++++++++---------- Gemfile | 3 +- Gemfile.lock | 82 +++++++++++++++++------------ Package.resolved | 4 +- Package.swift | 2 +- RxKeyboard.json | 3 +- RxKeyboard.podspec | 8 +-- Sources/RxKeyboard/RxKeyboard.swift | 18 +++---- 10 files changed, 95 insertions(+), 87 deletions(-) diff --git a/Cartfile b/Cartfile index 43e186b..b974c62 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveX/RxSwift" ~> 5.0.0 +github "ReactiveX/RxSwift" ~> 6.0.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index b751e3d..c07923a 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -github "ReactiveX/RxSwift" "5.0.1" +github "ReactiveX/RxSwift" "6.0.0" diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 62472bb..a4d8ab0 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,23 +1,23 @@ PODS: - CGFloatLiteral (0.5.0) - ManualLayout (1.3.0) - - ReusableKit (2.1.0): - - ReusableKit/Core (= 2.1.0) - - ReusableKit/Core (2.1.0) - - RxCocoa (5.0.0): - - RxRelay (~> 5) - - RxSwift (~> 5) - - RxKeyboard (1.0.0): - - RxCocoa (~> 5.0) - - RxSwift (~> 5.0) - - RxRelay (5.0.0): - - RxSwift (~> 5) - - RxSwift (5.0.0) - - SnapKit (5.0.0) - - SwiftyColor (1.2.0) - - SwiftyImage (1.5.0) - - Then (2.4.0) - - "UITextView+Placeholder (1.2.1)" + - ReusableKit (3.0.0): + - ReusableKit/Core (= 3.0.0) + - ReusableKit/Core (3.0.0) + - RxCocoa (6.0.0): + - RxRelay (= 6.0.0) + - RxSwift (= 6.0.0) + - RxKeyboard (2.0.0): + - RxCocoa (~> 6.0) + - RxSwift (~> 6.0) + - RxRelay (6.0.0): + - RxSwift (= 6.0.0) + - RxSwift (6.0.0) + - SnapKit (5.0.1) + - SwiftyColor (1.2.1) + - SwiftyImage (1.6.0) + - Then (2.7.0) + - "UITextView+Placeholder (1.4.0)" DEPENDENCIES: - CGFloatLiteral @@ -31,7 +31,7 @@ DEPENDENCIES: - "UITextView+Placeholder" SPEC REPOS: - https://github.com/cocoapods/specs.git: + trunk: - CGFloatLiteral - ManualLayout - ReusableKit @@ -51,17 +51,17 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: CGFloatLiteral: 0328648f666e3cb2263d5ee3972df9d320786d25 ManualLayout: 68ac8cfa6b5f656f7a9fadec3730208b95986880 - ReusableKit: d0b040de03b293288b0ca27a78602691d3346d9b - RxCocoa: fcf32050ac00d801f34a7f71d5e8e7f23026dcd8 - RxKeyboard: 6683c4344304a00f943c158bd8a43ce5469c82a7 - RxRelay: 4f7409406a51a55cd88483f21ed898c234d60f18 - RxSwift: 8b0671caa829a763bbce7271095859121cbd895f - SnapKit: fd22d10eb9aff484d79a8724eab922c1ddf89bcf - SwiftyColor: ac23e6c0b561838c1ef0f554ff170cceba14546b - SwiftyImage: b4f0523c4a775c79c45dd328f42ed9b3111d5898 - Then: 71866660c7af35a7343831f7668e7cd2b62ee0f2 - "UITextView+Placeholder": 0c3efd97f37ea64bde7f34cc6e90fe02e87b3909 + ReusableKit: e5f853ad4652e411f96b6119b2488afa12929be6 + RxCocoa: 3f79328fafa3645b34600f37c31e64c73ae3a80e + RxKeyboard: 268e4ed61c03b730c8ca71aa1cb2de40a7848b21 + RxRelay: 8d593be109c06ea850df027351beba614b012ffb + RxSwift: c14e798c59b9f6e9a2df8fd235602e85cc044295 + SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb + SwiftyColor: a2f468071c1b96be1ba41a0be7cf70d645cd7dcc + SwiftyImage: 65c71a147f417fc0fe137d17b135aaa666279a09 + Then: acfe0be7e98221c6204e12f8161459606d5d822d + "UITextView+Placeholder": d7b0c400921f66523f3a85d74f774512e14f6502 PODFILE CHECKSUM: 217b0b1c7b2faddc54272a5bde63843c54f48190 -COCOAPODS: 1.6.1 +COCOAPODS: 1.10.0 diff --git a/Gemfile b/Gemfile index 9775661..e1552a2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,4 @@ source 'https://rubygems.org' -ruby '~> 2.3' -gem 'cocoapods', '~> 1.6' +gem 'cocoapods', '~> 1.10' gem 'swiftproj' diff --git a/Gemfile.lock b/Gemfile.lock index 338a7d7..f371d71 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,83 +1,97 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (3.0.0) - activesupport (4.2.11.1) - i18n (~> 0.7) + CFPropertyList (3.0.3) + activesupport (5.2.4.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + algoliasearch (1.27.5) + httpclient (~> 2.8, >= 2.8.3) + json (>= 1.5.1) atomos (0.1.3) - claide (1.0.2) - cocoapods (1.6.2) - activesupport (>= 4.0.2, < 5) + claide (1.0.3) + cocoapods (1.10.0) + addressable (~> 2.6) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.6.2) - cocoapods-deintegrate (>= 1.0.2, < 2.0) - cocoapods-downloader (>= 1.2.2, < 2.0) + cocoapods-core (= 1.10.0) + cocoapods-deintegrate (>= 1.0.3, < 2.0) + cocoapods-downloader (>= 1.4.0, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) - cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.3.1, < 2.0) + cocoapods-trunk (>= 1.4.0, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) escape (~> 0.0.4) - fourflusher (>= 2.2.0, < 3.0) + fourflusher (>= 2.3.0, < 3.0) gh_inspector (~> 1.0) molinillo (~> 0.6.6) nap (~> 1.0) ruby-macho (~> 1.4) - xcodeproj (>= 1.8.1, < 2.0) - cocoapods-core (1.6.2) - activesupport (>= 4.0.2, < 6) + xcodeproj (>= 1.19.0, < 2.0) + cocoapods-core (1.10.0) + activesupport (> 5.0, < 6) + addressable (~> 2.6) + algoliasearch (~> 1.0) + concurrent-ruby (~> 1.1) fuzzy_match (~> 2.0.4) nap (~> 1.0) + netrc (~> 0.11) + public_suffix + typhoeus (~> 1.0) cocoapods-deintegrate (1.0.4) - cocoapods-downloader (1.2.2) + cocoapods-downloader (1.4.0) cocoapods-plugins (1.0.0) nap cocoapods-search (1.0.0) - cocoapods-stats (1.1.0) - cocoapods-trunk (1.3.1) + cocoapods-trunk (1.5.0) nap (>= 0.8, < 2.0) netrc (~> 0.11) - cocoapods-try (1.1.0) + cocoapods-try (1.2.0) colored2 (3.1.2) - concurrent-ruby (1.1.5) + concurrent-ruby (1.1.7) escape (0.0.4) - fourflusher (2.2.0) + ethon (0.12.0) + ffi (>= 1.3.0) + ffi (1.14.2) + fourflusher (2.3.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) - i18n (0.9.5) + httpclient (2.8.3) + i18n (1.8.6) concurrent-ruby (~> 1.0) - minitest (5.11.3) + json (2.5.1) + minitest (5.14.2) molinillo (0.6.6) - nanaimo (0.2.6) + nanaimo (0.3.0) nap (1.1.0) netrc (0.11.0) + public_suffix (4.0.6) ruby-macho (1.4.0) swiftproj (0.1.0) colored2 (>= 3.0) xcodeproj (>= 1.5) thread_safe (0.3.6) - tzinfo (1.2.5) + typhoeus (1.4.0) + ethon (>= 0.9.0) + tzinfo (1.2.9) thread_safe (~> 0.1) - xcodeproj (1.9.0) + xcodeproj (1.19.0) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) - nanaimo (~> 0.2.6) + nanaimo (~> 0.3.0) PLATFORMS - ruby + universal-darwin-19 DEPENDENCIES - cocoapods (~> 1.6) + cocoapods (~> 1.10) swiftproj -RUBY VERSION - ruby 2.3.1p112 - BUNDLED WITH - 1.17.3 + 2.2.4 diff --git a/Package.resolved b/Package.resolved index e3afef8..c620799 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/ReactiveX/RxSwift.git", "state": { "branch": null, - "revision": "b3e888b4972d9bc76495dd74d30a8c7fad4b9395", - "version": "5.0.1" + "revision": "c8742ed97fc2f0c015a5ea5eddefb064cd7532d2", + "version": "6.0.0" } } ] diff --git a/Package.swift b/Package.swift index 8ba3d39..0a38f25 100644 --- a/Package.swift +++ b/Package.swift @@ -8,7 +8,7 @@ let package = Package( .library(name: "RxKeyboard", targets: ["RxKeyboard"]), ], dependencies: [ - .package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "5.0.0")), + .package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.0.0")), ], targets: [ .target(name: "RxKeyboard", dependencies: ["RxSwift", "RxCocoa"]), diff --git a/RxKeyboard.json b/RxKeyboard.json index 63c1d87..06a1ab8 100644 --- a/RxKeyboard.json +++ b/RxKeyboard.json @@ -8,5 +8,6 @@ "0.9.0": "https://github.com/RxSwiftCommunity/RxKeyboard/releases/download/0.9.0/RxKeyboard.framework.zip", "0.9.1": "https://github.com/RxSwiftCommunity/RxKeyboard/releases/download/0.9.1/RxKeyboard.framework.zip", "0.9.2": "https://github.com/RxSwiftCommunity/RxKeyboard/releases/download/0.9.2/RxKeyboard.framework.zip", - "1.0.0": "https://github.com/RxSwiftCommunity/RxKeyboard/releases/download/1.0.0/RxKeyboard.framework.zip" + "1.0.0": "https://github.com/RxSwiftCommunity/RxKeyboard/releases/download/1.0.0/RxKeyboard.framework.zip", + "2.0.0": "https://github.com/RxSwiftCommunity/RxKeyboard/releases/download/2.0.0/RxKeyboard.framework.zip", } diff --git a/RxKeyboard.podspec b/RxKeyboard.podspec index afff4c5..2490b8b 100644 --- a/RxKeyboard.podspec +++ b/RxKeyboard.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'RxKeyboard' - s.version = '1.0.0' + s.version = '2.0.0' s.summary = 'Reactive Keyboard in iOS' s.homepage = 'https://github.com/RxSwiftCommunity/RxKeyboard' s.license = { :type => 'MIT', :file => 'LICENSE' } @@ -12,8 +12,8 @@ Pod::Spec.new do |s| s.requires_arc = true s.swift_version = "5.0" - s.dependency 'RxSwift', '~> 5.0' - s.dependency 'RxCocoa', '~> 5.0' + s.dependency 'RxSwift', '~> 6.0' + s.dependency 'RxCocoa', '~> 6.0' - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '9.0' end diff --git a/Sources/RxKeyboard/RxKeyboard.swift b/Sources/RxKeyboard/RxKeyboard.swift index 9563576..261054c 100644 --- a/Sources/RxKeyboard/RxKeyboard.swift +++ b/Sources/RxKeyboard/RxKeyboard.swift @@ -50,17 +50,10 @@ public class RxKeyboard: NSObject, RxKeyboardType { // MARK: Initializing override init() { - #if swift(>=4.2) - let keyboardWillChangeFrame = UIResponder.keyboardWillChangeFrameNotification - let keyboardWillHide = UIResponder.keyboardWillHideNotification - let keyboardFrameEndKey = UIResponder.keyboardFrameEndUserInfoKey - let applicationDidFinishLaunching = UIApplication.didFinishLaunchingNotification - #else - let keyboardWillChangeFrame = NSNotification.Name.UIKeyboardWillChangeFrame - let keyboardWillHide = NSNotification.Name.UIKeyboardWillHide - let keyboardFrameEndKey = UIKeyboardFrameEndUserInfoKey - let applicationDidFinishLaunching = NSNotification.Name.UIApplicationDidFinishLaunching - #endif + + let keyboardWillChangeFrame = UIResponder.keyboardWillChangeFrameNotification + let keyboardWillHide = UIResponder.keyboardWillHideNotification + let keyboardFrameEndKey = UIResponder.keyboardFrameEndUserInfoKey let defaultFrame = CGRect( x: 0, @@ -131,7 +124,8 @@ public class RxKeyboard: NSObject, RxKeyboardType { // gesture recognizer self.panRecognizer.delegate = self - NotificationCenter.default.rx.notification(applicationDidFinishLaunching) + + UIApplication.rx.didFinishLaunching .map { _ in Void() } .startWith(Void()) // when RxKeyboard is initialized before UIApplication.window is created .subscribe(onNext: { _ in From 0d6f2f17233cf65699fb3f0884276f1d7e14e92f Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 3 Jan 2021 12:50:38 +0300 Subject: [PATCH 03/13] Remove void --- Sources/RxKeyboard/RxKeyboard.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/RxKeyboard/RxKeyboard.swift b/Sources/RxKeyboard/RxKeyboard.swift index 261054c..f8c2582 100644 --- a/Sources/RxKeyboard/RxKeyboard.swift +++ b/Sources/RxKeyboard/RxKeyboard.swift @@ -126,8 +126,8 @@ public class RxKeyboard: NSObject, RxKeyboardType { self.panRecognizer.delegate = self UIApplication.rx.didFinishLaunching - .map { _ in Void() } - .startWith(Void()) // when RxKeyboard is initialized before UIApplication.window is created + .map { _ in () } + .startWith(()) // when RxKeyboard is initialized before UIApplication.window is created .subscribe(onNext: { _ in UIApplication.shared.windows.first?.addGestureRecognizer(self.panRecognizer) }) From b5739549a88ba5786083ae877da8af4f505d7896 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 3 Jan 2021 13:03:16 +0300 Subject: [PATCH 04/13] Update Package.swift - add platforms --- Package.swift | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Package.swift b/Package.swift index 0a38f25..d8ae64f 100644 --- a/Package.swift +++ b/Package.swift @@ -3,14 +3,17 @@ import PackageDescription let package = Package( - name: "RxKeyboard", - products: [ - .library(name: "RxKeyboard", targets: ["RxKeyboard"]), - ], - dependencies: [ - .package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.0.0")), - ], - targets: [ - .target(name: "RxKeyboard", dependencies: ["RxSwift", "RxCocoa"]), - ] + name: "RxKeyboard", + platforms: [ + .macOS(.v10_12), .iOS(.v10), .tvOS(.v10), .watchOS(.v3) + ], + products: [ + .library(name: "RxKeyboard", targets: ["RxKeyboard"]), + ], + dependencies: [ + .package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.0.0")), + ], + targets: [ + .target(name: "RxKeyboard", dependencies: ["RxSwift", "RxCocoa"]), + ] ) From 62d8fccaae16ec922941b5ada01e7bbfa140714a Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 3 Jan 2021 18:04:37 +0300 Subject: [PATCH 05/13] Correct indent and remove unused code --- Example/Podfile.lock | 2 +- Package.swift | 4 +- RxKeyboard.podspec | 4 +- Sources/RxKeyboard/RxKeyboard.swift | 285 +++++++++++++++------------- 4 files changed, 154 insertions(+), 141 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index a4d8ab0..cd88f7f 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -53,7 +53,7 @@ SPEC CHECKSUMS: ManualLayout: 68ac8cfa6b5f656f7a9fadec3730208b95986880 ReusableKit: e5f853ad4652e411f96b6119b2488afa12929be6 RxCocoa: 3f79328fafa3645b34600f37c31e64c73ae3a80e - RxKeyboard: 268e4ed61c03b730c8ca71aa1cb2de40a7848b21 + RxKeyboard: 4f5863f43b4ff0cbb2a20b94688d6b80c8a43c14 RxRelay: 8d593be109c06ea850df027351beba614b012ffb RxSwift: c14e798c59b9f6e9a2df8fd235602e85cc044295 SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb diff --git a/Package.swift b/Package.swift index d8ae64f..99d8db3 100644 --- a/Package.swift +++ b/Package.swift @@ -1,11 +1,11 @@ -// swift-tools-version:5.0 +// swift-tools-version:5.1 import PackageDescription let package = Package( name: "RxKeyboard", platforms: [ - .macOS(.v10_12), .iOS(.v10), .tvOS(.v10), .watchOS(.v3) + .iOS(.v10) ], products: [ .library(name: "RxKeyboard", targets: ["RxKeyboard"]), diff --git a/RxKeyboard.podspec b/RxKeyboard.podspec index 2490b8b..a2d8890 100644 --- a/RxKeyboard.podspec +++ b/RxKeyboard.podspec @@ -8,9 +8,9 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/RxSwiftCommunity/RxKeyboard.git', :tag => s.version.to_s } s.source_files = 'Sources/**/*.swift' - s.frameworks = 'UIKit', 'Foundation' + s.frameworks = 'UIKit' s.requires_arc = true - s.swift_version = "5.0" + s.swift_version = "5.1" s.dependency 'RxSwift', '~> 6.0' s.dependency 'RxCocoa', '~> 6.0' diff --git a/Sources/RxKeyboard/RxKeyboard.swift b/Sources/RxKeyboard/RxKeyboard.swift index f8c2582..7267baa 100644 --- a/Sources/RxKeyboard/RxKeyboard.swift +++ b/Sources/RxKeyboard/RxKeyboard.swift @@ -13,127 +13,130 @@ import RxCocoa import RxSwift public protocol RxKeyboardType { - var frame: Driver { get } - var visibleHeight: Driver { get } - var willShowVisibleHeight: Driver { get } - var isHidden: Driver { get } + var frame: Driver { get } + var visibleHeight: Driver { get } + var willShowVisibleHeight: Driver { get } + var isHidden: Driver { get } } /// RxKeyboard provides a reactive way of observing keyboard frame changes. public class RxKeyboard: NSObject, RxKeyboardType { - // MARK: Public - - /// Get a singleton instance. - public static let instance = RxKeyboard() - - /// An observable keyboard frame. - public let frame: Driver - - /// An observable visible height of keyboard. Emits keyboard height if the keyboard is visible - /// or `0` if the keyboard is not visible. - public let visibleHeight: Driver - - /// Same with `visibleHeight` but only emits values when keyboard is about to show. This is - /// useful when adjusting scroll view content offset. - public let willShowVisibleHeight: Driver - - /// An observable visibility of keyboard. Emits keyboard visibility - /// when changed keyboard show and hide. - public let isHidden: Driver - - // MARK: Private - - private let disposeBag = DisposeBag() - private let panRecognizer = UIPanGestureRecognizer() - - // MARK: Initializing - - override init() { - - let keyboardWillChangeFrame = UIResponder.keyboardWillChangeFrameNotification - let keyboardWillHide = UIResponder.keyboardWillHideNotification - let keyboardFrameEndKey = UIResponder.keyboardFrameEndUserInfoKey - - let defaultFrame = CGRect( - x: 0, - y: UIScreen.main.bounds.height, - width: UIScreen.main.bounds.width, - height: 0 - ) - let frameVariable = BehaviorRelay(value: defaultFrame) - self.frame = frameVariable.asDriver().distinctUntilChanged() - self.visibleHeight = self.frame.map { UIScreen.main.bounds.height - $0.origin.y } - self.willShowVisibleHeight = self.visibleHeight - .scan((visibleHeight: 0, isShowing: false)) { lastState, newVisibleHeight in - return (visibleHeight: newVisibleHeight, isShowing: lastState.visibleHeight == 0 && newVisibleHeight > 0) - } - .filter { state in state.isShowing } - .map { state in state.visibleHeight } - self.isHidden = self.visibleHeight.map({ $0 == 0.0 }).distinctUntilChanged() - super.init() - - // keyboard will change frame - let willChangeFrame = NotificationCenter.default.rx.notification(keyboardWillChangeFrame) - .map { notification -> CGRect in - let rectValue = notification.userInfo?[keyboardFrameEndKey] as? NSValue - return rectValue?.cgRectValue ?? defaultFrame - } - .map { frame -> CGRect in - if frame.origin.y < 0 { // if went to wrong frame - var newFrame = frame - newFrame.origin.y = UIScreen.main.bounds.height - newFrame.height - return newFrame - } - return frame - } - - // keyboard will hide - let willHide = NotificationCenter.default.rx.notification(keyboardWillHide) - .map { notification -> CGRect in - let rectValue = notification.userInfo?[keyboardFrameEndKey] as? NSValue - return rectValue?.cgRectValue ?? defaultFrame - } - .map { frame -> CGRect in - if frame.origin.y < 0 { // if went to wrong frame - var newFrame = frame - newFrame.origin.y = UIScreen.main.bounds.height - return newFrame - } - return frame - } - - // pan gesture - let didPan = self.panRecognizer.rx.event - .withLatestFrom(frameVariable.asObservable()) { ($0, $1) } - .flatMap { (gestureRecognizer, frame) -> Observable in - guard case .changed = gestureRecognizer.state, - let window = UIApplication.shared.windows.first, - frame.origin.y < UIScreen.main.bounds.height - else { return .empty() } - let origin = gestureRecognizer.location(in: window) - var newFrame = frame - newFrame.origin.y = max(origin.y, UIScreen.main.bounds.height - frame.height) - return .just(newFrame) - } - - // merge into single sequence - Observable.of(didPan, willChangeFrame, willHide).merge() - .bind(to: frameVariable) - .disposed(by: self.disposeBag) - - // gesture recognizer - self.panRecognizer.delegate = self - - UIApplication.rx.didFinishLaunching - .map { _ in () } - .startWith(()) // when RxKeyboard is initialized before UIApplication.window is created - .subscribe(onNext: { _ in - UIApplication.shared.windows.first?.addGestureRecognizer(self.panRecognizer) - }) - .disposed(by: self.disposeBag) - } - + // MARK: Public + + /// Get a singleton instance. + public static let instance = RxKeyboard() + + /// An observable keyboard frame. + public let frame: Driver + + /// An observable visible height of keyboard. Emits keyboard height if the keyboard is visible + /// or `0` if the keyboard is not visible. + public let visibleHeight: Driver + + /// Same with `visibleHeight` but only emits values when keyboard is about to show. This is + /// useful when adjusting scroll view content offset. + public let willShowVisibleHeight: Driver + + /// An observable visibility of keyboard. Emits keyboard visibility + /// when changed keyboard show and hide. + public let isHidden: Driver + + // MARK: Private + + private let disposeBag = DisposeBag() + private let panRecognizer = UIPanGestureRecognizer() + + // MARK: Initializing + + override init() { + + let defaultFrame = CGRect( + x: .zero, + y: UIScreen.main.bounds.height, + width: UIScreen.main.bounds.width, + height: .zero + ) + + let frameVariable = BehaviorRelay(value: defaultFrame) + + frame = frameVariable.asDriver().distinctUntilChanged() + visibleHeight = frame.map { UIScreen.main.bounds.height - $0.origin.y } + + willShowVisibleHeight = visibleHeight + .scan((visibleHeight: .zero, isShowing: false)) { lastState, newVisibleHeight in + (visibleHeight: newVisibleHeight, isShowing: lastState.visibleHeight <= .zero && newVisibleHeight > .zero) + } + .filter { $0.isShowing } + .map { $0.visibleHeight } + + isHidden = visibleHeight + .map { $0 <= .ulpOfOne } + .distinctUntilChanged() + + super.init() + + // keyboard will change frame + let willChangeFrame = NotificationCenter.default.rx.notification(.keyboardWillChangeFrame) + .map { notification -> CGRect in + let rectValue = notification.userInfo?[String.keyboardFrameEndKey] as? NSValue + return rectValue?.cgRectValue ?? defaultFrame + } + .map { frame -> CGRect in + if frame.origin.y < .zero { // if went to wrong frame + var newFrame = frame + newFrame.origin.y = UIScreen.main.bounds.height - newFrame.height + return newFrame + } + return frame + } + + // keyboard will hide + let willHide = NotificationCenter.default.rx.notification(.keyboardWillHide) + .map { notification -> CGRect in + let rectValue = notification.userInfo?[String.keyboardFrameEndKey] as? NSValue + return rectValue?.cgRectValue ?? defaultFrame + } + .map { frame -> CGRect in + if frame.origin.y < .zero { // if went to wrong frame + var newFrame = frame + newFrame.origin.y = UIScreen.main.bounds.height + return newFrame + } + return frame + } + + // pan gesture + let didPan = panRecognizer.rx.event + .withLatestFrom(frameVariable.asObservable()) { ($0, $1) } + .flatMap { (gestureRecognizer, frame) -> Observable in + guard case .changed = gestureRecognizer.state, + let window = UIApplication.shared.windows.first, + frame.origin.y < UIScreen.main.bounds.height else { + return .empty() + } + + let origin = gestureRecognizer.location(in: window) + var newFrame = frame + newFrame.origin.y = max(origin.y, UIScreen.main.bounds.height - frame.height) + return .just(newFrame) + } + + // merge into single sequence + Observable.merge(didPan, willChangeFrame, willHide) + .bind(to: frameVariable) + .disposed(by: disposeBag) + + // gesture recognizer + panRecognizer.delegate = self + + UIApplication.rx.didFinishLaunching // when RxKeyboard is initialized before UIApplication.window is created + .withUnretained(panRecognizer) + .subscribe { gestureRecognizer, _ in + UIApplication.shared.windows.first?.addGestureRecognizer(gestureRecognizer) + } + .disposed(by: disposeBag) + } } @@ -141,29 +144,39 @@ public class RxKeyboard: NSObject, RxKeyboardType { extension RxKeyboard: UIGestureRecognizerDelegate { - public func gestureRecognizer( - _ gestureRecognizer: UIGestureRecognizer, - shouldReceive touch: UITouch - ) -> Bool { - let point = touch.location(in: gestureRecognizer.view) - var view = gestureRecognizer.view?.hitTest(point, with: nil) - while let candidate = view { - if let scrollView = candidate as? UIScrollView, - case .interactive = scrollView.keyboardDismissMode { - return true - } - view = candidate.superview + public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { + let point = touch.location(in: gestureRecognizer.view) + var view = gestureRecognizer.view?.hitTest(point, with: nil) + + while let candidate = view { + if let scrollView = candidate as? UIScrollView, + case .interactive = scrollView.keyboardDismissMode { + return true + } + view = candidate.superview + } + + return false } - return false - } - public func gestureRecognizer( - _ gestureRecognizer: UIGestureRecognizer, - shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer - ) -> Bool { - return gestureRecognizer === self.panRecognizer - } + public func gestureRecognizer( + _ gestureRecognizer: UIGestureRecognizer, + shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer + ) -> Bool { + gestureRecognizer === panRecognizer + } +} + +private extension Notification.Name { + + static let keyboardWillChangeFrame = UIResponder.keyboardWillChangeFrameNotification + static let keyboardWillHide = UIResponder.keyboardWillHideNotification +} + +private extension String { + static let keyboardFrameEndKey = UIResponder.keyboardFrameEndUserInfoKey } + #endif From d70c2d782467b1247e0a5771ff6cdaa24b8623c6 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 3 Jan 2021 18:10:25 +0300 Subject: [PATCH 06/13] Revert s.swift_version to 5.0 --- RxKeyboard.podspec | 4 ++-- Sources/RxKeyboard/RxKeyboard.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RxKeyboard.podspec b/RxKeyboard.podspec index a2d8890..bef65ec 100644 --- a/RxKeyboard.podspec +++ b/RxKeyboard.podspec @@ -10,10 +10,10 @@ Pod::Spec.new do |s| s.source_files = 'Sources/**/*.swift' s.frameworks = 'UIKit' s.requires_arc = true - s.swift_version = "5.1" + s.swift_version = "5.0" s.dependency 'RxSwift', '~> 6.0' s.dependency 'RxCocoa', '~> 6.0' - s.ios.deployment_target = '9.0' + s.ios.deployment_target = '10.0' end diff --git a/Sources/RxKeyboard/RxKeyboard.swift b/Sources/RxKeyboard/RxKeyboard.swift index 7267baa..ef63406 100644 --- a/Sources/RxKeyboard/RxKeyboard.swift +++ b/Sources/RxKeyboard/RxKeyboard.swift @@ -163,7 +163,7 @@ extension RxKeyboard: UIGestureRecognizerDelegate { _ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer ) -> Bool { - gestureRecognizer === panRecognizer + return gestureRecognizer === panRecognizer } } From 62e9c997c4d48752cc78cacd528957ecb3d83d2e Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 3 Jan 2021 18:11:52 +0300 Subject: [PATCH 07/13] Revert swift-tools-version to 5.0 --- Example/Podfile.lock | 2 +- Package.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index cd88f7f..57b3a17 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -53,7 +53,7 @@ SPEC CHECKSUMS: ManualLayout: 68ac8cfa6b5f656f7a9fadec3730208b95986880 ReusableKit: e5f853ad4652e411f96b6119b2488afa12929be6 RxCocoa: 3f79328fafa3645b34600f37c31e64c73ae3a80e - RxKeyboard: 4f5863f43b4ff0cbb2a20b94688d6b80c8a43c14 + RxKeyboard: 63595f98880901578c019beabc4df74b424ebe1d RxRelay: 8d593be109c06ea850df027351beba614b012ffb RxSwift: c14e798c59b9f6e9a2df8fd235602e85cc044295 SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb diff --git a/Package.swift b/Package.swift index 99d8db3..abf8a23 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:5.0 import PackageDescription From 89a0830a414dbb20a17662e6f1c4728c47c4f8f1 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 4 Jan 2021 17:52:14 +0300 Subject: [PATCH 08/13] Revert code indentation and #98 --- Example/Podfile.lock | 2 +- Package.swift | 2 +- RxKeyboard.podspec | 2 +- Sources/RxKeyboard/RxKeyboard.swift | 283 +++++++++++++--------------- 4 files changed, 137 insertions(+), 152 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 57b3a17..1f3b880 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -53,7 +53,7 @@ SPEC CHECKSUMS: ManualLayout: 68ac8cfa6b5f656f7a9fadec3730208b95986880 ReusableKit: e5f853ad4652e411f96b6119b2488afa12929be6 RxCocoa: 3f79328fafa3645b34600f37c31e64c73ae3a80e - RxKeyboard: 63595f98880901578c019beabc4df74b424ebe1d + RxKeyboard: aefd4787ca8be28a4470cb871141fb50e105f900 RxRelay: 8d593be109c06ea850df027351beba614b012ffb RxSwift: c14e798c59b9f6e9a2df8fd235602e85cc044295 SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb diff --git a/Package.swift b/Package.swift index abf8a23..fff07b0 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "RxKeyboard", platforms: [ - .iOS(.v10) + .iOS(.v9) ], products: [ .library(name: "RxKeyboard", targets: ["RxKeyboard"]), diff --git a/RxKeyboard.podspec b/RxKeyboard.podspec index bef65ec..a1e64aa 100644 --- a/RxKeyboard.podspec +++ b/RxKeyboard.podspec @@ -15,5 +15,5 @@ Pod::Spec.new do |s| s.dependency 'RxSwift', '~> 6.0' s.dependency 'RxCocoa', '~> 6.0' - s.ios.deployment_target = '10.0' + s.ios.deployment_target = '9.0' end diff --git a/Sources/RxKeyboard/RxKeyboard.swift b/Sources/RxKeyboard/RxKeyboard.swift index ef63406..f92ad2b 100644 --- a/Sources/RxKeyboard/RxKeyboard.swift +++ b/Sources/RxKeyboard/RxKeyboard.swift @@ -13,130 +13,125 @@ import RxCocoa import RxSwift public protocol RxKeyboardType { - var frame: Driver { get } - var visibleHeight: Driver { get } - var willShowVisibleHeight: Driver { get } - var isHidden: Driver { get } + var frame: Driver { get } + var visibleHeight: Driver { get } + var willShowVisibleHeight: Driver { get } + var isHidden: Driver { get } } /// RxKeyboard provides a reactive way of observing keyboard frame changes. public class RxKeyboard: NSObject, RxKeyboardType { - // MARK: Public - - /// Get a singleton instance. - public static let instance = RxKeyboard() - - /// An observable keyboard frame. - public let frame: Driver - - /// An observable visible height of keyboard. Emits keyboard height if the keyboard is visible - /// or `0` if the keyboard is not visible. - public let visibleHeight: Driver - - /// Same with `visibleHeight` but only emits values when keyboard is about to show. This is - /// useful when adjusting scroll view content offset. - public let willShowVisibleHeight: Driver - - /// An observable visibility of keyboard. Emits keyboard visibility - /// when changed keyboard show and hide. - public let isHidden: Driver - - // MARK: Private - - private let disposeBag = DisposeBag() - private let panRecognizer = UIPanGestureRecognizer() - - // MARK: Initializing - - override init() { - - let defaultFrame = CGRect( - x: .zero, - y: UIScreen.main.bounds.height, - width: UIScreen.main.bounds.width, - height: .zero - ) - - let frameVariable = BehaviorRelay(value: defaultFrame) - - frame = frameVariable.asDriver().distinctUntilChanged() - visibleHeight = frame.map { UIScreen.main.bounds.height - $0.origin.y } - - willShowVisibleHeight = visibleHeight - .scan((visibleHeight: .zero, isShowing: false)) { lastState, newVisibleHeight in - (visibleHeight: newVisibleHeight, isShowing: lastState.visibleHeight <= .zero && newVisibleHeight > .zero) - } - .filter { $0.isShowing } - .map { $0.visibleHeight } - - isHidden = visibleHeight - .map { $0 <= .ulpOfOne } - .distinctUntilChanged() - - super.init() - - // keyboard will change frame - let willChangeFrame = NotificationCenter.default.rx.notification(.keyboardWillChangeFrame) - .map { notification -> CGRect in - let rectValue = notification.userInfo?[String.keyboardFrameEndKey] as? NSValue - return rectValue?.cgRectValue ?? defaultFrame - } - .map { frame -> CGRect in - if frame.origin.y < .zero { // if went to wrong frame - var newFrame = frame - newFrame.origin.y = UIScreen.main.bounds.height - newFrame.height - return newFrame - } - return frame - } - - // keyboard will hide - let willHide = NotificationCenter.default.rx.notification(.keyboardWillHide) - .map { notification -> CGRect in - let rectValue = notification.userInfo?[String.keyboardFrameEndKey] as? NSValue - return rectValue?.cgRectValue ?? defaultFrame - } - .map { frame -> CGRect in - if frame.origin.y < .zero { // if went to wrong frame - var newFrame = frame - newFrame.origin.y = UIScreen.main.bounds.height - return newFrame - } - return frame - } - - // pan gesture - let didPan = panRecognizer.rx.event - .withLatestFrom(frameVariable.asObservable()) { ($0, $1) } - .flatMap { (gestureRecognizer, frame) -> Observable in - guard case .changed = gestureRecognizer.state, - let window = UIApplication.shared.windows.first, - frame.origin.y < UIScreen.main.bounds.height else { - return .empty() - } - - let origin = gestureRecognizer.location(in: window) - var newFrame = frame - newFrame.origin.y = max(origin.y, UIScreen.main.bounds.height - frame.height) - return .just(newFrame) - } - - // merge into single sequence - Observable.merge(didPan, willChangeFrame, willHide) - .bind(to: frameVariable) - .disposed(by: disposeBag) - - // gesture recognizer - panRecognizer.delegate = self - - UIApplication.rx.didFinishLaunching // when RxKeyboard is initialized before UIApplication.window is created - .withUnretained(panRecognizer) - .subscribe { gestureRecognizer, _ in - UIApplication.shared.windows.first?.addGestureRecognizer(gestureRecognizer) - } - .disposed(by: disposeBag) - } + // MARK: Public + + /// Get a singleton instance. + public static let instance = RxKeyboard() + + /// An observable keyboard frame. + public let frame: Driver + + /// An observable visible height of keyboard. Emits keyboard height if the keyboard is visible + /// or `0` if the keyboard is not visible. + public let visibleHeight: Driver + + /// Same with `visibleHeight` but only emits values when keyboard is about to show. This is + /// useful when adjusting scroll view content offset. + public let willShowVisibleHeight: Driver + + /// An observable visibility of keyboard. Emits keyboard visibility + /// when changed keyboard show and hide. + public let isHidden: Driver + + // MARK: Private + + private let disposeBag = DisposeBag() + private let panRecognizer = UIPanGestureRecognizer() + + // MARK: Initializing + + override init() { + + let keyboardWillChangeFrame = UIResponder.keyboardWillChangeFrameNotification + let keyboardWillHide = UIResponder.keyboardWillHideNotification + let keyboardFrameEndKey = UIResponder.keyboardFrameEndUserInfoKey + + let defaultFrame = CGRect( + x: 0, + y: UIScreen.main.bounds.height, + width: UIScreen.main.bounds.width, + height: 0 + ) + let frameVariable = BehaviorRelay(value: defaultFrame) + self.frame = frameVariable.asDriver().distinctUntilChanged() + self.visibleHeight = self.frame.map { UIScreen.main.bounds.height - $0.origin.y } + self.willShowVisibleHeight = self.visibleHeight + .scan((visibleHeight: 0, isShowing: false)) { lastState, newVisibleHeight in + return (visibleHeight: newVisibleHeight, isShowing: lastState.visibleHeight == 0 && newVisibleHeight > 0) + } + .filter { state in state.isShowing } + .map { state in state.visibleHeight } + self.isHidden = self.visibleHeight.map({ $0 == 0.0 }).distinctUntilChanged() + super.init() + + // keyboard will change frame + let willChangeFrame = NotificationCenter.default.rx.notification(keyboardWillChangeFrame) + .map { notification -> CGRect in + let rectValue = notification.userInfo?[keyboardFrameEndKey] as? NSValue + return rectValue?.cgRectValue ?? defaultFrame + } + .map { frame -> CGRect in + if frame.origin.y < 0 { // if went to wrong frame + var newFrame = frame + newFrame.origin.y = UIScreen.main.bounds.height - newFrame.height + return newFrame + } + return frame + } + + // keyboard will hide + let willHide = NotificationCenter.default.rx.notification(keyboardWillHide) + .map { notification -> CGRect in + let rectValue = notification.userInfo?[keyboardFrameEndKey] as? NSValue + return rectValue?.cgRectValue ?? defaultFrame + } + .map { frame -> CGRect in + if frame.origin.y < 0 { // if went to wrong frame + var newFrame = frame + newFrame.origin.y = UIScreen.main.bounds.height + return newFrame + } + return frame + } + + // pan gesture + let didPan = self.panRecognizer.rx.event + .withLatestFrom(frameVariable.asObservable()) { ($0, $1) } + .flatMap { (gestureRecognizer, frame) -> Observable in + guard case .changed = gestureRecognizer.state, + let window = UIApplication.shared.windows.first, + frame.origin.y < UIScreen.main.bounds.height + else { return .empty() } + let origin = gestureRecognizer.location(in: window) + var newFrame = frame + newFrame.origin.y = max(origin.y, UIScreen.main.bounds.height - frame.height) + return .just(newFrame) + } + + // merge into single sequence + Observable.of(didPan, willChangeFrame, willHide).merge() + .bind(to: frameVariable) + .disposed(by: self.disposeBag) + + // gesture recognizer + self.panRecognizer.delegate = self + + UIApplication.rx.didFinishLaunching // when RxKeyboard is initialized before UIApplication.window is created + .subscribe(onNext: { _ in + UIApplication.shared.windows.first?.addGestureRecognizer(self.panRecognizer) + }) + .disposed(by: self.disposeBag) + } + } @@ -144,39 +139,29 @@ public class RxKeyboard: NSObject, RxKeyboardType { extension RxKeyboard: UIGestureRecognizerDelegate { - public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { - let point = touch.location(in: gestureRecognizer.view) - var view = gestureRecognizer.view?.hitTest(point, with: nil) - - while let candidate = view { - if let scrollView = candidate as? UIScrollView, - case .interactive = scrollView.keyboardDismissMode { - return true - } - view = candidate.superview - } - - return false + public func gestureRecognizer( + _ gestureRecognizer: UIGestureRecognizer, + shouldReceive touch: UITouch + ) -> Bool { + let point = touch.location(in: gestureRecognizer.view) + var view = gestureRecognizer.view?.hitTest(point, with: nil) + while let candidate = view { + if let scrollView = candidate as? UIScrollView, + case .interactive = scrollView.keyboardDismissMode { + return true + } + view = candidate.superview } + return false + } - public func gestureRecognizer( - _ gestureRecognizer: UIGestureRecognizer, - shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer - ) -> Bool { - return gestureRecognizer === panRecognizer - } -} - -private extension Notification.Name { - - static let keyboardWillChangeFrame = UIResponder.keyboardWillChangeFrameNotification - static let keyboardWillHide = UIResponder.keyboardWillHideNotification -} - -private extension String { + public func gestureRecognizer( + _ gestureRecognizer: UIGestureRecognizer, + shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer + ) -> Bool { + return gestureRecognizer === self.panRecognizer + } - static let keyboardFrameEndKey = UIResponder.keyboardFrameEndUserInfoKey } - #endif From 29a239960f957e92d55b5aa025ab86f33af497b3 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 5 Jan 2021 12:20:55 +0300 Subject: [PATCH 09/13] Update Gemfile.lock --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index f371d71..c26ab86 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,7 +87,7 @@ GEM nanaimo (~> 0.3.0) PLATFORMS - universal-darwin-19 + ruby DEPENDENCIES cocoapods (~> 1.10) From e7c9f8e98c09e176e4d7544bfe9a95c874cee6c0 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 5 Jan 2021 12:27:59 +0300 Subject: [PATCH 10/13] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dc96e3e..be4e602 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ install: before_script: - set -o pipefail + - swift package update - swift package generate-xcodeproj script: From 077ce969e14912de2846bd1e7bb5605a1d55555e Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 5 Jan 2021 12:31:26 +0300 Subject: [PATCH 11/13] Update .travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index be4e602..dc96e3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,6 @@ install: before_script: - set -o pipefail - - swift package update - swift package generate-xcodeproj script: From 0a8dfc1f9dc88b2d73c84a87d5f84b14194fd979 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 11 Jan 2021 12:08:01 +0300 Subject: [PATCH 12/13] Update .travis.yml --- .travis.yml | 12 ++++++------ Package.swift | 2 +- RxKeyboard.podspec | 2 +- Sources/RxKeyboard/RxKeyboard.swift | 2 +- scripts/carthage.sh | 21 +++++++++++++++++++++ 5 files changed, 30 insertions(+), 9 deletions(-) create mode 100755 scripts/carthage.sh diff --git a/.travis.yml b/.travis.yml index dc96e3e..d7dd4b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -osx_image: xcode10.2 +osx_image: xcode12.3 language: objective-c sudo: required env: @@ -6,12 +6,12 @@ env: - PROJECT="RxKeyboard.xcodeproj" - SCHEME="RxKeyboard-Package" - IOS_SDK="iphonesimulator" - - MACOS_SDK="macosx10.14" - - TVOS_SDK="appletvsimulator12.2" - - WATCHOS_SDK="watchsimulator5.2" + - MACOS_SDK="macosx11.0" + - TVOS_SDK="appletvsimulator9.0" + - WATCHOS_SDK="watchsimulator3.0" - FRAMEWORK="RxKeyboard" matrix: - - SDK="$IOS_SDK" TEST=0 SWIFT_VERSION=5.0 DESTINATION="platform=iOS Simulator,name=iPhone 8" + - SDK="$IOS_SDK" TEST=0 SWIFT_VERSION=5.1 DESTINATION="platform=iOS Simulator,name=iPhone 8" install: - swift --version @@ -49,7 +49,7 @@ before_deploy: - bundle exec swiftproj configure-scheme --project RxKeyboard.xcodeproj --scheme RxKeyboard-Package --buildable-targets RxKeyboard - bundle exec swiftproj remove-framework --project RxKeyboard.xcodeproj --target RxKeyboard --framework RxCocoa.framework - bundle exec swiftproj remove-framework --project RxKeyboard.xcodeproj --target RxKeyboard --framework RxCocoaRuntime.framework - - carthage bootstrap + - ./carthage.sh bootstrap - carthage build --no-skip-current --verbose | xcpretty -c - carthage archive RxKeyboard diff --git a/Package.swift b/Package.swift index fff07b0..0198bf0 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.0 +// swift-tools-version:5.1 import PackageDescription diff --git a/RxKeyboard.podspec b/RxKeyboard.podspec index a1e64aa..a2d8890 100644 --- a/RxKeyboard.podspec +++ b/RxKeyboard.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.source_files = 'Sources/**/*.swift' s.frameworks = 'UIKit' s.requires_arc = true - s.swift_version = "5.0" + s.swift_version = "5.1" s.dependency 'RxSwift', '~> 6.0' s.dependency 'RxCocoa', '~> 6.0' diff --git a/Sources/RxKeyboard/RxKeyboard.swift b/Sources/RxKeyboard/RxKeyboard.swift index f92ad2b..b59ce21 100644 --- a/Sources/RxKeyboard/RxKeyboard.swift +++ b/Sources/RxKeyboard/RxKeyboard.swift @@ -159,7 +159,7 @@ extension RxKeyboard: UIGestureRecognizerDelegate { _ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer ) -> Bool { - return gestureRecognizer === self.panRecognizer + gestureRecognizer === self.panRecognizer } } diff --git a/scripts/carthage.sh b/scripts/carthage.sh new file mode 100755 index 0000000..e21348f --- /dev/null +++ b/scripts/carthage.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# carthage.sh +# Usage example: ./carthage.sh build --platform iOS + +set -euo pipefail + +xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX) +trap 'rm -f "$xcconfig"' INT TERM HUP EXIT + +# For Xcode 12 make sure EXCLUDED_ARCHS is set to arm architectures otherwise +# the build will fail on lipo due to duplicate architectures. + +CURRENT_XCODE_VERSION=$(xcodebuild -version | grep "Build version" | cut -d' ' -f3) +echo "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$CURRENT_XCODE_VERSION = arm64 arm64e armv7 armv7s armv6 armv8" >> $xcconfig + +echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200 = $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$(XCODE_PRODUCT_BUILD_VERSION))' >> $xcconfig +echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig + +export XCODE_XCCONFIG_FILE="$xcconfig" +carthage build "$@" \ No newline at end of file From fd41857dcf8687d40a37a4c0d757a90bd3c4e8a5 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 11 Jan 2021 12:24:15 +0300 Subject: [PATCH 13/13] Code correction in Package.swift --- Package.swift | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Package.swift b/Package.swift index 0198bf0..7689c46 100644 --- a/Package.swift +++ b/Package.swift @@ -3,17 +3,14 @@ import PackageDescription let package = Package( - name: "RxKeyboard", - platforms: [ - .iOS(.v9) - ], - products: [ - .library(name: "RxKeyboard", targets: ["RxKeyboard"]), - ], - dependencies: [ - .package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.0.0")), - ], - targets: [ - .target(name: "RxKeyboard", dependencies: ["RxSwift", "RxCocoa"]), - ] + name: "RxKeyboard", + products: [ + .library(name: "RxKeyboard", targets: ["RxKeyboard"]), + ], + dependencies: [ + .package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.0.0")), + ], + targets: [ + .target(name: "RxKeyboard", dependencies: ["RxSwift", "RxCocoa"]), + ] )