UNPKG

create-expo-cljs-app

Version:

Create a react native application with Expo and Shadow-CLJS!

197 lines (189 loc) 6.13 kB
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow * @format */ 'use strict'; import * as React from 'react'; import View from '../../../exports/View'; import VirtualizedList from '../VirtualizedList'; import invariant from 'fbjs/lib/invariant'; import type { ViewToken } from '../ViewabilityHelper'; type Item = any; export type SectionBase<SectionItemT> = { /** * The data for rendering items in this section. */ data: $ReadOnlyArray<SectionItemT>, /** * Optional key to keep track of section re-ordering. If you don't plan on re-ordering sections, * the array index will be used by default. */ key?: string, // Optional props will override list-wide props just for this section. renderItem?: ?(info: { item: SectionItemT, index: number, section: SectionBase<SectionItemT>, separators: { highlight: () => void, unhighlight: () => void, updateProps: (select: 'leading' | 'trailing', newProps: Object) => void, ... }, ... }) => null | React.Element<any>, ItemSeparatorComponent?: ?React.ComponentType<any>, keyExtractor?: (item: SectionItemT, index?: ?number) => string, ... }; type RequiredProps<SectionT: SectionBase<any>> = {| sections: $ReadOnlyArray<SectionT> |}; type OptionalProps<SectionT: SectionBase<any>> = {| /** * Default renderer for every item in every section. */ renderItem?: (info: { item: Item, index: number, section: SectionT, separators: { highlight: () => void, unhighlight: () => void, updateProps: (select: 'leading' | 'trailing', newProps: Object) => void, ... }, ... }) => null | React.Element<any>, /** * Rendered at the top of each section. These stick to the top of the `ScrollView` by default on * iOS. See `stickySectionHeadersEnabled`. */ renderSectionHeader?: ?(info: { section: SectionT, ... }) => null | React.Element<any>, /** * Rendered at the bottom of each section. */ renderSectionFooter?: ?(info: { section: SectionT, ... }) => null | React.Element<any>, /** * Rendered at the top and bottom of each section (note this is different from * `ItemSeparatorComponent` which is only rendered between items). These are intended to separate * sections from the headers above and below and typically have the same highlight response as * `ItemSeparatorComponent`. Also receives `highlighted`, `[leading/trailing][Item/Separator]`, * and any custom props from `separators.updateProps`. */ SectionSeparatorComponent?: ?React.ComponentType<any>, /** * Makes section headers stick to the top of the screen until the next one pushes it off. Only * enabled by default on iOS because that is the platform standard there. */ stickySectionHeadersEnabled?: boolean, onEndReached?: ?({ distanceFromEnd: number, ... }) => void, |}; type VirtualizedListProps = React.ElementProps<typeof VirtualizedList>; export type Props<SectionT> = {| ...RequiredProps<SectionT>, ...OptionalProps<SectionT>, ...$Diff<VirtualizedListProps, { renderItem: $PropertyType<VirtualizedListProps, 'renderItem'>, ... }>, |}; export type ScrollToLocationParamsType = {| animated?: ?boolean, itemIndex: number, sectionIndex: number, viewOffset?: number, viewPosition?: number, |}; type DefaultProps = {| ...typeof VirtualizedList.defaultProps, data: $ReadOnlyArray<Item>, |}; type State = { childProps: VirtualizedListProps, ... }; /** * Right now this just flattens everything into one list and uses VirtualizedList under the * hood. The only operation that might not scale well is concatting the data arrays of all the * sections when new props are received, which should be plenty fast for up to ~10,000 items. */ declare class VirtualizedSectionList<SectionT: SectionBase<any>> extends React.PureComponent<Props<SectionT>, State> { static defaultProps: DefaultProps, scrollToLocation(params: ScrollToLocationParamsType): any, getListRef(): ?React.ElementRef<typeof VirtualizedList>, render(): React.Node, _getItem: any, _keyExtractor: any, _subExtractor(index: number): ?{ section: SectionT, // Key of the section or combined key for section + item key: string, // Relative index within the section index: ?number, // True if this is the section header header?: ?boolean, leadingItem?: ?Item, leadingSection?: ?SectionT, trailingItem?: ?Item, trailingSection?: ?SectionT, ... }, _convertViewable: any, _onViewableItemsChanged: any, _renderItem: any, _onUpdateSeparator: any, _getSeparatorComponent(index: number, info?: ?Object, listItemCount: number): ?React.ComponentType<any>, _cellRefs: any, _listRef: ?React.ElementRef<typeof VirtualizedList>, _captureRef: any, } type ItemWithSeparatorCommonProps = $ReadOnly<{| leadingItem: ?Item, leadingSection: ?Object, section: Object, trailingItem: ?Item, trailingSection: ?Object, |}>; type ItemWithSeparatorProps = $ReadOnly<{| ...ItemWithSeparatorCommonProps, LeadingSeparatorComponent: ?React.ComponentType<any>, SeparatorComponent: ?React.ComponentType<any>, cellKey: string, index: number, item: Item, onUpdateSeparator: (cellKey: string, newProps: Object) => void, prevCellKey?: ?string, renderItem: Function, inverted: boolean, |}>; type ItemWithSeparatorState = { separatorProps: $ReadOnly<{| highlighted: false, ...ItemWithSeparatorCommonProps, |}>, leadingSeparatorProps: $ReadOnly<{| highlighted: false, ...ItemWithSeparatorCommonProps, |}>, ... }; declare class ItemWithSeparator extends React.Component<ItemWithSeparatorProps, ItemWithSeparatorState> { state: any, _separators: any, static getDerivedStateFromProps(props: ItemWithSeparatorProps, prevState: ItemWithSeparatorState): ?ItemWithSeparatorState, updateSeparatorProps(newProps: Object): any, render(): any, } export default VirtualizedSectionList;