Skip to content

Commit

Permalink
less force unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Jul 18, 2017
1 parent c5a510f commit d8c9443
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
21 changes: 11 additions & 10 deletions Sources/Extensions/UIView+Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,19 @@ public extension UIView {
return snapshotView
}

internal func snapshotView() -> UIView {
var snapshot = snapshotView(afterScreenUpdates: true)!
if #available(iOS 11.0, *) {
internal func snapshotView() -> UIView? {
let snapshot = snapshotView(afterScreenUpdates: true)
if #available(iOS 11.0, *), let oldSnapshot = snapshot {
// in iOS 11, the snapshot taken by snapshotView(afterScreenUpdates) won't contain a container view
let oldSnapshot = snapshot
snapshot = UIView()
snapshot.bounds = oldSnapshot.bounds
snapshot.center = oldSnapshot.center
oldSnapshot.center = snapshot.bounds.center
snapshot.addSubview(oldSnapshot)
let wrappedSnapshot = UIView()
wrappedSnapshot.bounds = oldSnapshot.bounds
wrappedSnapshot.center = oldSnapshot.center
oldSnapshot.center = wrappedSnapshot.bounds.center
wrappedSnapshot.addSubview(oldSnapshot)
return wrappedSnapshot
} else {
return snapshot
}
return snapshot
}

internal var flattenedViewHierarchy: [UIView] {
Expand Down
6 changes: 3 additions & 3 deletions Sources/HeroContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ extension HeroContext {
view.layer.cornerRadius = 0
view.alpha = 1

var snapshot: UIView!
let snapshot: UIView
let snapshotType: HeroSnapshotType = self[view]?.snapshotType ?? .optimized

switch snapshotType {
case .normal:
snapshot = view.snapshotView()
snapshot = view.snapshotView() ?? UIView()
case .layerRender:
snapshot = view.slowSnapshotView()
case .noSnapshot:
Expand Down Expand Up @@ -194,7 +194,7 @@ extension HeroContext {
snapshot = UIVisualEffectView(effect: effectView.effect)
snapshot.frame = effectView.bounds
} else {
snapshot = view.snapshotView()
snapshot = view.snapshotView() ?? UIView()
}
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Transition/HeroTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ open class HeroTransition: NSObject {
return inNavigationController || inTabBarController
}
internal var toOverFullScreen: Bool {
return !inContainerController && (toViewController!.modalPresentationStyle == .overFullScreen || toViewController!.modalPresentationStyle == .overCurrentContext)
return !inContainerController && (toViewController?.modalPresentationStyle == .overFullScreen || toViewController?.modalPresentationStyle == .overCurrentContext)
}
internal var fromOverFullScreen: Bool {
return !inContainerController && (fromViewController!.modalPresentationStyle == .overFullScreen || fromViewController!.modalPresentationStyle == .overCurrentContext)
return !inContainerController && (fromViewController?.modalPresentationStyle == .overFullScreen || fromViewController?.modalPresentationStyle == .overCurrentContext)
}

internal var toView: UIView? { return toViewController?.view }
Expand Down

0 comments on commit d8c9443

Please sign in to comment.