Interface NtxPageLifecycle
A NtxPageLifecycle is owned by the view that hosts a page and is made
available to the render pipeline through
NTxRendererContext.pageLifecycle() (stored as the
CAPABILITY_PAGE_LIFECYCLE capability). Static renders (PDF, image,
HTML) do not provide one, so NTxRendererContext.isPageShowing() stays
true there and requestFrame() is never invoked.
Why it exists
Before this contract, animated components had to spin their ownjavax.swing.Timer to call NTxRendererContext.repaint(). With
more than one animated component on a slide that meant one timer (and one
full-page repaint) per component, and nothing stopped those timers when the
slide was left. Instead, components should:
- read
showElapsedSeconds()to compute their animation phase (stable across frames, starts at 0 each time the page is shown); - call
requestFrame()once per render while they still want to animate. The hosting view runs a single, throttled frame driver and idles as soon as no component requests a frame.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCapability key under which aNtxPageLifecycleis published onNTxRendererContext.getCapability(String). -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether this page is the one currently shown by the hosting view.default NtxAnimationTimerRegisters a periodic animation tick, owned by the page.intIndex of the page this lifecycle belongs to.voidAsks the hosting view to render another animation frame soon.default longMilliseconds elapsed since this page became visible, or0while it is not showing.default doubleSeconds elapsed since this page became visible; seeshowElapsedMillis().longWall-clock time (in milliseconds,System.currentTimeMillis()frame) at which the page became visible, or0if it has never been shown.
-
Field Details
-
CAPABILITY_PAGE_LIFECYCLE
Capability key under which aNtxPageLifecycleis published onNTxRendererContext.getCapability(String).- See Also:
-
-
Method Details
-
pageIndex
int pageIndex()Index of the page this lifecycle belongs to. -
isShowing
boolean isShowing()Whether this page is the one currently shown by the hosting view.falsefor a page that is only prefetched or already hidden. -
showStartTime
long showStartTime()Wall-clock time (in milliseconds,System.currentTimeMillis()frame) at which the page became visible, or0if it has never been shown. This is the anchor used byshowElapsedMillis(). -
showElapsedMillis
default long showElapsedMillis()Milliseconds elapsed since this page became visible, or0while it is not showing. The value is stable across frames so animations keep a continuous phase. -
showElapsedSeconds
default double showElapsedSeconds()Seconds elapsed since this page became visible; seeshowElapsedMillis(). -
requestFrame
void requestFrame()Asks the hosting view to render another animation frame soon. Components call this once per render for as long as they want to keep animating. It is a no-op when there is no live view driving the page. -
newTimer
Registers a periodic animation tick, owned by the page.The hosting view runs
tickeveryperiodMswhile the page is showing, stops it when the page stops showing and disposes it when the page is discarded, so callers never have to clean up. Ticks that share the sameperiodMsare grouped and driven by a single underlying timer.Registration is keyed by
owner: calling again with the same owner replaces the previous tick (typically used to refresh the callback on every render), so it is safe to call from every render. The callback runs on the UI thread; it should not capture a transient render context.- Parameters:
owner- stable identity of the registrant; typically the nodeperiodMs- desired period between ticks in milliseconds (> 0)tick- callback invoked on the UI thread while the page is showing- Returns:
- a handle to cancel the tick early; never
null
-