Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateBlock not being called on Node after update. #60

Closed
jewilhel opened this issue Jul 11, 2017 · 6 comments
Closed

CreateBlock not being called on Node after update. #60

jewilhel opened this issue Jul 11, 2017 · 6 comments

Comments

@jewilhel
Copy link

I was using the createBlock to perform some initialization and execute an animation like this:

let card = Node<UIView>(key: state.id,
                                create: {
            let cardView = UIView()
            ComponentAnimation.springOn(view: cardView)
            return cardView

but now this never gets called after I pulled the latest update. Should I be using another block, like props: for this?

I need to execute this animation just once when my card is created so that it pops on screen. If I put it out in the configuration block it gets called multiple times.

Thanks for your help.

@alexdrone
Copy link
Owner

you sure the create block is not called - it works for me :/

@jewilhel
Copy link
Author

Yeah, I put a print statement in there to check it for sure. I got nothing printed to the console. I reverted the framework to the previous update and it worked as expected. I haven't encountered this issue before the recent update. I will test again in the sample code that I shared with you earlier.

@alexdrone
Copy link
Owner

that's really weird - I'm on HEAD right now and the creation closure seems to be invoked all of the time.

@jewilhel
Copy link
Author

What is really strange is that it only stopped working in my card component, but it seems to work everywhere else.

import Foundation
import UIKit
import Render

struct CardState: State {
    var id: String = "Card"
    var feature: NodeType = layoutBuilder("")
    var titlebar: NodeType = layoutBuilder("")
    var cardSize: CGFloat = 1
    var layoutAs: String = "layer"
    
}

class CardComponent: ComponentView<CardState> {
    required init() {
        super.init()
        self.state = CardState()
        self.defaultOptions = [.preventViewHierarchyDiff]
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("Not supported")
    }
    
    override func render() -> NodeType {
        
        let card = Node<UIView>(key: state.id,
                                create: {
            let cardView = UIView()
            ComponentAnimation.springOn(view: cardView)
            return cardView
                                    
        }) { (view, layout, size) in
            let componentSize = self.getSize()
            
            // Add shadow
            view.layer.shadowColor = UIColor.black.cgColor
            view.layer.shadowOpacity = 0.5
            view.layer.shadowOffset = CGSize.init(width: 2, height: 2)
            view.layer.shadowRadius = 2
            
            // Perform layout
            layout.width = componentSize.width
            layout.height = componentSize.width * CardSize.Proportion
            configs[self.state.layoutAs]!(layout)
            
            //layout.paddingTop = 6
        }
        
        // A content view that clips its contents
        let content = Node<UIView> { (view, layout, size) in
            let componentSize = self.getSize()
            
            view.isUserInteractionEnabled = true
            view.onTap { _ in mainStore.dispatch(ContextActionRemove(sender: view))}
            view.layer.cornerRadius = componentSize.width * CardSize.CornerRadiusRatio
            view.clipsToBounds = true
            
            layout.percent.width = 100%
            layout.percent.height = 100%
            layout.alignContent = .center
            
        }
        return card.add(children: [ content.add(children: [
            state.feature, state.titlebar
            ])
            ])
    }
    
    private func getSize() -> CGSize {
        let componentWidth = (UIScreen.main.bounds.size.width * self.state.cardSize)
        return CGSize(width: componentWidth, height: componentWidth * CardSize.Proportion)
    }
}

@jewilhel
Copy link
Author

jewilhel commented Jul 11, 2017

Well, I tried putting a reuseIdentifer: "card" before the key: and then the card started behaving as usual and called the create: block correctly. If I remove the reuseIdentifer: again it stops calling the create block. I guess I'm still a bit unclear the difference between key: and the reuseIdentifier.

@alexdrone
Copy link
Owner

alexdrone commented Jul 12, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants