mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
refactor: circular deps part 9
This commit is contained in:
9
packages/core/http/http-shared.ts
Normal file
9
packages/core/http/http-shared.ts
Normal file
@ -0,0 +1,9 @@
|
||||
// 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.
|
||||
export interface ImageSourceLike {
|
||||
toBase64String(format: string, quality?: number): string;
|
||||
// ... add other shared methods/properties as needed
|
||||
}
|
9
packages/core/http/index.d.ts
vendored
9
packages/core/http/index.d.ts
vendored
@ -1,4 +1,5 @@
|
||||
import { ImageSource } from '../image-source';
|
||||
// import { ImageSource } from '../image-source';
|
||||
import type { ImageSourceLike } from './http-shared';
|
||||
import { File } from '../file-system';
|
||||
|
||||
/**
|
||||
@ -29,13 +30,13 @@ export function getJSON<T>(options: HttpRequestOptions): Promise<T>;
|
||||
* Downloads the content from the specified URL and attempts to decode it as an image.
|
||||
* @param url The URL to request from.
|
||||
*/
|
||||
export function getImage(url: string): Promise<ImageSource>;
|
||||
export function getImage(url: string): Promise<ImageSourceLike>;
|
||||
|
||||
/**
|
||||
* Downloads the content from the specified URL and attempts to decode it as an image.
|
||||
* @param options An object that specifies various request options.
|
||||
*/
|
||||
export function getImage(options: HttpRequestOptions): Promise<ImageSource>;
|
||||
export function getImage(options: HttpRequestOptions): Promise<ImageSourceLike>;
|
||||
|
||||
/**
|
||||
* Downloads the content from the specified URL and attempts to save it as file.
|
||||
@ -157,7 +158,7 @@ export interface HttpContent {
|
||||
/**
|
||||
* Gets the response body as ImageSource.
|
||||
*/
|
||||
toImage: () => Promise<ImageSource>;
|
||||
toImage: () => Promise<ImageSourceLike>;
|
||||
|
||||
/**
|
||||
* Gets the response body as file.
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ImageSource } from '../image-source';
|
||||
import type { ImageSourceLike } from './http-shared';
|
||||
import { File } from '../file-system';
|
||||
import * as httpRequest from './http-request';
|
||||
export * from './http-request';
|
||||
@ -91,7 +91,7 @@ export interface HttpContent {
|
||||
/**
|
||||
* Gets the response body as ImageSource.
|
||||
*/
|
||||
toImage: () => Promise<ImageSource>;
|
||||
toImage: () => Promise<ImageSourceLike>;
|
||||
|
||||
/**
|
||||
* Gets the response body as file.
|
||||
@ -131,7 +131,7 @@ export function getJSON<T>(arg: any): Promise<T> {
|
||||
});
|
||||
}
|
||||
|
||||
export function getImage(arg: any): Promise<ImageSource> {
|
||||
export function getImage(arg: any): Promise<ImageSourceLike> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
httpRequest.request(typeof arg === 'string' ? { url: arg, method: 'GET' } : arg).then(
|
||||
(r) => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Definitions.
|
||||
import { ImageSource as ImageSourceDefinition, iosSymbolScaleType } from '.';
|
||||
import { ImageAsset } from '../image-asset';
|
||||
import * as httpModule from '../http';
|
||||
import * as http from '../http';
|
||||
|
||||
// Types.
|
||||
import { path as fsPath, knownFolders } from '../file-system';
|
||||
@ -14,13 +14,6 @@ import { getScaledDimensions } from './image-source-common';
|
||||
|
||||
export { isFileOrResourcePath };
|
||||
|
||||
let http: typeof httpModule;
|
||||
function ensureHttp() {
|
||||
if (!http) {
|
||||
http = require('../http');
|
||||
}
|
||||
}
|
||||
|
||||
let application: android.app.Application;
|
||||
let resources: android.content.res.Resources;
|
||||
|
||||
@ -87,10 +80,8 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
});
|
||||
}
|
||||
|
||||
static fromUrl(url: string): Promise<ImageSourceDefinition> {
|
||||
ensureHttp();
|
||||
|
||||
return http.getImage(url);
|
||||
static fromUrl(url: string): Promise<ImageSource> {
|
||||
return http.getImage(url) as Promise<ImageSource>;
|
||||
}
|
||||
|
||||
static fromResourceSync(name: string): ImageSource {
|
||||
|
@ -2,7 +2,6 @@
|
||||
import { ImageSource as ImageSourceDefinition, iosSymbolScaleType } from '.';
|
||||
import { ImageAsset } from '../image-asset';
|
||||
import type { ImageBase } from '../ui/image/image-common';
|
||||
import * as httpModule from '../http';
|
||||
import { Font } from '../ui/styling/font';
|
||||
import { Color } from '../color';
|
||||
import { Trace } from '../trace';
|
||||
@ -12,16 +11,10 @@ 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 * as http from '../http';
|
||||
|
||||
export { isFileOrResourcePath };
|
||||
|
||||
let http: typeof httpModule;
|
||||
function ensureHttp() {
|
||||
if (!http) {
|
||||
http = require('../http');
|
||||
}
|
||||
}
|
||||
|
||||
export class ImageSource implements ImageSourceDefinition {
|
||||
public android: android.graphics.Bitmap;
|
||||
public ios: UIImage;
|
||||
@ -69,9 +62,7 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
}
|
||||
|
||||
static fromUrl(url: string): Promise<ImageSource> {
|
||||
ensureHttp();
|
||||
|
||||
return http.getImage(url);
|
||||
return http.getImage(url) as Promise<ImageSource>;
|
||||
}
|
||||
|
||||
static iosSystemScaleFor(scale: iosSymbolScaleType) {
|
||||
|
@ -1,12 +1,11 @@
|
||||
import { AlignSelf, Flex, FlexFlow, FlexGrow, FlexShrink, FlexWrapBefore, Order } from '../../layouts/flexbox-layout';
|
||||
import { Page } from '../../page';
|
||||
import { CoreTypes } from '../../../core-types';
|
||||
import { CoreTypes, Trace } from '../../styling/styling-shared';
|
||||
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, initNativeView } from '../properties';
|
||||
import { CSSUtils } from '../../../css/system-classes';
|
||||
import { Source } from '../../../utils/debug-source';
|
||||
import { Binding } from '../bindable';
|
||||
import { BindingOptions } from '../bindable/bindable-types';
|
||||
import { Trace } from '../../../trace';
|
||||
import { Observable, PropertyChangeData, WrappedValue } from '../../../data/observable';
|
||||
import { Style } from '../../styling/style';
|
||||
import { paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty } from '../../styling/style-properties';
|
||||
|
@ -8,8 +8,6 @@ import { sanitizeModuleName } from '../../../utils/common';
|
||||
import { Color } from '../../../color';
|
||||
import { Property, InheritedProperty } from '../properties';
|
||||
import { EventData } from '../../../data/observable';
|
||||
import { Trace } from '../../../trace';
|
||||
import { CoreTypes } from '../../../core-types';
|
||||
import { ViewHelper } from './view-helper';
|
||||
import { setupAccessibleView } from '../../../application';
|
||||
|
||||
@ -31,6 +29,7 @@ import { accessibilityBlurEvent, accessibilityFocusChangedEvent, accessibilityFo
|
||||
import { ShadowCSSValues } from '../../styling/css-shadow';
|
||||
import { SharedTransition, SharedTransitionInteractiveOptions } from '../../transition/shared-transition';
|
||||
import { Flex, FlexFlow } from '../../layouts/flexbox-layout';
|
||||
import { CoreTypes, Trace } from '../../styling/styling-shared';
|
||||
|
||||
// helpers (these are okay re-exported here)
|
||||
export * from './view-helper';
|
||||
|
@ -5,8 +5,8 @@ import type { View } from '..';
|
||||
// Requires
|
||||
import { ViewHelper } from './view-helper-common';
|
||||
import { SDK_VERSION } from '../../../../utils/constants';
|
||||
import { ios as iOSUtils, layout } from '../../../../utils';
|
||||
import { Trace } from '../../../../trace';
|
||||
import { layout, Trace } from './view-helper-shared';
|
||||
import { ios as iOSUtils } from '../../../../utils';
|
||||
|
||||
export * from './view-helper-common';
|
||||
export const AndroidHelper = 0;
|
||||
|
@ -1,10 +1,6 @@
|
||||
// Types
|
||||
import { View as ViewDefinition } from '..';
|
||||
import { CoreTypes } from '../../../../core-types';
|
||||
|
||||
// Requires
|
||||
import { layout } from '../../../../utils';
|
||||
import { Trace } from '../../../../trace';
|
||||
import { CoreTypes, layout, Trace } from './view-helper-shared';
|
||||
|
||||
export class ViewHelper {
|
||||
public static measureChild(parent: ViewDefinition, child: ViewDefinition, widthMeasureSpec: number, heightMeasureSpec: number): { measuredWidth: number; measuredHeight: number } {
|
||||
|
@ -0,0 +1,9 @@
|
||||
// Shared helpers and types for view-helper, used by both common and platform-specific files.
|
||||
// Only put platform-agnostic logic here.
|
||||
|
||||
import { CoreTypes } from '../../../../core-types';
|
||||
import { layout } from '../../../../utils';
|
||||
import { Trace } from '../../../../trace';
|
||||
|
||||
export type { CoreTypes };
|
||||
export { layout, Trace };
|
@ -1,7 +1,7 @@
|
||||
import { parse as convertToCSSWhatSelector, Selector as CSSWhatSelector, DataType as CSSWhatDataType } from 'css-what';
|
||||
import '../../globals';
|
||||
import { isCssVariable } from '../core/properties';
|
||||
import { Trace } from '../../trace';
|
||||
import { Trace, CoreTypes } from './styling-shared';
|
||||
import { isNullOrUndefined } from '../../utils/types';
|
||||
|
||||
import * as ReworkCSS from '../../css';
|
||||
|
@ -4,10 +4,10 @@ import { unsetValue, _evaluateCssVariableExpression, _evaluateCssCalcExpression,
|
||||
import * as ReworkCSS from '../../css';
|
||||
|
||||
import { RuleSet, StyleSheetSelectorScope, SelectorCore, SelectorsMatch, ChangeMap, fromAstNode, Node, MEDIA_QUERY_SEPARATOR, matchMediaQueryString } from './css-selector';
|
||||
import { Trace } from '../../trace';
|
||||
import { Trace, CoreTypes } from './styling-shared';
|
||||
import { File, knownFolders, path } from '../../file-system';
|
||||
import { Application, CssChangedEventData, LoadAppCSSEventData } from '../../application';
|
||||
import { profile } from '../../profiling';
|
||||
import { profile } from './styling-profile';
|
||||
|
||||
import * as kam from '../animation/keyframe-animation';
|
||||
let keyframeAnimationModule: typeof kam;
|
||||
|
4
packages/core/ui/styling/styling-profile.ts
Normal file
4
packages/core/ui/styling/styling-profile.ts
Normal file
@ -0,0 +1,4 @@
|
||||
// This file exists to break cycles caused by importing profiling into style-scope.ts.
|
||||
// Only put the @profile decorator and related logic here.
|
||||
|
||||
export { profile } from '../../profiling';
|
7
packages/core/ui/styling/styling-shared.ts
Normal file
7
packages/core/ui/styling/styling-shared.ts
Normal file
@ -0,0 +1,7 @@
|
||||
// Shared helpers and types for styling, used by both styling and view/dialogs/frame modules.
|
||||
// Only put platform-agnostic logic here.
|
||||
|
||||
import { Trace } from '../../trace';
|
||||
import { CoreTypes } from '../../core-types';
|
||||
|
||||
export { Trace, CoreTypes };
|
@ -101,20 +101,6 @@ export function isDataURI(uri: string): boolean {
|
||||
return firstSegment && firstSegment.indexOf('data:') === 0 && firstSegment.indexOf('base64') >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file extension from file path
|
||||
* @param path file path
|
||||
* @returns file extension
|
||||
*/
|
||||
export function getFileExtension(path: string): string {
|
||||
const dotIndex = path.lastIndexOf('.');
|
||||
if (dotIndex && dotIndex >= 0 && dotIndex < path.length) {
|
||||
return path.substring(dotIndex);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
export function mergeSort(arr, compareFunc) {
|
||||
if (arr.length < 2) {
|
||||
return arr;
|
||||
@ -292,3 +278,5 @@ export function getDurationWithDampingFromSpring(springSettings?: { tension?: nu
|
||||
damping,
|
||||
};
|
||||
}
|
||||
|
||||
export { getFileExtension } from './utils-shared';
|
||||
|
@ -4,6 +4,7 @@ import { Color } from '../color';
|
||||
import { Trace } from '../trace';
|
||||
import { CORE_ANIMATION_DEFAULTS, getDurationWithDampingFromSpring } from './common';
|
||||
import { SDK_VERSION } from './constants';
|
||||
import { getFileExtension } from './utils-shared';
|
||||
|
||||
export function dataDeserialize(nativeData?: any) {
|
||||
if (isNullOrUndefined(nativeData)) {
|
||||
|
12
packages/core/utils/utils-shared.ts
Normal file
12
packages/core/utils/utils-shared.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// Shared helpers and types for utils, used by both native-helper and common.
|
||||
// Only put platform-agnostic logic here.
|
||||
|
||||
export function getFileExtension(path: string): string {
|
||||
if (!path) {
|
||||
return '';
|
||||
}
|
||||
const index = path.lastIndexOf('.');
|
||||
return index !== -1 ? path.substring(index + 1) : '';
|
||||
}
|
||||
|
||||
// Add more shared helpers/types/constants as needed.
|
Reference in New Issue
Block a user