Skip to content

High-level API: fix API problems before beta #31

Open

Description

@pawicao

Context

#27 adds a high-level API: Collapsible, CollapsibleTabs, presets, and pager adapters. It ships as an alpha first. This issue lists the API problems that a review of #27 found. Fix them before the beta or stable release.

Links point to the #27 code at commit e0bb26a.

Must fix before beta

These change the public API. Changes after beta break users.

1. Rename the Collapsible root

The name is too general and does not say "header". react-native-collapsible is a common accordion library, and its main export is also Collapsible. Apps that use both libraries get an import clash.

  • Rename to CollapsibleHeader, or move it under the HeaderMotion namespace.

2. Make each built-in preset do one effect

parallax and scale also fade by default (presets.ts#L122, #L139). The merge multiplies opacity (#L245). So ['parallax', 'scale'] fades the content twice, at (1 − r)². The merge also joins transform arrays in order (#L243), so the array order changes the result.

  • Remove the fade option from parallax and scale. Users write ['parallax', 'fade'] instead.
  • Document the merge rules and the effect of preset order.

3. Key presets by part

Each part runs every preset in full and keeps one key (presets.ts#L276). That is four or more preset calls per frame, plus one for each extra Pinned. A preset keyed by part does less work and shows which part gets each style:

const fold = createCollapsiblePreset({
  header: ({ progress }) => {
    'worklet';
    return { backgroundColor: interpolateColor(progress, [0, 1], [a, b]) };
  },
  dynamicContent: ({ progress, progressThreshold }) => {
    'worklet';
    return { opacity: 1 - progress };
  },
});
  • Change CollapsiblePreset to an object with one optional worklet per part.

4. Let presets change how the header moves

The header always slides up with a fixed transform (Collapsible.tsx#L159). A preset can add styles but cannot replace this transform. These effects are not possible now:

  • a header that shrinks its height instead of sliding;

  • "stretch or zoom on overscroll". It also needs the raw scroll offset, not only the clamped progress.

  • Decide if header movement (behavior) and decoration (effects) become two separate options.

  • Add scrollY to CollapsiblePresetContext.

5. Fix the tabs contract

CollapsibleTabs has two sources of truth. The tabs prop and the Tab name children must match in order. A mismatch only gives a dev warning (CollapsibleTabs.tsx#L48, #L253).

  • Keep tabs as the single source of truth. Match Pager children by name, not by position.
  • Add a controlled activeTab prop, for example to sync the tab with route params.

6. Add page-scroll position to the pager adapter contract

The adapter reports only a settled index (pagerAdapters.tsx#L46). A custom tab bar cannot draw an animated indicator without a continuous position. The adapter contract is public. If adapters must supply the position later, adapters that users wrote break.

  • Add a continuous position shared value to CollapsibleTabsPagerAdapterProps.
  • Expose it through useCollapsibleTabs().

7. Move collapse() and expand() to the low-level API

useCollapsibleHeader() also works inside a plain HeaderMotion, and it repeats useMotionProgress().

  • Add collapse() and expand() to a low-level hook. Keep or remove useCollapsibleHeader().

Should fix

8. Collapsible.Pinned below Collapsible.Dynamic

Pinned moves down by the same distance that the header moves up (Collapsible.tsx#L184), so it keeps its first screen position. If a user puts it below Dynamic, it probably covers the content after the collapse. This comes from reading the code and is not tested.

  • Test the case.
  • Document that Pinned goes above Dynamic, or detect the wrong order in dev.

9. Inline preset arrays rebuild the presets on each render

The memo depends on the identity of the preset value (Collapsible.tsx#L117). preset={['collapse', 'fade']} makes a new array on each render. This gives a new context value and rebuilds the animated styles.

  • Memoize on a stable key, or document that users must define the array outside the component.

10. Add the refresh state to the preset context

#25 added the headless refresh control and useRefreshControl(). The preset context has only progress and progressThreshold, so a preset cannot react to pull to refresh.

  • After the rebase onto main, add the refresh state (for example phase and progress from useRefreshControl()) to CollapsiblePresetContext.
  • Add a built-in preset or an example that uses it.

Process

  • Split the work. The scroll-id context (useScrollManager.ts#L381) and item 7 can go into the low-level API now. Tabs and pager adapters carry the most API risk.
  • Remove @experimental and the alpha warning in the docs when the API is stable.

Activity

  1. added
    enhancement
    on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions