fix(core): circular imports of SDK_VERSION

This commit is contained in:
Nathan Walker
2022-11-30 09:10:11 -08:00
parent 55d24d30ce
commit 82d60ae057
28 changed files with 67 additions and 41 deletions

View File

@ -2,6 +2,7 @@ import * as Application from '../application';
import { Observable } from '../data/observable';
import { Trace } from '../trace';
import * as Utils from '../utils';
import { SDK_VERSION } from '../utils/constants';
import { CommonA11YServiceEnabledObservable, SharedA11YObservable } from './accessibility-service-common';
export function getAndroidAccessibilityManager(): android.view.accessibility.AccessibilityManager | null {
@ -73,7 +74,7 @@ function ensureStateListener(): SharedA11YObservable {
});
accessibilityManager.addAccessibilityStateChangeListener(accessibilityStateChangeListener);
if (Utils.SDK_VERSION >= 19) {
if (SDK_VERSION >= 19) {
touchExplorationStateChangeListener = new android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener({
onTouchExplorationStateChanged(enabled) {
updateAccessibilityState();

View File

@ -1,6 +1,6 @@
import * as Application from '../application';
import { Trace } from '../trace';
import { SDK_VERSION } from '../utils';
import { SDK_VERSION } from '../utils/constants';
import type { View } from '../ui/core/view';
import { GestureTypes } from '../ui/gestures';
import { notifyAccessibilityFocusState } from './accessibility-common';

View File

@ -1,5 +1,5 @@
import { android as androidApp, getNativeApplication } from '../application';
import { SDK_VERSION } from '../utils';
import { SDK_VERSION } from '../utils/constants';
export enum connectionType {
none = 0,

View File

@ -1,6 +1,7 @@
import * as textModule from '../text';
import { getNativeApplication } from '../application';
import { SDK_VERSION } from '../utils';
import { getFileExtension } from '../utils';
import { SDK_VERSION } from '../utils/constants';
import type { IFileSystemAccess } from './file-system-access';
@ -529,12 +530,7 @@ export class FileSystemAccess implements IFileSystemAccess {
// TODO: This method is the same as in the iOS implementation.
// Make it in a separate file / module so it can be reused from both implementations.
public getFileExtension(path: string): string {
const dotIndex = path.lastIndexOf('.');
if (dotIndex && dotIndex >= 0 && dotIndex < path.length) {
return path.substring(dotIndex);
}
return '';
return getFileExtension(path);
}
private enumEntities(path: string, callback: (entity: { path: string; name: string; extension: string }) => boolean, onError?: (error) => any) {

View File

@ -1,6 +1,5 @@
import { IFileSystemAccess, FileSystemAccess, FileSystemAccess29 } from './file-system-access';
import { Device } from '../platform';
import { SDK_VERSION } from '../utils';
import { SDK_VERSION } from '../utils/constants';
// The FileSystemAccess implementation, used through all the APIs.
let fileAccess: IFileSystemAccess;

View File

@ -1,5 +1,5 @@
import * as definition from './fps-native';
import { SDK_VERSION } from '../utils';
import { SDK_VERSION } from '../utils/constants';
export class FPSCallback implements definition.FPSCallback {
private impl: android.view.Choreographer.FrameCallback | ((nanos: number) => void);

View File

@ -105,10 +105,12 @@ export type { InstrumentationMode, TimerInfo } from './profiling';
export { encoding } from './text';
export * from './trace';
export * from './ui';
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, executeOnUIThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, escapeRegexSymbols, convertString, dismissSoftInput, dismissKeyboard, queueMacrotask, queueGC, throttle, debounce, dataSerialize, dataDeserialize, copyToClipboard } from './utils';
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, executeOnUIThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, escapeRegexSymbols, convertString, dismissSoftInput, dismissKeyboard, queueMacrotask, queueGC, throttle, debounce, dataSerialize, dataDeserialize, copyToClipboard, getFileExtension } from './utils';
import { SDK_VERSION } from './utils/constants';
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback, numberHasDecimals, numberIs64Bit } from './utils/types';
export declare const Utils: {
GC: typeof GC;
SDK_VERSION: typeof SDK_VERSION;
RESOURCE_PREFIX: string;
FILE_PREFIX: string;
queueMacrotask: typeof queueMacrotask;
@ -118,6 +120,7 @@ export declare const Utils: {
isFontIconURI: typeof isFontIconURI;
isDataURI: typeof isDataURI;
isFileOrResourcePath: typeof isFileOrResourcePath;
getFileExtension: typeof getFileExtension;
executeOnMainThread: typeof executeOnMainThread;
executeOnUIThread: typeof executeOnUIThread;
mainThreadify: typeof mainThreadify;

View File

@ -137,16 +137,19 @@ export * from './trace';
export * from './ui';
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, executeOnUIThread, queueMacrotask, queueGC, debounce, throttle, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX, escapeRegexSymbols, convertString, dismissSoftInput, dismissKeyboard, dataDeserialize, dataSerialize, copyToClipboard } from './utils';
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, executeOnUIThread, queueMacrotask, queueGC, debounce, throttle, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX, escapeRegexSymbols, convertString, dismissSoftInput, dismissKeyboard, dataDeserialize, dataSerialize, copyToClipboard, getFileExtension } from './utils';
import { SDK_VERSION } from './utils/constants';
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback, numberHasDecimals, numberIs64Bit } from './utils/types';
export const Utils = {
GC,
SDK_VERSION,
RESOURCE_PREFIX,
FILE_PREFIX,
isFontIconURI,
isDataURI,
isFileOrResourcePath,
getFileExtension,
executeOnMainThread,
executeOnUIThread,
mainThreadify,

View File

@ -1,6 +1,6 @@
/* tslint:disable:class-name */
import { getNativeApplication, on, orientationChangedEvent, android as AndroidApplication } from '../application';
import { SDK_VERSION } from '../utils';
import { SDK_VERSION } from '../utils/constants';
const MIN_TABLET_PIXELS = 600;

View File

@ -8,7 +8,7 @@ import { ImageSource } from '../../image-source';
import * as application from '../../application';
import { isAccessibilityServiceEnabled, updateContentDescription } from '../../accessibility';
import type { Background } from '../styling/background';
import { SDK_VERSION } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
export * from './action-bar-common';

View File

@ -7,7 +7,8 @@ import { AnimationBase, Properties, CubicBezierAnimationCurve } from './animatio
import { Color } from '../../color';
import { Trace } from '../../trace';
import { opacityProperty, backgroundColorProperty, rotateProperty, rotateXProperty, rotateYProperty, translateXProperty, translateYProperty, scaleXProperty, scaleYProperty, heightProperty, widthProperty, PercentLength } from '../styling/style-properties';
import { SDK_VERSION, layout } from '../../utils';
import { layout } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
import { Device, Screen } from '../../platform';
import lazy from '../../utils/lazy';

View File

@ -6,7 +6,7 @@ import { CoreTypes } from '../../core-types';
import { profile } from '../../profiling';
import { TouchGestureEventData, GestureTypes, TouchAction } from '../gestures';
import { Device } from '../../platform';
import { SDK_VERSION } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
import lazy from '../../utils/lazy';
import type { Background } from '../styling/background';

View File

@ -23,6 +23,7 @@ import lazy from '../../../utils/lazy';
import { accessibilityEnabledProperty, accessibilityHiddenProperty, accessibilityHintProperty, accessibilityIdentifierProperty, accessibilityLabelProperty, accessibilityLanguageProperty, accessibilityLiveRegionProperty, accessibilityMediaSessionProperty, accessibilityRoleProperty, accessibilityStateProperty, accessibilityValueProperty } from '../../../accessibility/accessibility-properties';
import { AccessibilityLiveRegion, AccessibilityRole, AndroidAccessibilityEvent, setupAccessibleView, isAccessibilityServiceEnabled, sendAccessibilityEvent, updateAccessibilityProperties, updateContentDescription, AccessibilityState } from '../../../accessibility';
import * as Utils from '../../../utils';
import { SDK_VERSION } from '../../../utils/constants';
import { CSSShadow } from '../../styling/css-shadow';
export * from './view-common';
@ -846,7 +847,7 @@ export class View extends ViewCommon {
this.accessibilityRole = value;
updateAccessibilityProperties(this);
if (Utils.SDK_VERSION >= 28) {
if (SDK_VERSION >= 28) {
this.nativeViewProtected?.setAccessibilityHeading(value === AccessibilityRole.Header);
}
}
@ -904,7 +905,7 @@ export class View extends ViewCommon {
return this.getDefaultElevation();
}
[androidElevationProperty.setNative](value: number) {
if (Utils.SDK_VERSION < 21) {
if (SDK_VERSION < 21) {
return;
}
@ -915,7 +916,7 @@ export class View extends ViewCommon {
return this.getDefaultDynamicElevationOffset();
}
[androidDynamicElevationOffsetProperty.setNative](value: number) {
if (Utils.SDK_VERSION < 21) {
if (SDK_VERSION < 21) {
return;
}
@ -923,7 +924,7 @@ export class View extends ViewCommon {
}
protected getDefaultElevation(): number {
if (Utils.SDK_VERSION < 21) {
if (SDK_VERSION < 21) {
return 0;
}

View File

@ -1,7 +1,8 @@
import { EditableTextBase as EditableTextBaseCommon, autofillTypeProperty, keyboardTypeProperty, returnKeyTypeProperty, editableProperty, autocapitalizationTypeProperty, autocorrectProperty, hintProperty, placeholderColorProperty, maxLengthProperty } from './editable-text-base-common';
import { textTransformProperty, textProperty, resetSymbol } from '../text-base';
import { Color } from '../../color';
import { SDK_VERSION, ad } from '../../utils';
import { ad } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
import { CoreTypes } from '../../core-types';
export * from './editable-text-base-common';

View File

@ -1,5 +1,5 @@
import { Color } from '../../color';
import { SDK_VERSION } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
import { Font } from '../styling/font';
import { colorProperty, fontSizeProperty, fontInternalProperty } from '../styling/style-properties';
import { HtmlViewBase, htmlProperty, selectableProperty, linkColorProperty } from './html-view-common';

View File

@ -4,7 +4,7 @@ import { View } from '../core/view';
import { Color } from '../../color';
import { ActionBar } from '../action-bar';
import { GridLayout } from '../layouts/grid-layout';
import { SDK_VERSION } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
import { profile } from '../../profiling';
import { AndroidAccessibilityEvent, getLastFocusedViewOnPage, isAccessibilityServiceEnabled } from '../../accessibility';

View File

@ -3,7 +3,8 @@ import { SegmentedBarItemBase, SegmentedBarBase, selectedIndexProperty, itemsPro
import { isEnabledProperty } from '../core/view';
import { colorProperty, fontInternalProperty, fontSizeProperty } from '../styling/style-properties';
import { Color } from '../../color';
import { SDK_VERSION, layout } from '../../utils';
import { layout } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
export * from './segmented-bar-common';

View File

@ -1,7 +1,7 @@
import { Font as FontBase, parseFontFamily, genericFontFamilies, FontWeight, FontVariationSettings } from './font-common';
import { FontStyleType, FontWeightType, FontVariationSettingsType } from './font-interfaces';
import { Trace } from '../../trace';
import { SDK_VERSION } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
import * as fs from '../../file-system';
import { ad } from '../../utils';

View File

@ -11,7 +11,8 @@ import { colorProperty, fontSizeProperty, fontInternalProperty, paddingLeftPrope
import { FormattedString } from './formatted-string';
import { Span } from './span';
import { CoreTypes } from '../../core-types';
import { SDK_VERSION, layout } from '../../utils';
import { layout } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
import { isString, isNullOrUndefined } from '../../utils/types';
import { accessibilityIdentifierProperty } from '../../accessibility/accessibility-properties';
import * as Utils from '../../utils';

View File

@ -1,5 +1,5 @@
import { TimePickerBase, getValidTime, timeProperty, hourProperty, minuteProperty } from './time-picker-common';
import { SDK_VERSION } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
export * from './time-picker-common';

View File

@ -74,6 +74,20 @@ 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;

View File

@ -0,0 +1 @@
export const SDK_VERSION = android.os.Build.VERSION.SDK_INT;

1
packages/core/utils/constants.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export const SDK_VERSION: number;

View File

@ -0,0 +1 @@
export const SDK_VERSION = parseFloat(UIDevice.currentDevice.systemVersion);

View File

@ -6,7 +6,7 @@ let applicationRootPath: string;
function ensureAppRootPath() {
if (!applicationRootPath) {
applicationRootPath = knownFolders.currentApp().path;
applicationRootPath = applicationRootPath.substr(0, applicationRootPath.length - 'app/'.length);
applicationRootPath = applicationRootPath.substring(0, applicationRootPath.length - 'app/'.length);
}
}
@ -20,8 +20,8 @@ export class Source {
constructor(uri: string, line: number, column: number) {
ensureAppRootPath();
if (uri.length > applicationRootPath.length && uri.substr(0, applicationRootPath.length) === applicationRootPath) {
this._uri = 'file://' + uri.substr(applicationRootPath.length);
if (uri.length > applicationRootPath.length && uri.substring(0, applicationRootPath.length) === applicationRootPath) {
this._uri = 'file://' + uri.substring(applicationRootPath.length);
} else {
this._uri = uri;
}

View File

@ -1,14 +1,13 @@
import { ad } from './native-helper';
import { FileSystemAccess } from '../file-system/file-system-access';
import { Trace } from '../trace';
import { getFileExtension } from './common';
import { SDK_VERSION } from './constants';
export { ad, dataDeserialize, dataSerialize, iOSNativeHelper } from './native-helper';
export * from './layout-helper';
export * from './common';
export { Source } from './debug';
export const SDK_VERSION = android.os.Build.VERSION.SDK_INT;
const MIN_URI_SHARE_RESTRICTED_APK_VERSION = 24;
export function GC() {
@ -72,7 +71,7 @@ function isExternalStorageAvailable(): boolean {
*/
function getMimeTypeNameFromExtension(filePath: string): string {
const mimeTypeMap = android.webkit.MimeTypeMap.getSingleton();
const extension = new FileSystemAccess().getFileExtension(filePath).replace('.', '').toLowerCase();
const extension = getFileExtension(filePath).replace('.', '').toLowerCase();
return mimeTypeMap.getMimeTypeFromExtension(extension);
}

View File

@ -11,8 +11,6 @@ export * from './common';
export const RESOURCE_PREFIX: string;
export const FILE_PREFIX: string;
export const SDK_VERSION: number;
//@private
/**
* Used by various android event listener implementations.
@ -177,6 +175,13 @@ export function isFontIconURI(uri: string): boolean;
*/
export function isFileOrResourcePath(path: string): boolean;
/**
* Get file extension from file path
* @param path file path
* @returns file extension
*/
export function getFileExtension(path: string): string;
/**
* Returns true if the specified URI is data URI (http://en.wikipedia.org/wiki/Data_URI_scheme).
* @param uri The URI.

View File

@ -6,8 +6,6 @@ export * from './layout-helper';
export * from './common';
export { Source } from './debug';
export const SDK_VERSION = parseFloat(UIDevice.currentDevice.systemVersion);
export function openFile(filePath: string): boolean {
try {
const appPath = iOSNativeHelper.getCurrentAppPath();