Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ the only Expo module used by the component itself.
## Single preset

```tsx
import { useState } from 'react';
import { Text } from 'react-native';
import { DialSlider, type DialPreset } from '@ngocdevv/dial-slider';

Expand All @@ -100,23 +99,25 @@ const EXPOSURE: readonly DialPreset[] = [
minValue: -100,
maxValue: 100,
initialValue: 0,
formatValue: (value) => `${value}%`,
},
];

export function ExposureControl() {
const [value, setValue] = useState(0);

return (
<DialSlider
presets={EXPOSURE}
defaultValues={{ exposure: 0 }}
onValueChange={(_presetId, nextValue) => setValue(nextValue)}
accessibilityLabel={`Exposure, ${value}`}
accessibilityLabel="Exposure"
/>
);
}
```

Keep `accessibilityLabel` stable. The active value is exposed separately through
the adjustable control's accessibility value and uses the preset's
`formatValue` output.

## Multiple presets

The example below is fully controlled. Update `selectedPresetId` and `values` in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { PresetButton } from './PresetButton';
import { PresetRing } from './PresetRing';

const { ITEM_SIZE, ITEM_GAP } = DIAL_CONFIG;
const NOOP = () => {};

interface DialPresetViewportProps {
presets: readonly DialPreset[];
Expand Down Expand Up @@ -113,7 +112,6 @@ export function DialPresetViewport({
selected
accentColor={accentColor}
adjustedColor={adjustedColor}
onPress={NOOP}
/>
</View>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ interface PresetButtonProps {
selected: boolean;
accentColor: string;
adjustedColor: string;
onPress: () => void;
/** Omit for a visual-only indicator that should not receive accessibility focus. */
onPress?: () => void;
}

export function PresetButton({
Expand All @@ -40,6 +41,34 @@ export function PresetButton({
positiveProgressColor,
COLORS.NEGATIVE
);
const content = (
<>
<PresetRing
value={value}
minValue={min}
maxValue={max}
color={progressColor}
backgroundColor={selected ? '#5C5C60' : '#4A4A4D'}
/>
<View style={[styles.iconSlot, !selected && styles.inactiveIcon]}>
{icon}
</View>
</>
);

if (!onPress) {
return (
<View
accessible={false}
accessibilityElementsHidden
importantForAccessibility="no-hide-descendants"
pointerEvents="none"
style={[styles.presetButton, preset.disabled && styles.disabledPreset]}
>
{content}
</View>
);
}

return (
<Pressable
Expand All @@ -60,16 +89,7 @@ export function PresetButton({
pressed && styles.pressedPreset,
]}
>
<PresetRing
value={value}
minValue={min}
maxValue={max}
color={progressColor}
backgroundColor={selected ? '#5C5C60' : '#4A4A4D'}
/>
<View style={[styles.iconSlot, !selected && styles.inactiveIcon]}>
{icon}
</View>
{content}
</Pressable>
);
}
Expand Down