Skip to content

Commit

Permalink
fix a regression with views not matching up
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Feb 7, 2017
1 parent 6480a2b commit 4baabd5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C68" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="hC7-Hw-3Wq">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16A313a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="hC7-Hw-3Wq">
<device id="retina5_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand Down Expand Up @@ -44,17 +44,17 @@
<fragment content=" ">
<attributes>
<color key="NSColor" red="0.13797999999999999" green="0.12134" blue="0.12545000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<font key="NSFont" size="24" name="OpenSans"/>
<font key="NSFont" metaFont="system" size="24"/>
<real key="NSKern" value="0.0"/>
<font key="NSOriginalFont" size="24" name="OpenSans"/>
<font key="NSOriginalFont" metaFont="system" size="24"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="leftToRight" defaultTabInterval="36" tighteningFactorForTruncation="0.0" allowsDefaultTighteningForTruncation="NO"/>
<color key="NSStrokeColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</attributes>
</fragment>
<fragment content="WATCH">
<attributes>
<color key="NSColor" red="0.13797999999999999" green="0.12134" blue="0.12545000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<font key="NSFont" size="24" name="OpenSans-Bold"/>
<font key="NSFont" metaFont="system" size="24"/>
<real key="NSKern" value="0.0"/>
<font key="NSOriginalFont" size="22" name="SFUIDisplay-Bold"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="leftToRight" defaultTabInterval="36" tighteningFactorForTruncation="0.0" allowsDefaultTighteningForTruncation="NO"/>
Expand All @@ -66,7 +66,7 @@
SERIES 2</string>
<attributes>
<color key="NSColor" red="0.13797999999999999" green="0.12134" blue="0.12545000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<font key="NSFont" size="11" name="OpenSans"/>
<font key="NSFont" metaFont="smallSystem"/>
<real key="NSKern" value="0.0"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="leftToRight" defaultTabInterval="36" tighteningFactorForTruncation="0.0" allowsDefaultTighteningForTruncation="NO"/>
<color key="NSStrokeColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down
14 changes: 8 additions & 6 deletions Sources/Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,20 @@ internal extension Hero {
// take a snapshot to hide all the flashing that might happen
let completeSnapshot = fromView.snapshotView(afterScreenUpdates: true)!
transitionContainer.addSubview(completeSnapshot)
context = HeroContext(container:container, fromView: fromView, toView:toView)

context = HeroContext(container:container)

context.hide(view: toView)
container.addSubview(toView)
container.addSubview(fromView)

toView.frame = fromView.frame
toView.updateConstraints()
toView.setNeedsLayout()
toView.layoutIfNeeded()


context.set(fromView: fromView, toView: toView)

for processor in processors {
processor.process(fromViews: context.fromViews, toViews: context.toViews)
}
Expand All @@ -338,8 +340,8 @@ internal extension Hero {

if toView.layer.zPosition < fromView.layer.zPosition {
// in this case, we have to animate the zPosition as well. otherwise the fade animation will be hidden.
context[toView]!.append(.zPosition(fromView.layer.zPosition))
context[fromView] = [.zPosition(toView.layer.zPosition)]
context[toView]!.append(.zPosition(fromView.layer.zPosition + 1))
context[fromView] = [.zPosition(toView.layer.zPosition - 1)]
animatingViews[0].0.insert(fromView, at: 0)
}
}
Expand Down
11 changes: 7 additions & 4 deletions Sources/HeroContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ public class HeroContext {
internal var viewAlphas = [UIView: CGFloat]()
internal var targetStates = [UIView: HeroTargetState]()

internal init(container: UIView, fromView: UIView, toView: UIView) {
internal init(container: UIView) {
self.container = container
}

internal func set(fromView:UIView, toView:UIView) {
fromViews = HeroContext.processViewTree(view: fromView, container: container, idMap: &heroIDToSourceView, stateMap: &targetStates)
toViews = HeroContext.processViewTree(view: toView, container: container, idMap: &heroIDToDestinationView, stateMap: &targetStates)
self.container = container
}

/**
Expand All @@ -43,12 +46,12 @@ public class HeroContext {
/**
A flattened list of all views from source ViewController
*/
public let fromViews: [UIView]
public var fromViews: [UIView]!

/**
A flattened list of all views from destination ViewController
*/
public let toViews: [UIView]
public var toViews: [UIView]!
}

// public
Expand Down

0 comments on commit 4baabd5

Please sign in to comment.