Remove unneeded getImageDimensions helper function. (#3200)

* Remove unneeded `getImageDimensions` helper function.

The built-in React Native function has an `async` API that we can call directly.

* Legit test failure

* Import Image from React Native

* Prefer using styledComponents.Image.getSize

* Revert "Prefer using styledComponents.Image.getSize"

This reverts commit 103ca9b3ef.
This commit is contained in:
Corey Farwell
2025-12-12 04:58:42 -05:00
committed by GitHub
parent 8f97ae197f
commit c36c94a5df
4 changed files with 5 additions and 22 deletions

View File

@@ -11,8 +11,8 @@ import {
import _, { compact } from "lodash";
import type { Node } from "react";
import React, { useEffect, useState } from "react";
import { Image as RNImage } from "react-native";
import Photo from "realmModels/Photo";
import getImageDimensions from "sharedHelpers/getImageDimensions";
type Props = {
representativePhoto?: Object,
@@ -74,7 +74,7 @@ const PhotosSection = ( {
useEffect( ( ) => {
const checkImageOrientation = async ( ) => {
if ( observationPhoto ) {
const imageDimensions = await getImageDimensions( observationPhoto );
const imageDimensions = await RNImage.getSize( observationPhoto );
if ( imageDimensions.width < imageDimensions.height ) {
setDisplayPortraitLayout( true );
} else {

View File

@@ -1,7 +1,7 @@
import { ScrollView, View } from "components/styledComponents";
import React, { useEffect, useState } from "react";
import { Image } from "react-native";
import Photo from "realmModels/Photo";
import getImageDimensions from "sharedHelpers/getImageDimensions";
import PhotoContainer from "./PhotoContainer";
import SoundContainer from "./SoundContainer";
@@ -25,7 +25,7 @@ const MasonryLayout = ( { items, onImagePress } ) => {
if ( item.file_url ) {
return item;
}
const imageDimensions = await getImageDimensions( photoUrl( item ) );
const imageDimensions = await Image.getSize( photoUrl( item ) );
return Object.assign( item, imageDimensions );
} );

View File

@@ -1,15 +0,0 @@
import { Image } from "react-native";
type ImageDimensions = {
width: number;
height: number;
};
// A helper function to get the image dimensions
const getImageDimensions = async ( uri: string ) => new Promise<ImageDimensions>( resolve => {
Image.getSize( uri, ( width, height ) => {
resolve( { width, height } );
} );
} );
export default getImageDimensions;

View File

@@ -6,9 +6,7 @@ import { Image } from "react-native";
import factory from "tests/factory";
import faker from "tests/helpers/faker";
Image.getSize = jest.fn( ( uri, callback ) => {
callback( { width: 1024, height: 768 } );
} );
Image.getSize = jest.fn( ( _uri, _callback ) => async () => ( { width: 1024, height: 768 } ) );
const mockObservation = factory( "LocalObservation", {
created_at: "2022-11-27T19:07:41-08:00",