Class LazyLoad<C extends com.vaadin.flow.component.Component>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<LazyLoad.LazyLoadElement>
org.vaadin.miki.superfields.lazyload.LazyLoad<C>
- 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThis class exists so thatLazyLoadcan have a custom tag name. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates lazy load wrapper for given contents.Creates lazy load wrapper for given component supplier.Creates lazy load wrapper for given component supplier.Creates lazy load wrapper for given contents. -
Method Summary
Modifier and TypeMethodDescriptionGets the content if it was already loaded (isOnlyLoadedOnce()()} istrue) or if it is currently showing.booleanisLoaded()Checks if the content has been already loaded (isOnlyLoadedOnce()()} istrue) or is currently loaded.booleanReturns if the lazy loading happens only on the first showing.protected voidprotected voidMethods inherited from class com.vaadin.flow.component.Composite
getChildren, getContent, getElement, initContentMethods 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, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface org.vaadin.miki.markers.WithIdMixin
withId
-
Field Details
-
EMPTY_CLASS_NAME
Style name when this component is empty (not showing anything).- See Also:
-
LOADED_CLASS_NAME
Style name when this component has content.- See Also:
-
-
Constructor Details
-
LazyLoad
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
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-Supplierthat will be called when the component gets into view.
-
LazyLoad
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
Creates lazy load wrapper for given component supplier.- Parameters:
supplier-Supplierthat will be called when the component gets into view.removeOnHide- Whether to remove the component when this object gets hidden.
-
-
Method Details
-
onNowHidden
protected void onNowHidden() -
onNowVisible
protected void onNowVisible() -
isOnlyLoadedOnce
public boolean isOnlyLoadedOnce()Returns if the lazy loading happens only on the first showing.- Returns:
truewhen the target component will be loaded only once, the first time this component is shown; otherwisefalse.
-
getLoadedContent
Gets the content if it was already loaded (isOnlyLoadedOnce()()} istrue) or if it is currently showing.- Returns:
- A component that was lazy-loaded. If the component was not yet shown on-screen, returns
Optional.empty(). - See Also:
-
isLoaded
public boolean isLoaded()Checks if the content has been already loaded (isOnlyLoadedOnce()()} istrue) or is currently loaded.- Returns:
- Whether or not the content has been loaded.
- See Also:
-