From dfa3a0eae67a4477e13e5406ff2bd2d91302c229 Mon Sep 17 00:00:00 2001 From: Konstantin Koulechov Date: Thu, 30 May 2019 15:34:27 +0200 Subject: [PATCH 1/2] renderHeader() for React Native --- README.md | 1 + src/core/RecyclerListView.tsx | 4 ++++ src/core/scrollcomponent/BaseScrollComponent.tsx | 1 + src/platform/reactnative/scrollcomponent/ScrollComponent.tsx | 2 ++ 4 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 0dfb54a4..fbc2bb92 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ not be as fast. | 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 | diff --git a/src/core/RecyclerListView.tsx b/src/core/RecyclerListView.tsx index 77f7a921..ec01b00f 100644 --- a/src/core/RecyclerListView.tsx +++ b/src/core/RecyclerListView.tsx @@ -93,6 +93,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 }; initialOffset?: number; initialRenderIndex?: number; @@ -643,6 +644,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, diff --git a/src/core/scrollcomponent/BaseScrollComponent.tsx b/src/core/scrollcomponent/BaseScrollComponent.tsx index 658836cf..271932c7 100644 --- a/src/core/scrollcomponent/BaseScrollComponent.tsx +++ b/src/core/scrollcomponent/BaseScrollComponent.tsx @@ -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; diff --git a/src/platform/reactnative/scrollcomponent/ScrollComponent.tsx b/src/platform/reactnative/scrollcomponent/ScrollComponent.tsx index 2cc7f1b8..70159f12 100644 --- a/src/platform/reactnative/scrollcomponent/ScrollComponent.tsx +++ b/src/platform/reactnative/scrollcomponent/ScrollComponent.tsx @@ -51,6 +51,7 @@ export default class ScrollComponent extends BaseScrollComponent { // externalScrollView, // canChangeSize, // renderFooter, + // renderHeader, // isHorizontal, // scrollThrottle, // ...props, @@ -64,6 +65,7 @@ export default class ScrollComponent extends BaseScrollComponent { onScroll={this._onScroll} onLayout={(!this._isSizeChangedCalledOnce || this.props.canChangeSize) ? this._onLayout : this.props.onLayout}> + {this.props.renderHeader ? this.props.renderHeader() : null} Date: Thu, 30 May 2019 16:06:49 +0200 Subject: [PATCH 2/2] Without /dist folder --- package.json | 2 +- src/core/RecyclerListView.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ce80dae2..b0a70771 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "recyclerlistview", "version": "2.0.0-beta.4", "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", diff --git a/src/core/RecyclerListView.tsx b/src/core/RecyclerListView.tsx index ec01b00f..462a9754 100644 --- a/src/core/RecyclerListView.tsx +++ b/src/core/RecyclerListView.tsx @@ -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";