import {useCallback, useEffect} from 'react' import {type ScrollView, View} from 'react-native' import Animated, {useAnimatedRef, useSharedValue} from 'react-native-reanimated' import {moderateProfile} from '@atproto/api' import {useLingui} from '@lingui/react/macro' import {HITSLOP_10} from '#/lib/constants' import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeHandle} from '#/lib/strings/handles' import {useModerationOpts} from '#/state/preferences/moderation-opts' import {DraggableScrollView} from '#/view/com/pager/DraggableScrollView' import {atoms as a, useTheme} from '#/alf' import {Button} from '#/components/Button' import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Times' import * as ProfileCard from '#/components/ProfileCard' import {Text} from '#/components/Typography' import type * as bsky from '#/types/bsky' type Props = { testID?: string profiles: bsky.profile.AnyProfileView[] onRemove?: (did: string) => void } export function ChatProfileTabs({testID, profiles, onRemove}: Props) { const t = useTheme() const scrollElRef = useAnimatedRef() const contentSize = useSharedValue(0) const scrollX = useSharedValue(0) useEffect(() => { requestAnimationFrame(() => { // Scroll to the end of the list when `profiles` changes. scrollElRef.current?.scrollToEnd({animated: true}) }) }, [profiles, scrollElRef]) return ( { scrollX.set(Math.round(e.nativeEvent.contentOffset.x)) }}> { contentSize.set(e.nativeEvent.layout.width) }}> {profiles.map((profile, index) => ( ))} ) } function Tab({ testID, index, profile, total, onRemove, }: { testID?: string index: number profile: bsky.profile.AnyProfileView total: number onRemove?: (did: string) => void }) { const t = useTheme() const {t: l} = useLingui() const moderationOpts = useModerationOpts() const moderation = moderateProfile(profile, moderationOpts!) const displayName = sanitizeDisplayName( profile.displayName || sanitizeHandle(profile.handle), moderation.ui('displayName'), ) const onPressItem = useCallback( (did: string) => { onRemove?.(did) }, [onRemove], ) return ( {moderationOpts ? ( <> {displayName} ) : ( <> )} ) }