Loading Documents

  • The interface for reading Lightwell screen documents and generating native elements – UIViews and CAAnimations.

    Exported projects from Lightwell include screen data and sliced images prepped in an asset catalog, vector and audio assets stored in an Assets folder, and the HullabaluStoryKit framework that includes all of the documented functionality. Makes sure to include all of them in your Xcode project.

    After including the screen documents, a LightwellLoadingContext can be initialized to read out the content.

    let loadingContext = LightwellLoadingContext(screenName: "my awesome screen")
    

    The loading context will then lazy load views and animations that correspond to the layers and actions defined in the Lightwell editor. The LightwellLoadingContext provides default behavior to translate the document’s content into UIViews and CAAnimations. However, if you’d like to do something custom the loading context provides hooks to override the default behavior. See LightwellLoadingContext.loadViews(usingGenerator:) and LightwellLoadingContext.loadAnimations(usingGenerator:)

    A basic implementation of the visual elements into a view controler might look like this:

    class MyViewController: UIViewController {
       override func viewDidLoad() {
           super.viewDidLoad()
    
           // Do any additional setup after loading the view.
           let loadingContext = LightwellLoadingContext(screenName: "my awesome screen")
           loadingContext?.views.forEach { self.view.addSubview($0) }
       }
    }
    

    If you are also including the dynamic elements, make sure to store the context as a parameter to save on reinitializing objects. For example:

    class MyViewController: UIViewController {
       let loadingContext = LightwellLoadingContext(screenName: "my awesome screen")
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Do any additional setup after loading the view.
            loadingContext?.views.forEach { self.view.addSubview($0) }
        }
    
        override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            super.touchesBegan(touches, with: event)
    
            if let view = self.loadingContext?.view(for: "my view") {
                if let animation = self.loadingContext?.animation(for: "my animation") {
                   view.layer.add(animation, forKey: nil)
                }
            }
        }
    }
    
    See more

    Declaration

    Swift

    public class LightwellLoadingContext : NSObject