This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
bun run build- Build the package using tsup and run post-build scriptbun run publish:manual- Build and publish to npm manuallybun run lint- Check code formatting with Biome for src and examplebun run lint:fix- Auto-fix formatting issues with Biome for src and example
The repository includes a React Native example app in the example/ directory:
cd example && bun i && bun run ios- Run the example app on iOS- Example app uses Expo and demonstrates various Legend List features
- Uses tsup for TypeScript compilation with multiple entry points:
src/index.ts(main export)src/integrations/animated.tsx(animated variant)src/integrations/reanimated.tsx(reanimated variant)src/integrations/keyboard-controller.tsx(keyboard integration)
- Post-build script (
posttsup.ts) copies LICENSE, CHANGELOG.md, README.md to dist and modifies package.json for publishing - Builds to both CommonJS and ESM formats with TypeScript declarations
src/components/- React components (LegendList, Container, ListComponent, etc.)src/state/- State management system (state.tsx, ContextContainer.ts)src/core/- Core logic functions (scroll handling, positioning, viewability)src/utils/- Utility functions (helpers, calculations, checks)src/hooks/- Custom React hookssrc/integrations/- Optional integrations (animated, reanimated, keyboard-controller)
Legend List is a high-performance React Native list component designed as a drop-in replacement for FlatList with better performance, especially for dynamically sized items.
LegendList (src/components/LegendList.tsx): Main component that wraps functionality in a StateProvider
- Handles virtualization logic, scroll management, and item positioning
- Manages anchor elements for
maintainVisibleContentPosition - Implements advanced scroll adjustment and jump prevention
- Uses container recycling for optimal performance
State Management (src/state/state.tsx): Global state management using observable patterns
- Manages container positions, item data, and scroll state
- Provides reactive updates to child components
- Custom state system inspired by Legend State with optimized listeners
Container System (src/components/Container.tsx, src/components/Containers.tsx): Manages item rendering containers
- Implements container recycling when
recycleItemsis enabled - Handles absolute positioning of list items
- Manages container allocation and deallocation
Scroll Adjustment (src/core/ScrollAdjustHandler.ts): Handles complex scroll position adjustments
- Prevents scroll jumps when items are added/removed
- Manages scroll position during layout changes
Dynamic Item Sizing: Items can have varying heights without performance penalties
- Uses
getEstimatedItemSizeorestimatedItemSizefor initial estimates - Measures actual sizes on layout and adjusts total size calculations
- Maintains position accuracy through size change events
Bidirectional Infinite Lists: Supports infinite scrolling in both directions
onStartReachedandonEndReachedcallbacks with configurable thresholds- Maintains scroll position when items are added to the beginning
Chat UI Support:
alignItemsAtEndaligns content to bottom for chat interfacesmaintainScrollAtEndautomatically scrolls to end when new items are added- Avoids need for inverted lists which cause animation issues
Column Support: Multi-column layouts via numColumns prop
- Manages row heights when items have different sizes within the same row
- Handles column-aware positioning and gap calculations via
columnWrapperStyle
Virtualization: Only renders items in the visible area plus buffer zones
drawDistancecontrols how far ahead/behind to render items- Dynamic buffer adjustment based on scroll velocity
- Container recycling to minimize React element creation/destruction
Scroll Jump Prevention: Sophisticated system to prevent visual jumps
- Anchor element tracking for
maintainVisibleContentPosition - Scroll history tracking for velocity calculations
- Position adjustment when item sizes change
Batched Updates: Groups layout calculations to reduce renders
- Uses
requestAnimationFramefor batching size change calculations - Optimizes container position updates
Legend List is designed as a drop-in FlatList replacement:
<LegendList
data={data}
renderItem={renderItem}
keyExtractor={(item) => item.id}
recycleItems={true}
/>- Animated:
@legendapp/list/animated- Works with React Native Animated - Reanimated:
@legendapp/list/reanimated- Works with React Native Reanimated - Keyboard Controller:
@legendapp/list/keyboard-controller- Integrates with react-native-keyboard-controller
Supports advanced viewability detection:
- Compatible with FlatList's
viewabilityConfigandonViewableItemsChanged - Custom hooks available:
useViewability,useViewabilityAmount
- When working with container recycling (
recycleItems={true}), be cautious about local state in item components - The
keyExtractoris crucial for performance and correct behavior when data changes - Use
getEstimatedItemSizefor better performance with varying item sizes - The component uses advanced scroll position management that should not be interfered with directly
- Biome (
biome.json): Used for linting and formatting with specific rules for the project - TypeScript (
tsconfig.json): Configured for React Native with path mappings for internal imports - Cursor Rules:
.cursor/rules/changelog.mdccontains guidelines for maintaining the changelog
To test changes, use the comprehensive example app which demonstrates various scenarios including dynamic sizing, infinite loading, chat interfaces, and performance comparisons with FlatList.