fix loose types in GifView module
This commit is contained in:
@@ -1,17 +1,24 @@
|
|||||||
import React from 'react'
|
import {createRef, PureComponent} from 'react'
|
||||||
import {requireNativeModule} from 'expo'
|
import {requireNativeModule} from 'expo'
|
||||||
import {requireNativeViewManager} from 'expo-modules-core'
|
import {requireNativeViewManager} from 'expo-modules-core'
|
||||||
|
|
||||||
import {type GifViewProps} from './GifView.types'
|
import {type GifViewProps} from './GifView.types'
|
||||||
|
|
||||||
const NativeModule = requireNativeModule('ExpoBlueskyGifView')
|
interface GifViewNativeRef {
|
||||||
|
playAsync: () => Promise<void>
|
||||||
|
pauseAsync: () => Promise<void>
|
||||||
|
toggleAsync: () => Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
const NativeModule: {
|
||||||
|
prefetchAsync: (sources: string[]) => Promise<void>
|
||||||
|
} = requireNativeModule('ExpoBlueskyGifView')
|
||||||
const NativeView: React.ComponentType<
|
const NativeView: React.ComponentType<
|
||||||
GifViewProps & {ref: React.RefObject<any>}
|
GifViewProps & {ref: React.RefObject<GifViewNativeRef | null>}
|
||||||
> = requireNativeViewManager('ExpoBlueskyGifView')
|
> = requireNativeViewManager('ExpoBlueskyGifView')
|
||||||
|
|
||||||
export class GifView extends React.PureComponent<GifViewProps> {
|
export class GifView extends PureComponent<GifViewProps> {
|
||||||
// TODO native types, should all be the same as those in this class
|
private nativeRef: React.RefObject<GifViewNativeRef | null> = createRef()
|
||||||
private nativeRef: React.RefObject<any> = React.createRef()
|
|
||||||
|
|
||||||
constructor(props: GifViewProps | Readonly<GifViewProps>) {
|
constructor(props: GifViewProps | Readonly<GifViewProps>) {
|
||||||
super(props)
|
super(props)
|
||||||
@@ -22,15 +29,15 @@ export class GifView extends React.PureComponent<GifViewProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async playAsync(): Promise<void> {
|
async playAsync(): Promise<void> {
|
||||||
await this.nativeRef.current.playAsync()
|
await this.nativeRef.current?.playAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
async pauseAsync(): Promise<void> {
|
async pauseAsync(): Promise<void> {
|
||||||
await this.nativeRef.current.pauseAsync()
|
await this.nativeRef.current?.pauseAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggleAsync(): Promise<void> {
|
async toggleAsync(): Promise<void> {
|
||||||
await this.nativeRef.current.toggleAsync()
|
await this.nativeRef.current?.toggleAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import {createRef, PureComponent, type RefObject} from 'react'
|
import {createRef, PureComponent} from 'react'
|
||||||
import {StyleSheet} from 'react-native'
|
import {StyleSheet} from 'react-native'
|
||||||
|
|
||||||
import {type GifViewProps} from './GifView.types'
|
import {type GifViewProps} from './GifView.types'
|
||||||
|
|
||||||
export class GifView extends PureComponent<GifViewProps> {
|
export class GifView extends PureComponent<GifViewProps> {
|
||||||
private readonly videoPlayerRef: RefObject<HTMLMediaElement> = createRef()
|
private readonly videoPlayerRef: React.RefObject<HTMLVideoElement | null> =
|
||||||
|
createRef()
|
||||||
private isLoaded = false
|
private isLoaded = false
|
||||||
|
|
||||||
constructor(props: GifViewProps | Readonly<GifViewProps>) {
|
constructor(props: GifViewProps | Readonly<GifViewProps>) {
|
||||||
@@ -18,9 +19,9 @@ export class GifView extends PureComponent<GifViewProps> {
|
|||||||
componentDidUpdate(prevProps: Readonly<GifViewProps>) {
|
componentDidUpdate(prevProps: Readonly<GifViewProps>) {
|
||||||
if (prevProps.autoplay !== this.props.autoplay) {
|
if (prevProps.autoplay !== this.props.autoplay) {
|
||||||
if (this.props.autoplay) {
|
if (this.props.autoplay) {
|
||||||
this.playAsync()
|
void this.playAsync()
|
||||||
} else {
|
} else {
|
||||||
this.pauseAsync()
|
void this.pauseAsync()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,6 +30,7 @@ export class GifView extends PureComponent<GifViewProps> {
|
|||||||
document.removeEventListener('visibilitychange', this.onVisibilityChange)
|
document.removeEventListener('visibilitychange', this.onVisibilityChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/require-await
|
||||||
static async prefetchAsync(_: string[]): Promise<void> {
|
static async prefetchAsync(_: string[]): Promise<void> {
|
||||||
console.warn('prefetchAsync is not supported on web')
|
console.warn('prefetchAsync is not supported on web')
|
||||||
}
|
}
|
||||||
@@ -81,6 +83,7 @@ export class GifView extends PureComponent<GifViewProps> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/require-await
|
||||||
async pauseAsync(): Promise<void> {
|
async pauseAsync(): Promise<void> {
|
||||||
this.videoPlayerRef.current?.pause()
|
this.videoPlayerRef.current?.pause()
|
||||||
}
|
}
|
||||||
@@ -102,12 +105,12 @@ export class GifView extends PureComponent<GifViewProps> {
|
|||||||
// When `<source>` children are present, omit `src` so the browser
|
// When `<source>` children are present, omit `src` so the browser
|
||||||
// walks the source list and picks via canPlayType.
|
// walks the source list and picks via canPlayType.
|
||||||
src={useSources ? undefined : source}
|
src={useSources ? undefined : source}
|
||||||
autoPlay={autoplay ? 'autoplay' : undefined}
|
autoPlay={autoplay ? true : undefined}
|
||||||
preload={autoplay ? 'auto' : undefined}
|
preload={autoplay ? 'auto' : undefined}
|
||||||
playsInline={true}
|
playsInline={true}
|
||||||
loop="loop"
|
loop={true}
|
||||||
muted="muted"
|
muted={true}
|
||||||
style={StyleSheet.flatten(style)}
|
style={StyleSheet.flatten(style) as React.CSSProperties}
|
||||||
onCanPlay={this.onLoad}
|
onCanPlay={this.onLoad}
|
||||||
onPlay={this.firePlayerStateChangeEvent}
|
onPlay={this.firePlayerStateChangeEvent}
|
||||||
onPause={this.firePlayerStateChangeEvent}
|
onPause={this.firePlayerStateChangeEvent}
|
||||||
|
|||||||
Reference in New Issue
Block a user