From 70cab3f36b915c494e549dff27a594d978bca3c6 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Thu, 20 Nov 2025 16:51:35 -0600 Subject: [PATCH] fix(image-source): url loading under different conditions --- apps/toolbox/src/pages/image-async.ts | 2 +- packages/core/http/http-shared.ts | 18 ++---------------- packages/core/http/index.ts | 3 +-- packages/core/image-source/index.android.ts | 4 ++-- packages/core/image-source/index.ios.ts | 4 ++-- 5 files changed, 8 insertions(+), 23 deletions(-) diff --git a/apps/toolbox/src/pages/image-async.ts b/apps/toolbox/src/pages/image-async.ts index 0df2b77c1f..68c9339783 100644 --- a/apps/toolbox/src/pages/image-async.ts +++ b/apps/toolbox/src/pages/image-async.ts @@ -8,7 +8,7 @@ export function navigatingTo(args: EventData) { } export class SampleData extends Observable { - src: string = 'https://source.unsplash.com/random'; + src: string = 'https://i.pravatar.cc/300'; savedData: string = ''; resizedImage: ImageSource; async save() { diff --git a/packages/core/http/http-shared.ts b/packages/core/http/http-shared.ts index d2e21b3ca8..aacb5eaf7a 100644 --- a/packages/core/http/http-shared.ts +++ b/packages/core/http/http-shared.ts @@ -1,21 +1,7 @@ -// Shared types and interfaces for http and image-source modules. -// Only put platform-agnostic types/interfaces here. - // Example: (add more as needed) -// TODO: look at removing this after circulars are completely resolved. +// Note: Circular dep help between http and image-source. +// Interfaces can be moved around further in future to help avoid. export interface ImageSourceLike { toBase64String(format: string, quality?: number): string; // ... add other shared methods/properties as needed } - -// Circular dependency resolution handling (http <--> image-source) -let _getImage: (arg: any) => Promise; -export function getImageRequest(arg: any): Promise { - if (_getImage) { - return _getImage(arg); - } - return Promise.reject(new Error('No getImage request handler set.')); -} -export function setGetImageRequest(fn: (arg: any) => Promise) { - _getImage = fn; -} diff --git a/packages/core/http/index.ts b/packages/core/http/index.ts index e175ffa6ae..fd43bb3f3f 100644 --- a/packages/core/http/index.ts +++ b/packages/core/http/index.ts @@ -1,4 +1,4 @@ -import { setGetImageRequest, type ImageSourceLike } from './http-shared'; +import { type ImageSourceLike } from './http-shared'; import { request } from './http-request'; export { request } from './http-request'; export * from './http-interfaces'; @@ -51,7 +51,6 @@ export function getImage(arg: any): Promise { ); }); } -setGetImageRequest(getImage); export function getFile(arg: any, destinationFilePath?: string): Promise { return new Promise((resolve, reject) => { diff --git a/packages/core/image-source/index.android.ts b/packages/core/image-source/index.android.ts index cd4d7938f6..f7099e0753 100644 --- a/packages/core/image-source/index.android.ts +++ b/packages/core/image-source/index.android.ts @@ -1,6 +1,6 @@ import { ImageSource as ImageSourceDefinition, iosSymbolScaleType } from '.'; import { ImageAsset } from '../image-asset'; -import { getImageRequest } from '../http/http-shared'; +import { getImage } from '../http'; import { path as fsPath, knownFolders } from '../file-system'; import { isFileOrResourcePath, RESOURCE_PREFIX, layout } from '../utils'; import { getNativeApp } from '../application/helpers-common'; @@ -63,7 +63,7 @@ export class ImageSource implements ImageSourceDefinition { } static fromUrl(url: string): Promise { - return getImageRequest(url) as Promise; + return getImage(url) as Promise; } static fromResourceSync(name: string): ImageSource { diff --git a/packages/core/image-source/index.ios.ts b/packages/core/image-source/index.ios.ts index 684cb3eb65..e0218b59c4 100644 --- a/packages/core/image-source/index.ios.ts +++ b/packages/core/image-source/index.ios.ts @@ -7,7 +7,7 @@ import { Trace } from '../trace'; import { path as fsPath, knownFolders } from '../file-system'; import { isFileOrResourcePath, RESOURCE_PREFIX, layout, releaseNativeObject, SYSTEM_PREFIX } from '../utils'; import { getScaledDimensions } from './image-source-common'; -import { getImageRequest } from '../http/http-shared'; +import { getImage } from '../http'; export { isFileOrResourcePath }; @@ -58,7 +58,7 @@ export class ImageSource implements ImageSourceDefinition { } static fromUrl(url: string): Promise { - return getImageRequest(url) as Promise; + return getImage(url) as Promise; } static iosSystemScaleFor(scale: iosSymbolScaleType) {