Skip to content

Commit 70cab3f

Browse files
committed
fix(image-source): url loading under different conditions
1 parent dec2b4b commit 70cab3f

File tree

5 files changed

+8
-23
lines changed

5 files changed

+8
-23
lines changed

apps/toolbox/src/pages/image-async.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function navigatingTo(args: EventData) {
88
}
99

1010
export class SampleData extends Observable {
11-
src: string = 'https://source.unsplash.com/random';
11+
src: string = 'https://i.pravatar.cc/300';
1212
savedData: string = '';
1313
resizedImage: ImageSource;
1414
async save() {

packages/core/http/http-shared.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
// Shared types and interfaces for http and image-source modules.
2-
// Only put platform-agnostic types/interfaces here.
3-
41
// Example: (add more as needed)
5-
// TODO: look at removing this after circulars are completely resolved.
2+
// Note: Circular dep help between http and image-source.
3+
// Interfaces can be moved around further in future to help avoid.
64
export interface ImageSourceLike {
75
toBase64String(format: string, quality?: number): string;
86
// ... add other shared methods/properties as needed
97
}
10-
11-
// Circular dependency resolution handling (http <--> image-source)
12-
let _getImage: (arg: any) => Promise<ImageSourceLike>;
13-
export function getImageRequest(arg: any): Promise<ImageSourceLike> {
14-
if (_getImage) {
15-
return _getImage(arg);
16-
}
17-
return Promise.reject(new Error('No getImage request handler set.'));
18-
}
19-
export function setGetImageRequest(fn: (arg: any) => Promise<ImageSourceLike>) {
20-
_getImage = fn;
21-
}

packages/core/http/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setGetImageRequest, type ImageSourceLike } from './http-shared';
1+
import { type ImageSourceLike } from './http-shared';
22
import { request } from './http-request';
33
export { request } from './http-request';
44
export * from './http-interfaces';
@@ -51,7 +51,6 @@ export function getImage(arg: any): Promise<ImageSourceLike> {
5151
);
5252
});
5353
}
54-
setGetImageRequest(getImage);
5554

5655
export function getFile(arg: any, destinationFilePath?: string): Promise<any> {
5756
return new Promise<any>((resolve, reject) => {

packages/core/image-source/index.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ImageSource as ImageSourceDefinition, iosSymbolScaleType } from '.';
22
import { ImageAsset } from '../image-asset';
3-
import { getImageRequest } from '../http/http-shared';
3+
import { getImage } from '../http';
44
import { path as fsPath, knownFolders } from '../file-system';
55
import { isFileOrResourcePath, RESOURCE_PREFIX, layout } from '../utils';
66
import { getNativeApp } from '../application/helpers-common';
@@ -63,7 +63,7 @@ export class ImageSource implements ImageSourceDefinition {
6363
}
6464

6565
static fromUrl(url: string): Promise<ImageSource> {
66-
return getImageRequest(url) as Promise<ImageSource>;
66+
return getImage(url) as Promise<ImageSource>;
6767
}
6868

6969
static fromResourceSync(name: string): ImageSource {

packages/core/image-source/index.ios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Trace } from '../trace';
77
import { path as fsPath, knownFolders } from '../file-system';
88
import { isFileOrResourcePath, RESOURCE_PREFIX, layout, releaseNativeObject, SYSTEM_PREFIX } from '../utils';
99
import { getScaledDimensions } from './image-source-common';
10-
import { getImageRequest } from '../http/http-shared';
10+
import { getImage } from '../http';
1111

1212
export { isFileOrResourcePath };
1313

@@ -58,7 +58,7 @@ export class ImageSource implements ImageSourceDefinition {
5858
}
5959

6060
static fromUrl(url: string): Promise<ImageSource> {
61-
return getImageRequest(url) as Promise<ImageSource>;
61+
return getImage(url) as Promise<ImageSource>;
6262
}
6363

6464
static iosSystemScaleFor(scale: iosSymbolScaleType) {

0 commit comments

Comments
 (0)