Skip to content

[parked] feat: renderEnabled prop to stop drawing or advancing covered views - #362

Draft
mfazekas wants to merge 1 commit into
mainfrom
feat/offscreen-behavior
Draft

mfazekas wants to merge 1 commit into
mainfrom
feat/offscreen-behavior

Conversation

@mfazekas

@mfazekas mfazekas commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

Parked in favor of #472, which adds only a paused?: boolean prop. That covers the covered-screen case with the same effect as 'pause' here, works the same on both platforms, and avoids the boolean | string prop. This PR is kept for reference for its Android-only skip-draws mode (false) and will likely be closed.


Adds renderEnabled?: boolean | 'pause' to RiveView, for views covered by UI they cannot detect. A customer's home screen has two looping Rive views; pushing a screen over it with @react-navigation/stack leaves the home screen attached and shown on Android, so both views kept advancing and drawing (168% CPU on their device). renderEnabled={isFocused ? true : 'pause'} brought that down to 16% and resumed fine.

  1. true (default): render normally.
  2. false: skip draws while the state machine keeps advancing, so events and data binding stay live. Android only; on iOS the runtime couples advancing and drawing, so it behaves like true.
  3. 'pause': stop advancing and drawing. It composes with the pause()/play() ref methods rather than overwriting their state.

On Android this is built into the current on-demand frame loop: a paused mode counts as no work, so no frame callbacks run while covered, and re-enabling forces one redraw. offscreenBehavior moved to #471 (parked). It only reacts to scrolled-out or hidden views, and that didn't help here (169%): a covering screen or sibling leaves isShown/getGlobalVisibleRect true. rive-android also has no equivalent.

The new example page "renderEnabled on a covered screen" reproduces it: two looping views under a JS stack push (inactive screens kept attached) or an opaque sibling, with a live advances/s counter. Process CPU on a Pixel 6 emulator (release, % of one core, 3×8s samples, covered by the stack push):

  • main, any value (prop ignored): 84–110%, 61 advances/s
  • this PR, true: 43–77%, 61 advances/s
  • this PR, false: 3–11%, 61 advances/s
  • this PR, 'pause': ~1%, 0 advances/s

Going back resumes at 61 advances/s in every mode. With the ref pause() active, uncovering keeps the view paused until play(). Emulator numbers vary between runs, so the true rows of main and this PR overlap rather than differ.

@mfazekas
mfazekas force-pushed the feat/offscreen-behavior branch from cf392a9 to 4466bfd Compare July 31, 2026 06:01
Views covered by UI they cannot detect (a screen pushed with a JS stack navigator, a Modal, an opaque sibling) stay attached and shown, so they keep advancing and drawing. renderEnabled={false} skips draws while the state machine keeps advancing (Android only); 'pause' also stops advancing and composes with the pause()/play() ref methods.
@mfazekas
mfazekas force-pushed the feat/offscreen-behavior branch from 4466bfd to f71bdb9 Compare November 19, 2026 10:42
@mfazekas mfazekas changed the title feat: offscreenBehavior and renderEnabled props to cut offscreen CPU cost feat: renderEnabled prop to stop drawing or advancing covered views Nov 19, 2026
@mfazekas mfazekas changed the title feat: renderEnabled prop to stop drawing or advancing covered views [parked] feat: renderEnabled prop to stop drawing or advancing covered views Nov 19, 2026
@mfazekas
mfazekas marked this pull request as draft November 19, 2026 13:22
mfazekas added a commit that referenced this pull request Nov 20, 2026
A screen pushed with `@react-navigation/stack` (with inactive screens
kept attached) leaves the screen underneath attached and shown on
Android, so looping Rive views on it keep advancing and drawing at full
rate. The view can't detect that on its own, so this adds a `paused?:
boolean` prop the app can drive, e.g. `paused={!isFocused}`.

`paused` stops advancing and drawing on the new backends;
`paused={false}` resumes where it left off (the frame timebase is reset
like `pause()` does). It combines with the ref: the view runs only when
neither the prop nor `pause()` has paused it, so `paused` wins over
`play()`, unpausing doesn't undo an earlier `pause()`, and
`autoPlay={false}` still waits for `play()`. It survives
reloads/reconfigures, and a view mounted paused still draws its first
frame and resolves `awaitViewReady()`. Legacy backends accept and ignore
it. On Android it's one main-thread flag folded into the existing
advancing/has-work check; on iOS it's kept apart from `isPaused` and
OR-ed in wherever `RiveUIView.isPaused` is written.

Measured on a Pixel 6 emulator with looping views under a stack push,
process CPU as % of one core: main 43–58% with 61 advances/s while
covered; this PR with `paused` off 48–75%, with `paused={!isFocused}`
1–2.5% and 0 advances/s. Playback resumes on going back. The
`PausedCovered` example page reproduces it with a live advances/s
counter. `example/__tests__/paused-prop.harness.tsx` passes on Android
(Pixel 6 emulator) and iOS (iOS 26.5 simulator), along with the existing
playback suites.

Supersedes #362 (`renderEnabled`); its skip-draws mode (`false`) is
parked.
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

Successfully merging this pull request may close these issues.

1 participant