about summary refs log tree commit diff
path: root/modules/expo-bluesky-swiss-army/src/HLSDownload/index.native.tsx
blob: 92f26192e56086c0e7eebdd61473f9ca593513f3 (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
import React from 'react'
import {StyleProp, ViewStyle} from 'react-native'
import {requireNativeModule, requireNativeViewManager} from 'expo-modules-core'

import {HLSDownloadViewProps} from './types'

const NativeModule = requireNativeModule('ExpoHLSDownload')
const NativeView: React.ComponentType<
  HLSDownloadViewProps & {
    ref: React.RefObject<any>
    style: StyleProp<ViewStyle>
  }
> = requireNativeViewManager('ExpoHLSDownload')

export default class HLSDownloadView extends React.PureComponent<HLSDownloadViewProps> {
  private nativeRef: React.RefObject<any> = React.createRef()

  constructor(props: HLSDownloadViewProps) {
    super(props)
  }

  static isAvailable(): boolean {
    return NativeModule.isAvailable()
  }

  async startDownloadAsync(sourceUrl: string): Promise<void> {
    return await this.nativeRef.current.startDownloadAsync(sourceUrl)
  }

  render() {
    return (
      <NativeView
        ref={this.nativeRef}
        style={{height: 0, width: 0}}
        {...this.props}
      />
    )
  }
}