Class LazyLoad<C extends com.vaadin.flow.component.Component>

  • Type Parameters:
    C - Type of component that is lazy-loaded.
    All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasStyle, Serializable, HasId, WithIdMixin<LazyLoad<C>>

    public class LazyLoad<C extends com.vaadin.flow.component.Component>
    extends com.vaadin.flow.component.Composite<LazyLoad.LazyLoadElement>
    implements WithIdMixin<LazyLoad<C>>, com.vaadin.flow.component.HasStyle
    A component that remains empty until it gets into view. After that it displays the lazy-loaded content. Note that by default the size of this component is 0px, as there is no styling to it. Be sure to apply styling. As a result and by default, if there are many of lazy load components one next to another, all of them will trigger.
    Since:
    2020-04-22
    Author:
    miki
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LazyLoad.LazyLoadElement
      This class exists so that LazyLoad can have a custom tag name.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String EMPTY_CLASS_NAME
      Style name when this component is empty (not showing anything).
      static String LOADED_CLASS_NAME
      Style name when this component has content.
    • Constructor Summary

      Constructors 
      Constructor Description
      LazyLoad​(C contents)
      Creates lazy load wrapper for given contents.
      LazyLoad​(com.vaadin.flow.function.SerializableSupplier<C> supplier)
      Creates lazy load wrapper for given component supplier.
      LazyLoad​(com.vaadin.flow.function.SerializableSupplier<C> supplier, boolean removeOnHide)
      Creates lazy load wrapper for given component supplier.
      LazyLoad​(C contents, boolean removeOnHide)
      Creates lazy load wrapper for given contents.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Optional<C> getLoadedContent()
      Gets the content if it was already loaded (isOnlyLoadedOnce() ()} is true) or if it is currently showing.
      boolean isLoaded()
      Checks if the content has been already loaded (isOnlyLoadedOnce() ()} is true) or is currently loaded.
      boolean isOnlyLoadedOnce()
      Returns if the lazy loading happens only on the first showing.
      protected void onNowHidden()  
      protected void onNowVisible()  
      • Methods inherited from class com.vaadin.flow.component.Composite

        getChildren, getContent, getElement, initContent
      • Methods inherited from class com.vaadin.flow.component.Component

        addListener, findAncestor, fireEvent, from, get, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisible
      • Methods inherited from interface com.vaadin.flow.component.AttachNotifier

        addAttachListener
      • Methods inherited from interface com.vaadin.flow.component.DetachNotifier

        addDetachListener
      • Methods inherited from interface com.vaadin.flow.component.HasElement

        getElement
      • Methods inherited from interface com.vaadin.flow.component.HasStyle

        addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
    • Field Detail

      • EMPTY_CLASS_NAME

        public static final String EMPTY_CLASS_NAME
        Style name when this component is empty (not showing anything).
        See Also:
        Constant Field Values
      • LOADED_CLASS_NAME

        public static final String LOADED_CLASS_NAME
        Style name when this component has content.
        See Also:
        Constant Field Values
    • Constructor Detail

      • LazyLoad

        public LazyLoad​(C contents)
        Creates lazy load wrapper for given contents. It will be displayed the first time this component becomes shown on screen.
        Parameters:
        contents - Contents to wrap for lazy loading.
      • LazyLoad

        public LazyLoad​(com.vaadin.flow.function.SerializableSupplier<C> supplier)
        Creates lazy load wrapper for given component supplier. It will be called exactly once, the first time this component becomes shown on screen.
        Parameters:
        supplier - Supplier that will be called when the component gets into view.
      • LazyLoad

        public LazyLoad​(C contents,
                        boolean removeOnHide)
        Creates lazy load wrapper for given contents.
        Parameters:
        contents - Contents to wrap for lazy loading.
        removeOnHide - Whether to remove the component when this object gets hidden.
      • LazyLoad

        public LazyLoad​(com.vaadin.flow.function.SerializableSupplier<C> supplier,
                        boolean removeOnHide)
        Creates lazy load wrapper for given component supplier.
        Parameters:
        supplier - Supplier that will be called when the component gets into view.
        removeOnHide - Whether to remove the component when this object gets hidden.
    • Method Detail

      • onNowHidden

        protected void onNowHidden()
      • onNowVisible

        protected void onNowVisible()
      • isOnlyLoadedOnce

        public boolean isOnlyLoadedOnce()
        Returns if the lazy loading happens only on the first showing.
        Returns:
        true when the target component will be loaded only once, the first time this component is shown; otherwise false.