callstack / callstack/react-native-slider
Step between 0 and 1 produces floating point rounding errors
- 主要言語
- TypeScript
- スター
- 1.4k
- フォーク
- 295
- 平均マージ
- 5分
- マージ済み PR(30日)
- 1
説明
## Environment
System:
OS: macOS
Binaries:
Node: v22.16.0
npm: 10.9.2
are you using the new architecture?
No (Expo-managed workflow)
which version of react & react-native are you using?
React: 19.1.0
React Native: 0.81.5
@react-native-community/slider: 5.0.1
Expo SDK: 54.0.17
## Description
when using minimumValue of 0, maximumValue of 1, and a step of 0.1, the value returned by onValueChange shows floating-point precision errors. Instead of returning decimal values (e.g. 0.4), it returns e.g. 0.4000000596046448, this can be seen in the value and the markers. Occurs consistently across iOS and Android in the Expo environment.
## Reproducible Demo
```
import React, { useState } from 'react';
import { View, Text } from 'react-native';
import Slider from '@react-native-community/slider';
export default function App() {
const [value, setValue] = useState(0);
return (
setValue(val)}
/>
Value: {value}
);
}
```
## Potential Fix
Round the computed value before emitting it in onValueChange: `value = parseFloat(value.toFixed(6));`
## Workaround
For a temp workaround users can use:
`onValueChange={(val) => setValue(Math.round(val * 10) / 10)}`
コントリビューションガイド
調査の方向性
まず、提供されている Expo の再現を minimumValue 0、maximumValue 1、step 0.1 で iOS と Android の両方で実行します。onValueChange が計算された値を受け取る箇所を追跡し、その後、発行される値と表示されるマーカーが浮動小数点のアーティファクトなしに期待される小数ステップを使用していることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react-native, typescript
- 領域
- mobile-dev
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100