import React from 'react'; import { FlatList, Platform, RefreshControl, Text, View } from 'react-native'; import { SIZE, WEIGHT } from '../../common/common'; import { useTracked } from '../../provider'; import { ACTIONS } from '../../provider/actions'; import { eSendEvent } from '../../services/eventManager'; import { eClearSearch, eScrollEvent } from '../../services/events'; import { hexToRGBA } from '../../utils/utils'; import { NotebookItem } from '../NotebookItem'; import SelectionWrapper from '../SelectionWrapper'; import { useSafeArea } from 'react-native-safe-area-context'; const SimpleList = ({ data, type, placeholder, onRefresh, renderItem, focused, refreshing, placeholderText, pinned = null, isMove, hideMore, noteToMove, }) => { const [state, dispatch] = useTracked(); const { colors, selectionMode } = state; const searchResults = { ...state.searchResults }; const insets = useSafeArea(); const _onScroll = event => { if (!event) return; let y = event.nativeEvent.contentOffset.y; eSendEvent(eScrollEvent, y); }; const _ListFooterComponent = data[0] ? ( - End - ) : null; const _ListHeaderComponent_S = searchResults.type === type && searchResults.results.length > 0 ? ( Search Results for {searchResults.keyword} { eSendEvent(eClearSearch); }} style={{ fontFamily: WEIGHT.regular, color: colors.errorText, fontSize: SIZE.xs, }}> Clear ) : ( {pinned && pinned.notebooks && pinned.notebooks.length > 0 ? ( <> item.id.toString()} renderItem={({ item, index }) => item.type === 'notebook' ? ( { if (!selectionMode) { dispatch({ type: ACTIONS.SELECTION_MODE, enabled: true, }); } dispatch({ type: ACTIONS.SELECTED_ITEMS, item: item }); }} noteToMove={noteToMove} item={item} pinned={true} index={index} colors={colors} /> ) : null } /> ) : null} ); const _ListEmptyComponent = ( <> {placeholder} {placeholderText} ); const _listKeyExtractor = (item, index) => item.id.toString() + index.toString(); return ( 0 ? searchResults.results : data } refreshControl={ } keyExtractor={_listKeyExtractor} ListFooterComponent={_ListFooterComponent} onScroll={_onScroll} ListHeaderComponent={_ListHeaderComponent_S} ListEmptyComponent={_ListEmptyComponent} contentContainerStyle={{ width: '100%', alignSelf: 'center', minHeight: '100%', }} style={{ height: '100%', }} renderItem={renderItem} /> ); }; export default SimpleList;