Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added renderHeader prop for React Native #704

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ In case you cannot determine heights of items in advance just set `forceNonDeter
| onVisibleIndicesChanged | No | TOnItemStatusChanged | Provides visible index; helpful in sending impression events |
| onVisibleIndexesChanged | No | TOnItemStatusChanged | (Deprecated in 2.0 beta) Provides visible index; helpful in sending impression events |
| renderFooter | No | () => JSX.Element \| JSX.Element[] \| null | Provide this method if you want to render a footer. Helpful in showing a loader while doing incremental loads |
| renderHeader | No | () => JSX.Element \| JSX.Element[] \| null | **React Native only**. Provide this method if you want to render a header |
| initialRenderIndex | No | number | Specify the initial item index you want rendering to start from. Preferred over initialOffset if both specified |
| scrollThrottle | No | number |iOS only; Scroll throttle duration |
| canChangeSize | No | boolean | Specify if size can change |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "recyclerlistview",
"version": "3.2.0-beta.1",
"description": "The listview that you need and deserve. It was built for performance, uses cell recycling to achieve smooth scrolling.",
"main": "dist/reactnative/index.js",
"main": "src/index.ts",
"types": "dist/reactnative/index.d.ts",
"scripts": {
"build": "sh scripts/build.sh",
Expand Down
6 changes: 5 additions & 1 deletion src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* TODO: Observe size changes on web to optimize for reflowability
* TODO: Solve //TSI
*/
import debounce = require("lodash.debounce");
const debounce = require("lodash.debounce");
import * as PropTypes from "prop-types";
import * as React from "react";
import { ObjectUtil, Default } from "ts-object-utils";
Expand Down Expand Up @@ -91,6 +91,7 @@ export interface RecyclerListViewProps {
onVisibleIndexesChanged?: TOnItemStatusChanged;
onVisibleIndicesChanged?: TOnItemStatusChanged;
renderFooter?: () => JSX.Element | JSX.Element[] | null;
renderHeader?: () => JSX.Element | JSX.Element[] | null;
externalScrollView?: { new(props: ScrollViewDefaultProps): BaseScrollView };
layoutSize?: Dimension;
initialOffset?: number;
Expand Down Expand Up @@ -832,6 +833,9 @@ RecyclerListView.propTypes = {

//Provide this method if you want to render a footer. Helpful in showing a loader while doing incremental loads.
renderFooter: PropTypes.func,

//Provide this method if you want to render a header
renderHeader: PropTypes.func,

//Specify the initial item index you want rendering to start from. Preferred over initialOffset if both are specified.
initialRenderIndex: PropTypes.number,
Expand Down
1 change: 1 addition & 0 deletions src/core/scrollcomponent/BaseScrollComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ScrollComponentProps {
externalScrollView?: { new(props: ScrollViewDefaultProps): BaseScrollView };
isHorizontal?: boolean;
renderFooter?: () => JSX.Element | JSX.Element[] | null;
renderHeader?: () => JSX.Element | JSX.Element[] | null;
scrollThrottle?: number;
useWindowScroll?: boolean;
onLayout?: any;
Expand Down
2 changes: 2 additions & 0 deletions src/platform/reactnative/scrollcomponent/ScrollComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default class ScrollComponent extends BaseScrollComponent {
// externalScrollView,
// canChangeSize,
// renderFooter,
// renderHeader,
// isHorizontal,
// scrollThrottle,
// ...props,
Expand All @@ -84,6 +85,7 @@ export default class ScrollComponent extends BaseScrollComponent {
onScroll={this._onScroll}
onLayout={(!this._isSizeChangedCalledOnce || this.props.canChangeSize) ? this._onLayout : this.props.onLayout}>
<View style={{ flexDirection: this.props.isHorizontal ? "row" : "column" }}>
{this.props.renderHeader ? this.props.renderHeader() : null}
{renderContentContainer(contentContainerProps, this.props.children)}
{this.props.renderFooter ? this.props.renderFooter() : null}
</View>
Expand Down