From 02c8ec6a4fa9d3bdc1e680a2c7e77ba1c0982f15 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 26 Jun 2026 11:29:08 +0300 Subject: [PATCH] fix loose types in GifView module --- modules/expo-bluesky-gif-view/src/GifView.tsx | 25 ++++++++++++------- .../expo-bluesky-gif-view/src/GifView.web.tsx | 19 ++++++++------ 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/modules/expo-bluesky-gif-view/src/GifView.tsx b/modules/expo-bluesky-gif-view/src/GifView.tsx index 0cca26cf5e..c1d6ecddc0 100644 --- a/modules/expo-bluesky-gif-view/src/GifView.tsx +++ b/modules/expo-bluesky-gif-view/src/GifView.tsx @@ -1,17 +1,24 @@ -import React from 'react' +import {createRef, PureComponent} from 'react' import {requireNativeModule} from 'expo' import {requireNativeViewManager} from 'expo-modules-core' import {type GifViewProps} from './GifView.types' -const NativeModule = requireNativeModule('ExpoBlueskyGifView') +interface GifViewNativeRef { + playAsync: () => Promise + pauseAsync: () => Promise + toggleAsync: () => Promise +} + +const NativeModule: { + prefetchAsync: (sources: string[]) => Promise +} = requireNativeModule('ExpoBlueskyGifView') const NativeView: React.ComponentType< - GifViewProps & {ref: React.RefObject} + GifViewProps & {ref: React.RefObject} > = requireNativeViewManager('ExpoBlueskyGifView') -export class GifView extends React.PureComponent { - // TODO native types, should all be the same as those in this class - private nativeRef: React.RefObject = React.createRef() +export class GifView extends PureComponent { + private nativeRef: React.RefObject = createRef() constructor(props: GifViewProps | Readonly) { super(props) @@ -22,15 +29,15 @@ export class GifView extends React.PureComponent { } async playAsync(): Promise { - await this.nativeRef.current.playAsync() + await this.nativeRef.current?.playAsync() } async pauseAsync(): Promise { - await this.nativeRef.current.pauseAsync() + await this.nativeRef.current?.pauseAsync() } async toggleAsync(): Promise { - await this.nativeRef.current.toggleAsync() + await this.nativeRef.current?.toggleAsync() } render() { diff --git a/modules/expo-bluesky-gif-view/src/GifView.web.tsx b/modules/expo-bluesky-gif-view/src/GifView.web.tsx index e51b9bf9fc..379ced95ca 100644 --- a/modules/expo-bluesky-gif-view/src/GifView.web.tsx +++ b/modules/expo-bluesky-gif-view/src/GifView.web.tsx @@ -1,10 +1,11 @@ -import {createRef, PureComponent, type RefObject} from 'react' +import {createRef, PureComponent} from 'react' import {StyleSheet} from 'react-native' import {type GifViewProps} from './GifView.types' export class GifView extends PureComponent { - private readonly videoPlayerRef: RefObject = createRef() + private readonly videoPlayerRef: React.RefObject = + createRef() private isLoaded = false constructor(props: GifViewProps | Readonly) { @@ -18,9 +19,9 @@ export class GifView extends PureComponent { componentDidUpdate(prevProps: Readonly) { if (prevProps.autoplay !== this.props.autoplay) { if (this.props.autoplay) { - this.playAsync() + void this.playAsync() } else { - this.pauseAsync() + void this.pauseAsync() } } } @@ -29,6 +30,7 @@ export class GifView extends PureComponent { document.removeEventListener('visibilitychange', this.onVisibilityChange) } + // eslint-disable-next-line @typescript-eslint/require-await static async prefetchAsync(_: string[]): Promise { console.warn('prefetchAsync is not supported on web') } @@ -81,6 +83,7 @@ export class GifView extends PureComponent { } } + // eslint-disable-next-line @typescript-eslint/require-await async pauseAsync(): Promise { this.videoPlayerRef.current?.pause() } @@ -102,12 +105,12 @@ export class GifView extends PureComponent { // When `` children are present, omit `src` so the browser // walks the source list and picks via canPlayType. src={useSources ? undefined : source} - autoPlay={autoplay ? 'autoplay' : undefined} + autoPlay={autoplay ? true : undefined} preload={autoplay ? 'auto' : undefined} playsInline={true} - loop="loop" - muted="muted" - style={StyleSheet.flatten(style)} + loop={true} + muted={true} + style={StyleSheet.flatten(style) as React.CSSProperties} onCanPlay={this.onLoad} onPlay={this.firePlayerStateChangeEvent} onPause={this.firePlayerStateChangeEvent}