mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-22 19:18:10 +00:00
Improves type safety throughout the codebase by eliminating unsafe `any` type assertions and replacing them with proper type definitions. Adds explicit type parameters and constraints to MMKV augmentations, component props, and router navigation calls. Updates function signatures to use `unknown` instead of `any` where appropriate, and properly types Icon glyphs, router Href parameters, and component prop spreads. Enhances maintainability and catches potential type errors at compile time rather than runtime.
145 lines
3.6 KiB
TypeScript
145 lines
3.6 KiB
TypeScript
import { Ionicons } from "@expo/vector-icons";
|
|
import { BlurView } from "expo-blur";
|
|
import type { PropsWithChildren } from "react";
|
|
import { Platform, TouchableOpacity, type ViewProps } from "react-native";
|
|
import { useHaptic } from "@/hooks/useHaptic";
|
|
|
|
interface Props
|
|
extends Omit<
|
|
ViewProps,
|
|
| "children"
|
|
| "onPressIn"
|
|
| "onPressOut"
|
|
| "onPress"
|
|
| "nextFocusDown"
|
|
| "nextFocusForward"
|
|
| "nextFocusLeft"
|
|
| "nextFocusRight"
|
|
| "nextFocusUp"
|
|
> {
|
|
onPress?: () => void;
|
|
icon?: keyof typeof Ionicons.glyphMap;
|
|
background?: boolean;
|
|
size?: "default" | "large";
|
|
fillColor?: "primary";
|
|
color?: "white" | "purple";
|
|
hapticFeedback?: boolean;
|
|
}
|
|
|
|
export const RoundButton: React.FC<PropsWithChildren<Props>> = ({
|
|
background = true,
|
|
icon,
|
|
onPress,
|
|
children,
|
|
size = "default",
|
|
fillColor,
|
|
color = "white",
|
|
hapticFeedback = true,
|
|
...viewProps
|
|
}) => {
|
|
const buttonSize = size === "large" ? "h-10 w-10" : "h-9 w-9";
|
|
const fillColorClass = fillColor === "primary" ? "bg-purple-600" : "";
|
|
const lightHapticFeedback = useHaptic("light");
|
|
|
|
const handlePress = () => {
|
|
if (hapticFeedback) {
|
|
lightHapticFeedback();
|
|
}
|
|
onPress?.();
|
|
};
|
|
|
|
if (Platform.OS === "ios") {
|
|
return (
|
|
<TouchableOpacity
|
|
onPress={handlePress}
|
|
className={`rounded-full ${buttonSize} flex items-center justify-center ${fillColorClass}`}
|
|
{...viewProps}
|
|
>
|
|
{icon ? (
|
|
<Ionicons
|
|
name={icon}
|
|
size={size === "large" ? 22 : 18}
|
|
color={color === "white" ? "white" : "#9334E9"}
|
|
/>
|
|
) : null}
|
|
{children ? children : null}
|
|
</TouchableOpacity>
|
|
);
|
|
}
|
|
|
|
if (fillColor)
|
|
return (
|
|
<TouchableOpacity
|
|
onPress={handlePress}
|
|
className={`rounded-full ${buttonSize} flex items-center justify-center ${fillColorClass}`}
|
|
{...viewProps}
|
|
>
|
|
{icon ? (
|
|
<Ionicons
|
|
name={icon}
|
|
size={size === "large" ? 22 : 18}
|
|
color={"white"}
|
|
/>
|
|
) : null}
|
|
{children ? children : null}
|
|
</TouchableOpacity>
|
|
);
|
|
|
|
if (background === false)
|
|
return (
|
|
<TouchableOpacity
|
|
onPress={handlePress}
|
|
className={`rounded-full ${buttonSize} flex items-center justify-center ${fillColorClass}`}
|
|
{...viewProps}
|
|
>
|
|
{icon ? (
|
|
<Ionicons
|
|
name={icon}
|
|
size={size === "large" ? 22 : 18}
|
|
color={"white"}
|
|
/>
|
|
) : null}
|
|
{children ? children : null}
|
|
</TouchableOpacity>
|
|
);
|
|
|
|
if (Platform.OS === "android")
|
|
return (
|
|
<TouchableOpacity
|
|
onPress={handlePress}
|
|
className={`rounded-full ${buttonSize} flex items-center justify-center ${
|
|
fillColor ? fillColorClass : "bg-transparent"
|
|
}`}
|
|
{...viewProps}
|
|
>
|
|
{icon ? (
|
|
<Ionicons
|
|
name={icon}
|
|
size={size === "large" ? 22 : 18}
|
|
color={"white"}
|
|
/>
|
|
) : null}
|
|
{children ? children : null}
|
|
</TouchableOpacity>
|
|
);
|
|
|
|
return (
|
|
<TouchableOpacity onPress={handlePress} {...viewProps}>
|
|
<BlurView
|
|
intensity={90}
|
|
className={`rounded-full overflow-hidden ${buttonSize} flex items-center justify-center ${fillColorClass}`}
|
|
{...viewProps}
|
|
>
|
|
{icon ? (
|
|
<Ionicons
|
|
name={icon}
|
|
size={size === "large" ? 22 : 18}
|
|
color={"white"}
|
|
/>
|
|
) : null}
|
|
{children ? children : null}
|
|
</BlurView>
|
|
</TouchableOpacity>
|
|
);
|
|
};
|