Skip to content

Commit

Permalink
Fix UIStackView Layout issue during transition
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Jan 7, 2017
1 parent f8128f4 commit 27a9270
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Hero/Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ internal extension Hero {
for (currentFromViews, currentToViews) in self.animatorViews {
// auto hide all animated views
for v in currentFromViews{
v.isHidden = true
self.context.hide(view: v)
}
for v in currentToViews{
v.isHidden = true
self.context.hide(view: v)
}
}

Expand Down Expand Up @@ -210,10 +210,10 @@ internal extension Hero {
for (i, animator) in self.animators.enumerated(){
animator.clean()
for v in self.animatorViews[i].0{
v.isHidden = false
context.unhide(view:v)
}
for v in self.animatorViews[i].1{
v.isHidden = false
context.unhide(view:v)
}
}

Expand Down
18 changes: 16 additions & 2 deletions Hero/HeroContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class HeroContext {
fileprivate var heroIDToDestinationView = [String:UIView]()
fileprivate var snapshotViews = [UIView:UIView]()
fileprivate var modifiers = [UIView:HeroModifiers]()
fileprivate var viewAlphas = [UIView:CGFloat]()

internal init(container:UIView, fromView:UIView, toView:UIView){
fromViews = HeroContext.processViewTree(view: fromView, container: container, idMap: &heroIDToSourceView, modifierMap: &modifiers)
Expand Down Expand Up @@ -94,7 +95,7 @@ extension HeroContext{
return snapshot
}

view.isHidden = false
unhide(view: view)

// capture a snapshot without cornerRadius
let oldCornerRadius = view.layer.cornerRadius
Expand Down Expand Up @@ -142,7 +143,7 @@ extension HeroContext{
snapshot.frame = container.convert(view.bounds, from: view)
snapshot.heroID = view.heroID

view.isHidden = true
hide(view: view)

container.addSubview(snapshot)
snapshotViews[view] = snapshot
Expand Down Expand Up @@ -220,6 +221,19 @@ extension HeroContext{

// internal
extension HeroContext{
internal func hide(view:UIView) {
if viewAlphas[view] == nil{
viewAlphas[view] = view.alpha
view.alpha = 0
}
}
internal func unhide(view:UIView){
if let oldAlpha = viewAlphas[view]{
view.alpha = oldAlpha
viewAlphas[view] = nil
}
}

internal static func extractModifiers(modifierString:String) -> HeroModifiers {
func matches(for regex: String, text:NSString) -> [NSTextCheckingResult] {
do {
Expand Down

0 comments on commit 27a9270

Please sign in to comment.