Extract utils
This commit is contained in:
@@ -1,22 +1,11 @@
|
|||||||
import {useEffect} from 'react'
|
import {useEffect} from 'react'
|
||||||
import {type FlatList} from 'react-native'
|
import {type FlatList} from 'react-native'
|
||||||
|
|
||||||
import {ITEM_GAP} from '#/components/images/Gallery/const'
|
|
||||||
import {tween} from '#/components/images/Gallery/tween'
|
import {tween} from '#/components/images/Gallery/tween'
|
||||||
|
import {getOffsetForIndex} from '#/components/images/Gallery/utils'
|
||||||
|
|
||||||
const SETTLE_DURATION = 600
|
const SETTLE_DURATION = 600
|
||||||
|
|
||||||
function getOffsetForIndex(
|
|
||||||
itemWidths: Map<number, number>,
|
|
||||||
index: number,
|
|
||||||
): number {
|
|
||||||
let offset = 0
|
|
||||||
for (let i = 0; i < index; i++) {
|
|
||||||
offset += (itemWidths.get(i) ?? 0) + ITEM_GAP
|
|
||||||
}
|
|
||||||
return offset
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useKeyboardHandlers({
|
export function useKeyboardHandlers({
|
||||||
flatListRef,
|
flatListRef,
|
||||||
itemWidthsRef,
|
itemWidthsRef,
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import {type FlatList} from 'react-native'
|
|||||||
|
|
||||||
import {ITEM_GAP} from '#/components/images/Gallery/const'
|
import {ITEM_GAP} from '#/components/images/Gallery/const'
|
||||||
import {tween} from '#/components/images/Gallery/tween'
|
import {tween} from '#/components/images/Gallery/tween'
|
||||||
|
import {getOffsetForIndex} from '#/components/images/Gallery/utils'
|
||||||
|
|
||||||
const DRAG_THRESHOLD = 3
|
const DRAG_THRESHOLD = 3
|
||||||
const FLICK_DECAY = 0.85
|
const FLICK_DECAY = 0.85
|
||||||
const FLICK_MIN_VELOCITY = 0.1
|
const FLICK_MIN_VELOCITY = 0.1
|
||||||
@@ -10,17 +12,6 @@ const ADVANCE_THRESHOLD = 0.15
|
|||||||
const FRAME_MS = 1000 / 60
|
const FRAME_MS = 1000 / 60
|
||||||
const SETTLE_DURATION = 600
|
const SETTLE_DURATION = 600
|
||||||
|
|
||||||
function getOffsetForIndex(
|
|
||||||
itemWidths: Map<number, number>,
|
|
||||||
index: number,
|
|
||||||
): number {
|
|
||||||
let offset = 0
|
|
||||||
for (let i = 0; i < index; i++) {
|
|
||||||
offset += (itemWidths.get(i) ?? 0) + ITEM_GAP
|
|
||||||
}
|
|
||||||
return offset
|
|
||||||
}
|
|
||||||
|
|
||||||
function whichByDistance(
|
function whichByDistance(
|
||||||
itemWidths: Map<number, number>,
|
itemWidths: Map<number, number>,
|
||||||
currentIndex: number,
|
currentIndex: number,
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import {ITEM_GAP} from '#/components/images/Gallery/const'
|
||||||
|
|
||||||
|
export function getOffsetForIndex(
|
||||||
|
itemWidths: Map<number, number>,
|
||||||
|
index: number,
|
||||||
|
): number {
|
||||||
|
let offset = 0
|
||||||
|
for (let i = 0; i < index; i++) {
|
||||||
|
offset += (itemWidths.get(i) ?? 0) + ITEM_GAP
|
||||||
|
}
|
||||||
|
return offset
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user