Skip to content

Commit

Permalink
Simplify binding in GeolocationViewController
Browse files Browse the repository at this point in the history
Remove warning in Storyboard
  • Loading branch information
Czajnikowski committed Dec 7, 2016
1 parent 3293a6c commit 0e1b43a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
<outlet property="button2" destination="3q9-a2-ojh" id="kww-B7-jeL"/>
<outlet property="label" destination="Edb-tp-cly" id="Icm-cQ-9QB"/>
<outlet property="noGeolocationView" destination="7Wy-Xx-ged" id="tce-XP-hMK"/>
<outlet property="view" destination="oOI-v8-i8g" id="g8m-Rt-ZGi"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="yOr-7R-tPd" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand All @@ -104,7 +103,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Geolocation is not enabled for this app" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QDz-hL-6ve">
<rect key="frame" x="48" y="168" width="280" height="68"/>
<rect key="frame" x="48" y="168.5" width="280" height="67.5"/>
<constraints>
<constraint firstAttribute="width" constant="280" id="OAO-CK-RYp"/>
</constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ private extension Reactive where Base: UILabel {
}
}

private extension Reactive where Base: UIView {
func subviewPresence(_ subview: UIView) -> UIBindingObserver<Base, Bool> {
return UIBindingObserver(UIElement: base) { view, show in
if !show {
subview.removeFromSuperview()
}
else {
view.addSubview(subview)
}
}
}
}

class GeolocationViewController: ViewController {

@IBOutlet weak private var noGeolocationView: UIView!
Expand All @@ -44,11 +31,12 @@ class GeolocationViewController: ViewController {
override func viewDidLoad() {
super.viewDidLoad()

view.addSubview(noGeolocationView)

let geolocationService = GeolocationService.instance

geolocationService.authorized
.map(!)
.drive(view.rx.subviewPresence(noGeolocationView))
.drive(noGeolocationView.rx.isHidden)
.addDisposableTo(disposeBag)

geolocationService.location
Expand Down

0 comments on commit 0e1b43a

Please sign in to comment.