about summary refs log tree commit diff
path: root/src/view/com/util/post-embeds/VideoEmbed.tsx
blob: 887efac1ab63ad6492ec86563e918aaedbb22624 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React from 'react'
import {View} from 'react-native'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {VideoEmbedInnerNative} from 'view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative'
import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonIcon} from '#/components/Button'
import {Play_Filled_Corner2_Rounded as PlayIcon} from '#/components/icons/Play'
import {VisibilityView} from '../../../../../modules/expo-bluesky-swiss-army'
import {useActiveVideoView} from './ActiveVideoContext'

export function VideoEmbed({source}: {source: string}) {
  const t = useTheme()
  const {active, setActive} = useActiveVideoView({source})
  const {_} = useLingui()

  return (
    <View
      style={[
        a.w_full,
        a.rounded_sm,
        {aspectRatio: 16 / 9},
        a.overflow_hidden,
        t.atoms.bg_contrast_25,
        a.my_xs,
      ]}>
      <VisibilityView
        enabled={true}
        onChangeStatus={isActive => {
          if (isActive) {
            setActive()
          }
        }}>
        {active ? (
          <VideoEmbedInnerNative />
        ) : (
          <Button
            style={[a.flex_1, t.atoms.bg_contrast_25]}
            onPress={setActive}
            label={_(msg`Play video`)}
            variant="ghost"
            color="secondary"
            size="large">
            <ButtonIcon icon={PlayIcon} />
          </Button>
        )}
      </VisibilityView>
    </View>
  )
}