mattermost-mobile/app/components/retriable_fast_image/index.tsx
Elias Nahum 5ea470a235
V1 dependencies and bump to RN 0.67.2 (#5908)
* update dependencies

* eslint fixes

* Upgrade to RN 67

* update other deps

* Update to RN 0.67.2

* fix Android build (mmkv)

* Fix crash when root message is deleted from the thread screen

* Fix gif emoji playing at high speed on iOS ProMotion capable devices
2022-02-02 15:28:57 -03:00

41 lines
1,005 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import FastImage, {FastImageProps} from 'react-native-fast-image';
export const FAST_IMAGE_MAX_RETRIES = 3;
type RetriableFastImageProps = FastImageProps & {
id: string;
}
type RetriableFastImageState = {
retry: number;
}
export default class RetriableFastImage extends PureComponent<RetriableFastImageProps, RetriableFastImageState> {
state = {
retry: 0,
};
onError = () => {
const retry = this.state.retry + 1;
if (retry > FAST_IMAGE_MAX_RETRIES && this.props.onError) {
this.props.onError();
return;
}
this.setState({retry});
};
render() {
return (
<FastImage
{...this.props}
key={`${this.props.id}-${this.state.retry}`}
onError={this.onError}
/>
);
}
}