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
{isSearching ? (
) : (
)}
)
}
interface PaginateButtonProps {
name: IconString
accessibilityLabel: string
onPress: () => void
disabled: boolean
}
function PaginateButton({ name, accessibilityLabel, onPress, disabled }: PaginateButtonProps) {
const styles = useStyles()
const { colors } = useTheme()
const androidRippleColor = useCreateAndroidRippleColor({ color: colors.interaction })
return (
)
}
const useStyles = () => {
const { colors } = useTheme()
return StyleSheet.create({
container: {
paddingTop: 32,
paddingHorizontal: 16,
gap: 8,
},
blankStateContainer: {
paddingVertical: 64,
},
blankState: {
flex: 0,
flexGrow: 1,
},
poweredByGiphyContainer: {
alignSelf: 'flex-start',
padding: 4,
borderRadius: 4,
backgroundColor: colors.name === 'dark' ? tokens.colorNeutral68 : 'transparent',
},
poweredByGiphyImage: {
width: 170,
height: 20,
},
controlToolbar: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
formButtonGroup: {
flexDirection: 'row',
alignItems: 'center',
gap: 16,
},
paginateButtonGroup: {
flexDirection: 'row',
gap: 8,
},
paginateButton: {
borderColor: colors.interaction,
borderWidth: 1,
height: 28,
paddingHorizontal: 12,
borderRadius: 16,
overflow: 'hidden',
},
paginateButtonDisabled: {
backgroundColor: colors.fillColorButtonNeutralSolidDisabled,
borderColor: colors.fillColorButtonNeutralSolidDisabled,
},
image: {
borderRadius: 8,
maxWidth: '100%',
},
})
}
const poweredByGiphyImage = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAAWCAYAAACFbNPBAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA
GXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABa9JREFUeNrsWy1z40gQla8EDAwE
DAQCDAIMAgwCDA0XBgYGBu5PyM84aLgw8KDBAoMDBgsEAgQEBAQEBARclZ2uepPrne2WRrbls7Pq
KpWc0UxPz0y//pIyen9/Dwa6LhqNRjNzmwmPcnOl5kzrYZdOQ+GwBVcDirG5LXGNG7rWpu/O3Dcu
UEz7ytxW7gDT76WtjzYXAdJcW8MjFWR+EoBMAF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