From 4b95e238e1c1bc2e9877afda27a9669c4949e1b3 Mon Sep 17 00:00:00 2001 From: Eduardo Pinheiro Date: Wed, 21 Nov 2018 12:00:29 +0000 Subject: [PATCH 01/10] Added new scroll options and new find index options based on approx visible index added scrollToApproxFirstVisibleIndex, scrollToApproxLastVisibleIndex, scrollToApproxMiddleVisibleIndex. added findApproxLastVisibleIndex, findApproxMiddleVisibleIndex --- src/core/RecyclerListView.tsx | 33 +++++++++++++++++++++++++++++++-- src/core/ViewabilityTracker.ts | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/core/RecyclerListView.tsx b/src/core/RecyclerListView.tsx index 2ebb043a..6123a922 100644 --- a/src/core/RecyclerListView.tsx +++ b/src/core/RecyclerListView.tsx @@ -64,8 +64,9 @@ const refreshRequestDebouncer = debounce((executable: () => void) => { /*** * This is the main component, please refer to samples to understand how to use. * For advanced usage check out prop descriptions below. - * You also get common methods such as: scrollToIndex, scrollToItem, scrollToTop, scrollToEnd, scrollToOffset, getCurrentScrollOffset, - * findApproxFirstVisibleIndex. + * You also get common methods such as: scrollToApproxFirstVisibleIndex, scrollToApproxLastVisibleIndex, scrollToApproxMiddleVisibleIndex, + * scrollToIndex, scrollToItem, scrollToTop, scrollToEnd, scrollToOffset, getCurrentScrollOffset, findApproxFirstVisibleIndex, findApproxLastVisibleIndex, + * findApproxMiddleVisibleIndex. * You'll need a ref to Recycler in order to call these * Needs to have bounded size in all cases other than window scrolling (web). * @@ -270,6 +271,24 @@ export default class RecyclerListView

{ if (this._scrollComponent) { if (this.props.isHorizontal) { @@ -313,6 +332,16 @@ export default class RecyclerListView

= 0; i--) { if (this._isHorizontal) { @@ -123,6 +122,24 @@ export default class ViewabilityTracker { return result; } + public findFirstLogicallyVisibleIndex(): number { + const relevantIndex = this._findFirstVisibleIndexUsingBS(0.001); + const result = this.findLogicallyVisibleIndex(relevantIndex); + return result; + } + + public findLastLogicallyVisibleIndex(): number { + const relevantIndex = this._findLastVisibleIndexUsingBS(0.001); + const result = this.findLogicallyVisibleIndex(relevantIndex); + return result; + } + + public findMiddleLogicallyVisibleIndex(): number { + const relevantIndex = this._findMiddleVisibleIndex(); + const result = this.findLogicallyVisibleIndex(relevantIndex); + return result; + } + public updateRenderAheadOffset(renderAheadOffset: number): void { this._renderAheadOffset = Math.max(0, renderAheadOffset); this.forceRefreshWithOffset(this._currentOffset); @@ -180,6 +197,17 @@ export default class ViewabilityTracker { return BinarySearch.findClosestHigherValueIndex(count, this._visibleWindow.start + bias, this._valueExtractorForBinarySearch); } + private _findLastVisibleIndexUsingBS(bias = 0): number { + const count = this._layouts.length; + return BinarySearch.findClosestHigherValueIndex(count, this._visibleWindow.end - bias, this._valueExtractorForBinarySearch); + } + + private _findMiddleVisibleIndex(): number { + const count = this._layouts.length; + const targetValue = Math.round( (this._visibleWindow.start + this._visibleWindow.end) / 2 ); + return BinarySearch.findClosestHigherValueIndex(count, targetValue, this._valueExtractorForBinarySearch); + } + private _valueExtractorForBinarySearch = (index: number): number => { const itemRect = this._layouts[index]; this._setRelevantBounds(itemRect, this._relevantDim); From ff15772dbefa036f9a6d36d0e7b4a998646ec237 Mon Sep 17 00:00:00 2001 From: Edu Date: Sat, 7 Sep 2019 21:30:08 +0100 Subject: [PATCH 02/10] some changes --- package.json | 1 + scripts/publish-local.sh | 3 ++- .../web/scrollcomponent/ScrollViewer.tsx | 19 ++++++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 5ecb4fa3..082ecfda 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "dependencies": { "lodash.debounce": "4.0.8", "prop-types": "15.5.8", + "react-alert": "^4.0.2", "ts-object-utils": "0.0.5" }, "peerDependencies": { diff --git a/scripts/publish-local.sh b/scripts/publish-local.sh index db50797c..b2b861a5 100644 --- a/scripts/publish-local.sh +++ b/scripts/publish-local.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash set -e -TARGET=$"/Users/talha.naqvi/Documents/Work/RLV-Demo/node_modules/recyclerlistview/dist" #target-path +#TARGET=$"/Users/talha.naqvi/Documents/Work/RLV-Demo/node_modules/recyclerlistview/dist" #target-path +TARGET=$"/Users/edup/develop/Biti/biti.tv/biti-tv-react/node_modules/recyclerlistview/dist" #target-path npm run build diff --git a/src/platform/web/scrollcomponent/ScrollViewer.tsx b/src/platform/web/scrollcomponent/ScrollViewer.tsx index cb6ec074..2df74e5a 100644 --- a/src/platform/web/scrollcomponent/ScrollViewer.tsx +++ b/src/platform/web/scrollcomponent/ScrollViewer.tsx @@ -144,17 +144,26 @@ export default class ScrollViewer extends BaseScrollView { start = Math.min(offset + 800, start); } const change = offset - start; - const increment = 20; const duration = 200; - const animateScroll = (elapsedTime: number) => { - elapsedTime += increment; + let elapsedTime = 0; + let lastRenderTimestamp: number = -1; + const animateScroll = (timestamp: number) => { + + if ( lastRenderTimestamp === -1 ) { + lastRenderTimestamp = timestamp - 20; + } + + const deltaTime = timestamp - lastRenderTimestamp; + lastRenderTimestamp = timestamp; + elapsedTime = Math.min ( elapsedTime + deltaTime, duration ); + const position = this._easeInOut(elapsedTime, start, change, duration); this._setRelevantOffset(position); if (elapsedTime < duration) { - window.setTimeout(() => animateScroll(elapsedTime), increment); + window.requestAnimationFrame(animateScroll); } }; - animateScroll(0); + window.requestAnimationFrame(animateScroll); } private _startListeningToDivEvents(): void { From bb07c5f88e4dbf8fd21ef0c0e5686c0abb8d5038 Mon Sep 17 00:00:00 2001 From: Eduardo Pinheiro Date: Mon, 5 Oct 2020 17:27:55 +0100 Subject: [PATCH 03/10] added scripts folder --- .npmignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.npmignore b/.npmignore index 13ae3c7c..d17cf412 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,6 @@ node_modules/ samples/ -scripts/ +#scripts/ .idea/ .babelrc .travis.yml From 92c0c52d085e3ef98f026038c6b764eb60d5a8df Mon Sep 17 00:00:00 2001 From: Eduardo Pinheiro Date: Mon, 5 Oct 2020 17:32:11 +0100 Subject: [PATCH 04/10] added postinstall hook --- package.json | 3 ++- scripts/publish-local.sh | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 082ecfda..0af533d7 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "clean": "sh scripts/clean.sh", "release": "sh scripts/publish-latest.sh", "release-beta": "sh scripts/publish-beta.sh", - "release-local": "sh scripts/publish-local.sh" + "release-local": "sh scripts/publish-local.sh", + "postinstall": "sh scripts/build.sh" }, "keywords": [ "react-native", diff --git a/scripts/publish-local.sh b/scripts/publish-local.sh index b2b861a5..db50797c 100644 --- a/scripts/publish-local.sh +++ b/scripts/publish-local.sh @@ -1,8 +1,7 @@ #!/usr/bin/env bash set -e -#TARGET=$"/Users/talha.naqvi/Documents/Work/RLV-Demo/node_modules/recyclerlistview/dist" #target-path -TARGET=$"/Users/edup/develop/Biti/biti.tv/biti-tv-react/node_modules/recyclerlistview/dist" #target-path +TARGET=$"/Users/talha.naqvi/Documents/Work/RLV-Demo/node_modules/recyclerlistview/dist" #target-path npm run build From b0fb9d6fbe0463415993faa58d7e9e27f4260d92 Mon Sep 17 00:00:00 2001 From: Eduardo Pinheiro Date: Mon, 5 Oct 2020 17:39:21 +0100 Subject: [PATCH 05/10] added postinstall hook --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0af533d7..47cb7f07 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "release": "sh scripts/publish-latest.sh", "release-beta": "sh scripts/publish-beta.sh", "release-local": "sh scripts/publish-local.sh", - "postinstall": "sh scripts/build.sh" + "postinstall": "npm install && sh scripts/build.sh" }, "keywords": [ "react-native", From e940d5a1180ea8c5d22aee32439c8906f27ab96f Mon Sep 17 00:00:00 2001 From: Eduardo Pinheiro Date: Mon, 5 Oct 2020 17:45:46 +0100 Subject: [PATCH 06/10] added postinstall hook --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47cb7f07..e8aea4b1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "release": "sh scripts/publish-latest.sh", "release-beta": "sh scripts/publish-beta.sh", "release-local": "sh scripts/publish-local.sh", - "postinstall": "npm install && sh scripts/build.sh" + "prepare": "sh scripts/build.sh" }, "keywords": [ "react-native", From 4fa5757f4ad20359325ef05ba3ff1e098ff46883 Mon Sep 17 00:00:00 2001 From: Eduardo Pinheiro Date: Mon, 5 Oct 2020 17:47:29 +0100 Subject: [PATCH 07/10] added postinstall hook --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e8aea4b1..0af533d7 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "release": "sh scripts/publish-latest.sh", "release-beta": "sh scripts/publish-beta.sh", "release-local": "sh scripts/publish-local.sh", - "prepare": "sh scripts/build.sh" + "postinstall": "sh scripts/build.sh" }, "keywords": [ "react-native", From 5b9fbb305e97547cd2c9ae1af32e55b10b512a8b Mon Sep 17 00:00:00 2001 From: Eduardo Pinheiro Date: Mon, 5 Oct 2020 17:55:51 +0100 Subject: [PATCH 08/10] added postinstall hook --- src/core/RecyclerListView.tsx | 4 ++-- src/core/scrollcomponent/BaseScrollComponent.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/RecyclerListView.tsx b/src/core/RecyclerListView.tsx index 6123a922..07fcab34 100644 --- a/src/core/RecyclerListView.tsx +++ b/src/core/RecyclerListView.tsx @@ -95,7 +95,7 @@ export interface RecyclerListViewProps { onEndReachedThreshold?: number; onVisibleIndexesChanged?: TOnItemStatusChanged; renderFooter?: () => JSX.Element | JSX.Element[] | null; - externalScrollView?: { new(props: ScrollViewDefaultProps): BaseScrollView }; + externalScrollView?: new(props: ScrollViewDefaultProps) => BaseScrollView; initialOffset?: number; initialRenderIndex?: number; scrollThrottle?: number; @@ -566,7 +566,7 @@ export default class RecyclerListView

{ + private _generateRenderStack(): T[] { const renderedItems = []; for (const key in this.state.renderStack) { if (this.state.renderStack.hasOwnProperty(key)) { diff --git a/src/core/scrollcomponent/BaseScrollComponent.tsx b/src/core/scrollcomponent/BaseScrollComponent.tsx index 658836cf..e7628c31 100644 --- a/src/core/scrollcomponent/BaseScrollComponent.tsx +++ b/src/core/scrollcomponent/BaseScrollComponent.tsx @@ -8,7 +8,7 @@ export interface ScrollComponentProps { contentHeight: number; contentWidth: number; canChangeSize?: boolean; - externalScrollView?: { new(props: ScrollViewDefaultProps): BaseScrollView }; + externalScrollView?: new(props: ScrollViewDefaultProps) => BaseScrollView; isHorizontal?: boolean; renderFooter?: () => JSX.Element | JSX.Element[] | null; scrollThrottle?: number; From d3964e6629129d548a81479fee6db5f9a3664818 Mon Sep 17 00:00:00 2001 From: Eduardo Pinheiro Date: Mon, 5 Oct 2020 17:59:43 +0100 Subject: [PATCH 09/10] added postinstall hook --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0af533d7..f40eba8b 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "release": "sh scripts/publish-latest.sh", "release-beta": "sh scripts/publish-beta.sh", "release-local": "sh scripts/publish-local.sh", + "prepare": "npm install --only=dev", "postinstall": "sh scripts/build.sh" }, "keywords": [ From 1ab65ec0eecf5ae8a8fbd09c0766c749bea33d23 Mon Sep 17 00:00:00 2001 From: Eduardo Pinheiro Date: Mon, 5 Oct 2020 18:10:28 +0100 Subject: [PATCH 10/10] added postinstall hook --- package.json | 4 +--- src/core/RecyclerListView.tsx | 2 +- tsconfig.json | 4 +++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f40eba8b..082ecfda 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,7 @@ "clean": "sh scripts/clean.sh", "release": "sh scripts/publish-latest.sh", "release-beta": "sh scripts/publish-beta.sh", - "release-local": "sh scripts/publish-local.sh", - "prepare": "npm install --only=dev", - "postinstall": "sh scripts/build.sh" + "release-local": "sh scripts/publish-local.sh" }, "keywords": [ "react-native", diff --git a/src/core/RecyclerListView.tsx b/src/core/RecyclerListView.tsx index 07fcab34..fffa0167 100644 --- a/src/core/RecyclerListView.tsx +++ b/src/core/RecyclerListView.tsx @@ -566,7 +566,7 @@ export default class RecyclerListView

{ const renderedItems = []; for (const key in this.state.renderStack) { if (this.state.renderStack.hasOwnProperty(key)) { diff --git a/tsconfig.json b/tsconfig.json index c9400d72..8a73b92c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,6 +12,8 @@ "removeComments": false, "jsx": "react", "sourceMap": true, - "skipLibCheck": true + "skipLibCheck": true, + "strictNullChecks": false, + "noImplicitAny": false } }