React Native Advanced FlatList https://github.com/StarksJohn/react-native-advanced-flatlist
A powerful React Native FlatList component that provides advanced features including pagination, pull-to-refresh, single selection, loading states, and more.
- β Pagination Loading - Support for automatic pagination and infinite scrolling
- β Pull-to-Refresh - Built-in pull-to-refresh control
- β Single Selection - Support for single item selection functionality
- β Loading States - Built-in loading indicators
- β Empty State - Customizable empty list display
- β TypeScript - Complete TypeScript type support
- β Flexible Rendering - Support for custom list item rendering
- β Event Handling - Rich scroll and click event handling
npm install react-native-advanced-flatlist
# or
yarn add react-native-advanced-flatlist
import React, {useCallback, useRef} from 'react';
import {View, Text, TouchableOpacity} from 'react-native';
import {
AdvancedFlatList,
AdvancedFlatListRef,
FetchDataParams,
ListData,
ListItem,
RenderItemParams
} from 'react-native-advanced-flatlist';
interface MyItem extends ListItem {
title: string;
description: string;
}
const MyComponent = () => {
const flatListRef = useRef<AdvancedFlatListRef>(null);
// Fetch data function
const fetchData = useCallback(async ({pageIndex, pageSize}: FetchDataParams): Promise<ListData | null> => {
try {
// Replace with your API call
const response = await fetch(`/api/items?page=${pageIndex}&size=${pageSize}`);
const data = await response.json();
return {
items: data.items,
pageIndex: pageIndex,
needLoadMore: data.hasMore
};
} catch (error) {
console.error('Failed to fetch data:', error);
return null;
}
}, []);
// Custom render item
const renderItem = useCallback(({item, index, selected, onItemPress}: RenderItemParams) => {
const myItem = item as MyItem;
return (
<TouchableOpacity
onPress={() => onItemPress?.(item, index)}
style={{
padding: 15,
backgroundColor: selected ? '#e3f2fd' : 'white',
borderBottomWidth: 1,
borderBottomColor: '#eee'
}}
>
<Text style={{fontSize: 16, fontWeight: 'bold'}}>{myItem.title}</Text>
<Text style={{fontSize: 14, color: '#666'}}>{myItem.description}</Text>
</TouchableOpacity>
);
}, []);
// Handle selection change
const handleSelectionChange = useCallback((selectedItem: ListItem | null) => {
console.log('Selected item:', selectedItem);
}, []);
return (
<View style={{flex: 1}}>
<AdvancedFlatList
ref={flatListRef}
fetchData={fetchData}
renderItem={renderItem}
keyExtractor={(item) => item.id.toString()}
singleSelect={true}
onSingleSelectChange={handleSelectionChange}
autoRefresh={true}
pageSize={20}
emptyText="No items found"
showListEmptyComponent={true}
/>
</View>
);
};
export default MyComponent;
const CustomEmptyComponent = () => (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Custom empty state</Text>
</View>
);
<AdvancedFlatList
fetchData={fetchData}
renderItem={renderItem}
ListEmptyComponent={CustomEmptyComponent}
showListEmptyComponent={true}
/>
const HeaderComponent = () => (
<View style={{ padding: 20, backgroundColor: '#f5f5f5' }}>
<Text style={{ fontSize: 18, fontWeight: 'bold' }}>My List Header</Text>
</View>
);
<AdvancedFlatList
fetchData={fetchData}
renderItem={renderItem}
ListHeaderComponent={HeaderComponent}
/>
const flatListRef = useRef<AdvancedFlatListRef>(null);
// Refresh the list
const handleRefresh = () => {
flatListRef.current?.refresh();
};
// Scroll to top
const handleScrollToTop = () => {
flatListRef.current?.scrollToTop();
};
// Get current items
const getCurrentItems = () => {
const items = flatListRef.current?.getItems();
console.log('Current items:', items);
};
// Clear selection
const clearSelection = () => {
flatListRef.current?.clearSelection();
};
Prop | Type | Default | Description |
---|---|---|---|
fetchData |
(params: FetchDataParams) => Promise<ListData | null> |
Required | Function to fetch list data |
renderItem |
(params: RenderItemParams) => React.ReactNode |
undefined |
Custom render function for list items |
keyExtractor |
(item: ListItem) => string | number |
(item) => item.id |
Function to extract unique keys |
initialData |
Partial<ListData> |
{} |
Initial data for the list |
initPageIndex |
number |
0 |
Initial page index |
pageSize |
number |
20 |
Number of items per page |
autoRefresh |
boolean |
true |
Whether to auto-refresh on mount |
disabledRefresh |
boolean |
false |
Whether to disable pull-to-refresh |
singleSelect |
boolean |
false |
Enable single selection mode |
onSingleSelectChange |
(item: ListItem | null) => void |
undefined |
Callback for selection changes |
onItemPress |
(item: ListItem, index: number) => void |
undefined |
Callback for item press |
emptyText |
string |
'No data available' |
Text to show when list is empty |
showListEmptyComponent |
boolean |
true |
Whether to show empty component |
ListEmptyComponent |
React.ComponentType | React.ReactElement |
undefined |
Custom empty component |
ListHeaderComponent |
ReactNode |
undefined |
Header component |
style |
StyleProp<ViewStyle> |
{} |
Style for FlatList |
flatListBoxStyle |
StyleProp<ViewStyle> |
{} |
Style for container |
keyboardShouldPersistTaps |
'always' | 'never' | 'handled' |
'never' |
Keyboard handling |
onScrollBeginDrag |
(event: any) => void |
undefined |
Scroll begin callback |
onScrollEndDrag |
(event: any) => void |
undefined |
Scroll end callback |
Method | Type | Description |
---|---|---|
refresh |
(parentParams?: object) => void |
Manually trigger refresh |
scrollToTop |
() => void |
Scroll to top of list |
stopRefresh |
() => void |
Stop refresh indicator |
getItems |
() => ListItem[] |
Get current list items |
changeItemSelect |
(index: number) => void |
Toggle item selection |
clearSelection |
() => void |
Clear current selection |
interface ListItem {
id: string | number;
selected?: boolean;
[key: string]: any;
}
interface ListData {
items: ListItem[];
pageIndex?: number;
needLoadMore?: boolean;
}
interface FetchDataParams {
pageIndex: number;
pageSize: number;
prevItems?: ListItem[];
}
interface RenderItemParams {
item: ListItem;
index: number;
selected?: boolean;
onItemPress?: (item: ListItem, index: number) => void;
}
This React Native library was created as an optimized and publishable version based on the original CsxFlatList.tsx
component, transforming it into a complete, production-ready npm package.
- β Fixed all compilation errors and improved TypeScript type safety
- β Optimized component performance with React.memo and useCallback
- β Added comprehensive type definitions and self-contained types
- β Cleaned up console logging with proper English comments
- β Removed external dependencies for React/React Native types
- β Created self-contained type definitions for maximum compatibility
- β Optimized for performance with proper memoization
- β Added comprehensive error handling and TypeScript strict mode compliance
- β Pagination: Automatic loading with customizable page size
- β Pull-to-Refresh: Built-in refresh control with loading states
- β Single Selection: Item selection with change callbacks
- β Custom Rendering: Support for custom item and empty state components
- β Loading Indicators: Built-in loading states for better UX
- β Empty State Management: Customizable empty list handling
- β TypeScript Support: Complete type safety with exported interfaces
- β Imperative API: Methods for external control (refresh, scroll, etc.)
- Name:
react-native-advanced-flatlist
- Version: 1.0.4
- Size: Lightweight with zero runtime dependencies
- Files: Comprehensive package including source and compiled code
- Dependencies: Zero runtime dependencies (only peer dependencies)
Feature | Original CsxFlatList | Advanced FlatList |
---|---|---|
TypeScript | β Compilation errors | β Fully typed & compiled |
Dependencies | β Internal dependencies | β Zero external deps |
Documentation | β Limited | β Comprehensive |
Examples | β None | β Complete examples |
npm Ready | β No | β Yes |
GitHub Ready | β No | β Yes |
Community | β Private | β Open source |
- π¦ Professional npm Package - Complete with documentation and examples
- π§ TypeScript Library Development - Advanced type safety and compilation
- π Comprehensive Documentation - Usage examples and API reference
- π― React Native Performance Optimization - Proper memoization and rendering
- π Open Source Contribution - Available for the React Native community
- Add unit tests with Jest
- Set up CI/CD pipeline
- Add more advanced features (multi-select, sorting, filtering)
- Create video tutorials
- Add animation support
- Performance benchmarking
MIT
Pull Requests and Issues are welcome!
- Enhanced release automation system
- Improved documentation and publishing guides
- Updated TypeScript configurations
- Performance optimizations
- Bug fixes and stability improvements
- Enhanced error handling
- Improved type definitions
- Bug fixes and minor improvements
- Initial release
- Support for pagination loading, pull-to-refresh, single selection and other core features