You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GifsMenu.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { GiphyContent, GiphyGridView, GiphyMediaType } from '@giphy/react-native-sdk';
  2. import React, { useCallback, useState } from 'react';
  3. import { Image, Keyboard, Text, View } from 'react-native';
  4. import { useSafeAreaInsets } from 'react-native-safe-area-context';
  5. import { useDispatch } from 'react-redux';
  6. import { createGifSentEvent, sendAnalytics } from '../../../analytics';
  7. import JitsiScreen from '../../../base/modal/components/JitsiScreen';
  8. import { sendMessage } from '../../../chat/actions.any';
  9. import { goBack } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  10. import ClearableInput from '../../../participants-pane/components/native/ClearableInput';
  11. import { formatGifUrlMessage, getGifUrl } from '../../functions';
  12. import styles from './styles';
  13. const GifsMenu = () => {
  14. const [ searchQuery, setSearchQuery ] = useState('');
  15. const dispatch = useDispatch();
  16. const insets = useSafeAreaInsets();
  17. const content = searchQuery === ''
  18. ? GiphyContent.trending({ mediaType: GiphyMediaType.Gif })
  19. : GiphyContent.search({
  20. searchQuery,
  21. mediaType: GiphyMediaType.Gif
  22. });
  23. const sendGif = useCallback(e => {
  24. const url = getGifUrl(e.nativeEvent.media);
  25. sendAnalytics(createGifSentEvent());
  26. dispatch(sendMessage(formatGifUrlMessage(url), true));
  27. goBack();
  28. }, []);
  29. const onScroll = useCallback(Keyboard.dismiss, []);
  30. return (<JitsiScreen
  31. style = { styles.container }>
  32. <ClearableInput
  33. autoFocus = { true }
  34. customStyles = { styles.clearableInput }
  35. onChange = { setSearchQuery }
  36. placeholder = 'Search GIPHY'
  37. value = { searchQuery } />
  38. <GiphyGridView
  39. cellPadding = { 5 }
  40. content = { content }
  41. onMediaSelect = { sendGif }
  42. onScroll = { onScroll }
  43. style = { styles.grid } />
  44. <View
  45. style = { [ styles.credit, {
  46. bottom: insets.bottom,
  47. left: insets.left,
  48. right: insets.right
  49. } ] }>
  50. <Text
  51. style = { styles.creditText }>Powered by</Text>
  52. <Image source = { require('../../../../../images/GIPHY_logo.png') } />
  53. </View>
  54. </JitsiScreen>);
  55. };
  56. export default GifsMenu;