-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from AnTonhoLAB/feature/ActivityIndicator
Add ActivityIndicator and update project to accept pods
- Loading branch information
Showing
8 changed files
with
280 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
GGDevelopmentKit.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// ActivityIndicator.swift | ||
// GGDevelopmentKit | ||
// | ||
// Created by George Vilnei Arboite Gomes on 07/01/22. | ||
// Copyright © 2022 George Gomes. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import RxSwift | ||
import RxCocoa | ||
|
||
public class ActivityIndicator: SharedSequenceConvertibleType { | ||
public typealias Element = Bool | ||
public typealias SharingStrategy = DriverSharingStrategy | ||
|
||
private let _lock = NSRecursiveLock() | ||
private let _behavior = BehaviorRelay<Bool>(value: false) | ||
private let _loading: SharedSequence<SharingStrategy, Bool> | ||
|
||
public init() { | ||
_loading = _behavior.asDriver() | ||
.distinctUntilChanged() | ||
} | ||
|
||
fileprivate func trackActivityOfObservable<O: ObservableConvertibleType>(_ source: O) -> Observable<O.Element> { | ||
return source.asObservable() | ||
.do(onNext: { _ in | ||
self.sendStopLoading() | ||
}, onError: { _ in | ||
self.sendStopLoading() | ||
}, onCompleted: { | ||
self.sendStopLoading() | ||
}, onSubscribe: subscribed) | ||
} | ||
|
||
private func subscribed() { | ||
_lock.lock() | ||
_behavior.accept(true) | ||
_lock.unlock() | ||
} | ||
|
||
private func sendStopLoading() { | ||
_lock.lock() | ||
_behavior.accept(false) | ||
_lock.unlock() | ||
} | ||
|
||
public func asSharedSequence() -> SharedSequence<SharingStrategy, Element> { | ||
return _loading | ||
} | ||
} | ||
|
||
extension ObservableConvertibleType { | ||
public func trackActivity(_ activityIndicator: ActivityIndicator) -> Observable<Element> { | ||
return activityIndicator.trackActivityOfObservable(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
platform :ios, '10.0' | ||
|
||
# source to download other pods | ||
source 'https://github.com/CocoaPods/Specs.git' | ||
|
||
|
||
target 'GGDevelopmentKit' do | ||
# Comment the next line if you don't want to use dynamic frameworks | ||
use_frameworks! | ||
|
||
# Pods for GGDevelopmentKit | ||
pod 'RxSwift', '>= 5.0.0' | ||
pod 'RxCocoa', '>= 5.0.0' | ||
|
||
target 'GGDevelopmentKitTests' do | ||
# Pods for testing | ||
pod 'RxBlocking' | ||
pod 'RxTest' | ||
end | ||
|
||
end | ||
|
||
target 'Run' do | ||
# Comment the next line if you don't want to use dynamic frameworks | ||
use_frameworks! | ||
|
||
# Pods for Run | ||
|
||
end |