Skip to content

Disable image preview for invalid images #23103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
6 changes: 4 additions & 2 deletions src/components/AttachmentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const defaultProps = {
function AttachmentView(props) {
const [loadComplete, setLoadComplete] = useState(false);
const containerStyles = [styles.flex1, styles.flexRow, styles.alignSelfStretch];
const [isValidImage, setIsValidImage] = useState(true);

// Handles case where source is a component (ex: SVG)
if (_.isFunction(props.source)) {
Expand Down Expand Up @@ -104,14 +105,15 @@ function AttachmentView(props) {

// For this check we use both source and file.name since temporary file source is a blob
// both PDFs and images will appear as images when pasted into the the text field
const isImage = Str.isImage(props.source);
if (isImage || (props.file && Str.isImage(props.file.name))) {
const isImage = Str.isImage(props.source) || (props.file && Str.isImage(props.file.name));
if (isImage && isValidImage) {
const children = (
<ImageView
onScaleChanged={props.onScaleChanged}
url={props.source}
fileName={props.file.name}
isAuthTokenRequired={isImage && props.isAuthTokenRequired}
onError={() => setIsValidImage(false)}
/>
);
return props.onPress ? (
Expand Down
2 changes: 2 additions & 0 deletions src/components/ImageView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class ImageView extends PureComponent {
resizeMode={this.state.zoomScale > 1 ? Image.resizeMode.center : Image.resizeMode.contain}
onLoadStart={this.imageLoadingStart}
onLoad={this.imageLoad}
onError={this.props.onError}
/>
{this.state.isLoading && <FullscreenLoadingIndicator style={[styles.opacity1, styles.bgTransparent]} />}
</View>
Expand Down Expand Up @@ -299,6 +300,7 @@ class ImageView extends PureComponent {
resizeMode={Image.resizeMode.contain}
onLoadStart={this.imageLoadingStart}
onLoad={this.imageLoad}
onError={this.props.onError}
/>
</PressableWithoutFeedback>

Expand Down