import { StackActions, StaticScreenProps, useNavigation } from '@react-navigation/native' import React from 'react' import { Image as NativeImage, Platform, StyleSheet, useWindowDimensions, View } from 'react-native' import { Button, IconButton, IconString, TextButton } from '../components' import { DefaultLoading } from '../components/page/loading' import BlankState from '../components/primitive/blank_state_primitive' import FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet' import { useCreateAndroidRippleColor, useTheme } from '../hooks' import { useGiphy } from '../hooks/use_giphy' import { useMessageCreateOrUpdate } from '../hooks/use_message_create_or_update' import { tokens } from '../vendor/tapestry/tokens' export const SendGiphyScreenOptions = getFormSheetScreenOptions({ headerTitle: 'Send Giphy', sheetAllowedDetents: Platform.select({ android: [0.7, 0.94], default: [0.7, 1] }), }) export type SendGiphyScreenProps = StaticScreenProps<{ conversation_id: number reply_root_id?: string | null search_term: string }> export function SendGiphyScreen({ route }: SendGiphyScreenProps) { const { conversation_id, reply_root_id, search_term } = route.params const styles = useStyles() const navigation = useNavigation() const { isPending, mutate } = useMessageCreateOrUpdate({ conversationId: conversation_id, replyRootId: reply_root_id, }) const { isSearching, result, nextResult, prevResult } = useGiphy(search_term) const disabled = isPending || isSearching const { width } = useWindowDimensions() const size = width - 24 if (!result) return ( No Giphys found Try a different search term. navigation.goBack()} title="Close" /> ) const gif = result.giphy.fixed_width const { url } = gif function goBack({ clearInput = false }) { if (clearInput) { const routeName = reply_root_id ? 'ConversationReply' : 'Conversation' const routes = navigation.getState()?.routes || [] const conversationParams = routes.findLast(r => r.name === routeName)?.params || {} navigation.dispatch( StackActions.popTo(routeName, { ...conversationParams, conversation_id, clear_input: true, }) ) } else { navigation.goBack() } } function sendGiphy() { if (disabled) return mutate({ text: '', attachments: [result] }) goBack({ clearInput: true }) } return ( goBack({ clearInput: false })} maxFontSizeMultiplier={1} accessibilityHint="Cancels the Giphy selection and closes this modal." > Cancel