Modernizes image view extensions.
This commit is contained in:
parent
afd40f5d8b
commit
d1cde77b18
|
|
@ -26,6 +26,7 @@ extension NSImageView {
|
|||
|
||||
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
||||
*/
|
||||
@available(*, deprecated, renamed: "rx_image(transitionType:)")
|
||||
public func rx_imageAnimated(_ transitionType: String?) -> AnyObserver<NSImage?> {
|
||||
return UIBindingObserver(UIElement: self) { control, value in
|
||||
if let transitionType = transitionType {
|
||||
|
|
@ -43,5 +44,27 @@ extension NSImageView {
|
|||
control.image = value
|
||||
}.asObserver()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Bindable sink for `image` property.
|
||||
|
||||
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
||||
*/
|
||||
public func rx_image(transitionType: String? = nil) -> AnyObserver<NSImage?> {
|
||||
return UIBindingObserver(UIElement: self) { control, value in
|
||||
if let transitionType = transitionType {
|
||||
if value != nil {
|
||||
let transition = CATransition()
|
||||
transition.duration = 0.25
|
||||
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
transition.type = transitionType
|
||||
control.layer?.add(transition, forKey: kCATransition)
|
||||
}
|
||||
}
|
||||
else {
|
||||
control.layer?.removeAllAnimations()
|
||||
}
|
||||
control.image = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ extension UIImageView {
|
|||
Bindable sink for `image` property.
|
||||
*/
|
||||
public var rx_image: AnyObserver<UIImage?> {
|
||||
return self.rx_imageAnimated(nil)
|
||||
return self.rx_image(transitionType: nil)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -28,6 +28,7 @@ extension UIImageView {
|
|||
|
||||
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
||||
*/
|
||||
@available(*, deprecated, renamed: "rx_image(transitionType:)")
|
||||
public func rx_imageAnimated(_ transitionType: String?) -> AnyObserver<UIImage?> {
|
||||
return UIBindingObserver(UIElement: self) { imageView, image in
|
||||
if let transitionType = transitionType {
|
||||
|
|
@ -45,7 +46,29 @@ extension UIImageView {
|
|||
imageView.image = image
|
||||
}.asObserver()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Bindable sink for `image` property.
|
||||
|
||||
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
||||
*/
|
||||
public func rx_image(transitionType: String? = nil) -> AnyObserver<UIImage?> {
|
||||
return UIBindingObserver(UIElement: self) { imageView, image in
|
||||
if let transitionType = transitionType {
|
||||
if image != nil {
|
||||
let transition = CATransition()
|
||||
transition.duration = 0.25
|
||||
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
transition.type = transitionType
|
||||
imageView.layer.add(transition, forKey: kCATransition)
|
||||
}
|
||||
}
|
||||
else {
|
||||
imageView.layer.removeAllAnimations()
|
||||
}
|
||||
imageView.image = image
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ class PartialUpdatesViewController : ViewController {
|
|||
let cvReloadDataSource = RxCollectionViewSectionedReloadDataSource<NumberSection>()
|
||||
skinCollectionViewDataSource(cvReloadDataSource)
|
||||
self.sections.asObservable()
|
||||
.bindTo(partialUpdatesCollectionViewOutlet.rx_itemsWithDataSource(cvReloadDataSource))
|
||||
.bindTo(partialUpdatesCollectionViewOutlet.rx_items(dataSource: cvReloadDataSource))
|
||||
.addDisposableTo(disposeBag)
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class WikipediaSearchCell: UITableViewCell {
|
|||
|
||||
let reachabilityService = Dependencies.sharedDependencies.reachabilityService
|
||||
viewModel.imageURLs
|
||||
.drive(self.imagesOutlet.rx_itemsWithCellIdentifier("ImageCell", cellType: CollectionViewImageCell.self)) { [weak self] (_, url, cell) in
|
||||
.drive(self.imagesOutlet.rx_items(cellIdentifier: "ImageCell", cellType: CollectionViewImageCell.self)) { [weak self] (_, url, cell) in
|
||||
cell.downloadableImage = self?.imageService.imageFromURL(url, reachabilityService: reachabilityService) ?? Observable.empty()
|
||||
}
|
||||
.addDisposableTo(disposeBag)
|
||||
|
|
|
|||
Loading…
Reference in New Issue