Skip to content

feat: add native bottom-anchored sheet content - #136

Open
arekkubaczkowski wants to merge 4 commits into
software-mansion:mainfrom
arekkubaczkowski:t3/bottom-anchored-content
Open

arekkubaczkowski wants to merge 4 commits into
software-mansion:mainfrom
arekkubaczkowski:t3/bottom-anchored-content

Conversation

@arekkubaczkowski

@arekkubaczkowski arekkubaczkowski commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A chat sheet can keep its message list at a stable layout height and pin its composer to the moving bottom edge of the card. This is useful when a short detent should reveal less of the conversation without resizing the list while the user drags or releases the sheet.

  • Add bottomAnchoredContent to inline and modal sheets on iOS and Android. The native host positions and clips the slot against the card during dragging and settling.
  • Add optional contentClipTopInset on open detents. It sets the distance from the top of the card to the start of the visible and interactive area of bottomAnchoredContent. It defaults to zero and interpolates between detents. Regular children still determine the height of content-sized detents.
  • Support visible anchored descendants in native hit testing and scroll handoff.

For a footer on its own:

<BottomSheet
  index={index}
  onIndexChange={setIndex}
  detents={[0, '50%', '100%']}
  bottomAnchoredContent={<Footer />}
>
  <SheetContent />
</BottomSheet>

Why the visible content needs a top boundary

A sheet can reveal more or less of a view while keeping that view's layout size stable. When a separate part of the interface occupies the same area, the sheet needs a shared boundary for drawing and touch input. An opaque overlay hides pixels by replacing the surface in that area with a solid fill. That changes the appearance of a translucent or blurred surface. It also leaves the touch boundary to the overlay's separate view hierarchy.

contentClipTopInset defines the boundary in native card coordinates and moves it with the card during dragging and settling. It preserves the content's layout and its bottom anchor. A footer on its own normally uses the default of zero.

For example, a chat can pass bottomAnchoredContent={<Conversation />} with a separate header as a regular child. The app can reserve 48 points at the compact detent and 64 at full height, where the header might also include the safe area.

detents={[
  0,
  { value: '50%', contentClipTopInset: 48 },
  { value: '100%', contentClipTopInset: 64 },
]}

What we tried in a Fabric chat sheet

The sheet opens at 50% and expands to 100%. The message list keeps a fixed layout height so opening the sheet reveals more history without resizing or remounting it. The composer stays visible at both detents. During a pause-and-release gesture on iOS, the handle continued moving upward while the list and composer briefly moved down together.

Approach Result
Drive the fixed-height conversation from onPositionChange, using Reanimated worklets and layout offsets Preserved list height and worked during the drag. The content could fall out of step with the card after release. Each animated layout offset still passed through Fabric and Yoga.
Use translateY on the canvas, then replace the layout offsets on all four moving views Removed animated layout properties from those views. The canvas-only trial produced a larger snap, and the full transform variant still looked visibly rough in a manual test in the native Simulator window.
Bottom-align the fixed-height canvas in a viewport whose height follows the sheet Simplified the React layout. The viewport still depended on the sampled position, and the list and composer still moved backward after release.
Sample the iOS spring at CADisplayLink.targetTimestamp Reduced the typical error in an isolated marker test. The real chat still jumped after release. Sampling closer to the intended display time still leaves the follower in a separate presentation update.

Why the native host can keep the content aligned

During an iOS settle, Core Animation presents the card and its clip from keyframes. A display-link callback samples the spring for onPositionChange. A consumer can handle that event in a Reanimated UI worklet and write a transform without changing React state. The consumer still applies that transform separately from the card's Core Animation animation. Even with the same spring curve, the card and child can show different steps of it in a frame.

The reported position measures from the host's bottom to the card's top. The visible bottom also depends on the resolved card insets, scale, and clip. A static bottom: 0 inside the standard content wrapper attaches to the full-height layout box, so it can leave the composer below the visible clip at the compact detent. A screen-level overlay could anchor the composer independently, but would have to coordinate clipping, native scroll handoff, hit testing, keyboard, and dismissal across two separate view hierarchies.

The opt-in native slot uses the geometry the host already calculates. On iOS the card, clip and slot share the same Core Animation keyframes and start time. On Android the host updates them in the same geometry pass. The list layout remains fixed, and the same clip governs visibility, hit testing and scroll handoff below the header. This was the smoothest of the tested approaches and preserves the existing gesture physics.

Test plan

  • Built and installed a Fabric consumer with exact commit 029679c on iPhone 17 (iOS 27.2) and Pixel 9 (Android API 37).

  • Checked both detents, fast release, scroll handoff with an inverted list, clipped touch targets, keyboard and composer, rotation, changing the header inset, remounting the slot, and regular content sizing. In 16 sampled moving frames per platform, the composer stayed at the same position while the card expanded.

  • Verified drag reversal on iOS. The Android reversal recording was inconclusive. Accessibility was checked through the native trees and touch behavior. Screen-reader traversal remains to be checked.

  • 55 Bun tests, 35 focused Android JVM tests, Swift geometry and UIKit host tests passed. TypeScript, ESLint and the package build passed.

  • Manually compared the all-transform follower and the native anchor in the actual Fabric chat on the same iPhone 17 Pro simulator (iOS 26.4) in the native Simulator window. The follower remained visibly rough after release. The app owner confirmed the anchored build at 029679c moved smoothly. The test was visual on a simulator. Physical-iPhone frame timing remains unmeasured.

  • Verified the final property name in the generated Fabric schemas for iOS and Android. The rename passed 55 Bun tests, TypeScript, ESLint, the package build, and Swift syntax checking. The device runs above used the previous spelling at the cited commit.

Verified-by: lint + TypeScript + 53 Bun tests + Bob package build + iOS simulator SDK Swift typecheck + Swift anchor geometry tests
Verified-by: 55 Bun tests, TypeScript, ESLint, Bob, 35 Android JVM tests, NDK and ObjC++ syntax checks, Swift geometry and UIKit host tests
Verified-by: 55 Bun tests, TypeScript, ESLint, Bob, iOS and Android Fabric codegen, Swift syntax check

This branch has not been deployed

No deployments
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