From 0a8bfa8fb6ab6f527785db968178264c2e10a564 Mon Sep 17 00:00:00 2001 From: mohitjainblr Date: Mon, 11 Jan 2021 17:00:06 +0530 Subject: [PATCH] Fixed first visible index issue --- package.json | 2 +- src/utils/BinarySearch.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a5584d85..ce3cf931 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "recyclerlistview", - "version": "3.0.5-beta.1", + "version": "3.0.10", "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", "types": "dist/reactnative/index.d.ts", diff --git a/src/utils/BinarySearch.ts b/src/utils/BinarySearch.ts index 119b7703..82acbb29 100644 --- a/src/utils/BinarySearch.ts +++ b/src/utils/BinarySearch.ts @@ -10,7 +10,8 @@ export default class BinarySearch { let high = size - 1; let mid = Math.floor((low + high) / 2); let lastValue = 0; - let absoluteLastDiff = Math.abs(valueExtractor(mid) - targetValue); + const initialDiff = (valueExtractor(mid) - targetValue); + let absoluteLastDiff = initialDiff >= 0 ? initialDiff : Number.MAX_SAFE_INTEGER; let result = mid; let diff = 0; let absoluteDiff = 0;