// withHooks import { LibFont } from 'esoftplay/cache/lib/font/import'; import { LibGradient } from 'esoftplay/cache/lib/gradient/import'; import { LibIcon } from 'esoftplay/cache/lib/icon/import'; import { LibStyle } from 'esoftplay/cache/lib/style/import'; import React, { useRef } from 'react'; import { FlatList, TextInput, View } from 'react-native'; export interface LibNumbermeterArgs { } export interface LibNumbermeterProps { range: [number, number], onValueChange: (value: number) => void, valueDisplayEdit?: (value: string) => string } /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/numbermeter.md) untuk melihat dokumentasi*/ export default function m(props: LibNumbermeterProps): any { const valueRef = useRef(null) let value = useRef(0) function interpolate(input: number, inputRange: number[], outputRange: number[], clamp = true) { if (inputRange.length !== outputRange.length || inputRange.length < 2) { throw new Error("Input and output ranges must have the same length and at least two values."); } // Find the segment of the range where the input belongs for (let i = 0; i < inputRange.length - 1; i++) { if (input >= inputRange[i] && input <= inputRange[i + 1]) { // Interpolate within this segment const t = (input - inputRange[i]) / (inputRange[i + 1] - inputRange[i]); const value = outputRange[i] + t * (outputRange[i + 1] - outputRange[i]); return clamp ? Math.max(outputRange[0], Math.min(outputRange[outputRange.length - 1], value)) : value; } } // If the input is outside the range, clamp to the nearest bound if (clamp) { if (input < inputRange[0]) { return outputRange[0]; } if (input > inputRange[inputRange.length - 1]) { return outputRange[outputRange.length - 1]; } } throw new Error("Input value could not be interpolated."); } const max = props.range[1] const min = String(props.range[0]) function display(input: string) { if (props.valueDisplayEdit) { return props.valueDisplayEdit(input) } else return input } return ( { const val = interpolate(e.nativeEvent.contentOffset.x, [0, max * 10], [props.range[0], max]).toFixed(0) valueRef.current?.setNativeProps({ text: display(val) }) if (Number(val) != value.current) { value.current = Number(val) props.onValueChange(Number(val)) } }} style={{ flex: 1 }} bounces={false} scrollEventThrottle={16} data={new Array(max).fill(0)} ListHeaderComponent={} ListFooterComponent={} renderItem={({ item, index }) => { return ( ) }} /> ) }