Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
115 lines
3.4 KiB
TypeScript
115 lines
3.4 KiB
TypeScript
/**
|
|
* OpacitySlider — a dependency-free horizontal slider for the watermark opacity
|
|
* (a fraction in [0, 1]). Built on React Native's View responder system
|
|
* (`onResponder*` + `onLayout`) so it needs no native slider package. Tapping or
|
|
* dragging anywhere on the track sets the value from the touch's x position.
|
|
* Pure / controlled: the value is owned by the parent (immutable updates).
|
|
*/
|
|
|
|
import { useCallback, useState } from "react";
|
|
import {
|
|
type GestureResponderEvent,
|
|
type LayoutChangeEvent,
|
|
StyleSheet,
|
|
Text,
|
|
View,
|
|
} from "react-native";
|
|
|
|
import { colors } from "@/components/me/theme";
|
|
import { WATERMARK_OPACITY_MAX, WATERMARK_OPACITY_MIN } from "@/lib/types";
|
|
|
|
const THUMB_SIZE = 22;
|
|
|
|
interface OpacitySliderProps {
|
|
/** Current value in [0, 1]. */
|
|
value: number;
|
|
onChange: (value: number) => void;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
function clamp(value: number): number {
|
|
return Math.max(WATERMARK_OPACITY_MIN, Math.min(WATERMARK_OPACITY_MAX, value));
|
|
}
|
|
|
|
export function OpacitySlider({
|
|
value,
|
|
onChange,
|
|
disabled = false,
|
|
}: OpacitySliderProps) {
|
|
const [width, setWidth] = useState(0);
|
|
|
|
const onLayout = useCallback((e: LayoutChangeEvent) => {
|
|
setWidth(e.nativeEvent.layout.width);
|
|
}, []);
|
|
|
|
const handleTouch = useCallback(
|
|
(e: GestureResponderEvent) => {
|
|
if (disabled || width <= 0) return;
|
|
onChange(clamp(e.nativeEvent.locationX / width));
|
|
},
|
|
[disabled, width, onChange],
|
|
);
|
|
|
|
const pct = clamp(value);
|
|
const percentLabel = `${Math.round(pct * 100)}%`;
|
|
|
|
return (
|
|
<View style={styles.wrap}>
|
|
<View style={styles.header}>
|
|
<Text style={styles.label}>Opacity</Text>
|
|
<Text style={styles.value}>{percentLabel}</Text>
|
|
</View>
|
|
|
|
<View
|
|
style={styles.hitArea}
|
|
onLayout={onLayout}
|
|
onStartShouldSetResponder={() => !disabled}
|
|
onMoveShouldSetResponder={() => !disabled}
|
|
onResponderGrant={handleTouch}
|
|
onResponderMove={handleTouch}
|
|
accessibilityRole="adjustable"
|
|
accessibilityLabel="Watermark opacity"
|
|
accessibilityValue={{ min: 0, max: 100, now: Math.round(pct * 100) }}
|
|
accessibilityState={{ disabled }}
|
|
>
|
|
<View style={styles.track}>
|
|
<View style={[styles.fill, { width: `${pct * 100}%` }]} />
|
|
</View>
|
|
<View
|
|
style={[
|
|
styles.thumb,
|
|
disabled && styles.thumbDisabled,
|
|
{ left: `${pct * 100}%`, marginLeft: -THUMB_SIZE / 2 },
|
|
]}
|
|
/>
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
wrap: { gap: 8 },
|
|
header: { flexDirection: "row", justifyContent: "space-between", alignItems: "center" },
|
|
label: { color: colors.textSecondary, fontSize: 13, fontWeight: "600" },
|
|
value: { color: colors.textPrimary, fontSize: 13, fontWeight: "700" },
|
|
// Extra vertical padding gives a comfortable touch target around the 6px track.
|
|
hitArea: { justifyContent: "center", height: THUMB_SIZE + 12 },
|
|
track: {
|
|
height: 6,
|
|
borderRadius: 3,
|
|
backgroundColor: colors.border,
|
|
overflow: "hidden",
|
|
},
|
|
fill: { height: 6, backgroundColor: colors.primary },
|
|
thumb: {
|
|
position: "absolute",
|
|
width: THUMB_SIZE,
|
|
height: THUMB_SIZE,
|
|
borderRadius: THUMB_SIZE / 2,
|
|
backgroundColor: colors.primary,
|
|
borderColor: colors.textPrimary,
|
|
borderWidth: 2,
|
|
},
|
|
thumbDisabled: { backgroundColor: colors.muted },
|
|
});
|