import React, { useEffect, useRef } from "react"; import { TouchableOpacity, StyleSheet, Animated, Platform } from "react-native"; import { ChevronDown } from "lucide-react-native"; import type { OperoChatStyles } from "../types"; import { mergeStyles } from "../utils/helpers"; export interface OperoScrollToBottomProps { visible: boolean; onPress: () => void; customStyles?: OperoChatStyles; } export const OperoScrollToBottom: React.FC = ({ visible, onPress, customStyles, }) => { const fadeAnim = useRef(new Animated.Value(0)).current; const styles = createStyles(mergeStyles(customStyles)); useEffect(() => { Animated.timing(fadeAnim, { toValue: visible ? 1 : 0, duration: 200, useNativeDriver: true, }).start(); }, [visible, fadeAnim]); // Don't render at all if not visible (skip first render optimization) const [hasBeenVisible, setHasBeenVisible] = React.useState(false); React.useEffect(() => { if (visible) { setHasBeenVisible(true); } }, [visible]); if (!hasBeenVisible && !visible) { return null; } return ( ); }; const createStyles = (theme: OperoChatStyles) => StyleSheet.create({ container: { position: "absolute", right: 16, bottom: Platform.OS === "ios" ? 90 : 80, zIndex: 100, }, button: { width: 48, height: 48, borderRadius: 24, backgroundColor: theme.primaryColor || "#3b82f6", alignItems: "center", justifyContent: "center", shadowColor: "#000", shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 4, elevation: 5, }, });