mirror of
https://github.com/KoalaSat/nostros.git
synced 2024-09-29 14:40:43 +00:00
27 lines
916 B
TypeScript
27 lines
916 B
TypeScript
export const handleInfinityScroll: (event: any) => boolean = (event) => {
|
|
const mHeight = event.nativeEvent.layoutMeasurement.height
|
|
const cSize = event.nativeEvent.contentSize.height
|
|
const Y = event.nativeEvent.contentOffset.y
|
|
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
if (Math.ceil(mHeight + Y) >= cSize) return true
|
|
return false
|
|
}
|
|
|
|
export const stringToColour: (string: string) => string = (string) => {
|
|
let hash = 0
|
|
for (let i = 0; i < string.length; i++) {
|
|
hash = string.charCodeAt(i) + ((hash << 5) - hash)
|
|
}
|
|
let colour = '#'
|
|
for (let i = 0; i < 3; i++) {
|
|
const value = (hash >> (i * 8)) & 0xff
|
|
colour += ('00' + value.toString(16)).substr(-2)
|
|
}
|
|
return colour
|
|
}
|
|
|
|
export const pickRandomItems = <T extends unknown>(arr: T[], n: number): T[] => {
|
|
const shuffled = Array.from(arr).sort(() => 0.5 - Math.random())
|
|
return shuffled.slice(0, n)
|
|
}
|