mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
refactor: circular deps part 8
This commit is contained in:
@ -3,6 +3,7 @@ import type { View } from '../ui/core/view';
|
|||||||
import { isEmbedded } from '../ui/embedding';
|
import { isEmbedded } from '../ui/embedding';
|
||||||
import { IOSHelper } from '../ui/core/view/view-helper';
|
import { IOSHelper } from '../ui/core/view/view-helper';
|
||||||
import { NavigationEntry } from '../ui/frame/frame-interfaces';
|
import { NavigationEntry } from '../ui/frame/frame-interfaces';
|
||||||
|
import { getWindow } from '../utils/ios-helper';
|
||||||
import * as Utils from '../utils';
|
import * as Utils from '../utils';
|
||||||
import { ApplicationCommon } from './application-common';
|
import { ApplicationCommon } from './application-common';
|
||||||
import { ApplicationEventData } from './application-interfaces';
|
import { ApplicationEventData } from './application-interfaces';
|
||||||
@ -167,7 +168,7 @@ export class iOSApplication extends ApplicationCommon {
|
|||||||
}
|
}
|
||||||
this._rootView = rootView;
|
this._rootView = rootView;
|
||||||
// Attach to the existing iOS app
|
// Attach to the existing iOS app
|
||||||
const window = Utils.ios.getWindow();
|
const window = getWindow() as UIWindow;
|
||||||
|
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return;
|
return;
|
||||||
@ -282,7 +283,7 @@ export class iOSApplication extends ApplicationCommon {
|
|||||||
// particularly with SwiftUI app lifecycle based apps
|
// particularly with SwiftUI app lifecycle based apps
|
||||||
if (!this._window) {
|
if (!this._window) {
|
||||||
// Note: NativeScriptViewFactory.getKeyWindow will always be used in SwiftUI app lifecycle based apps
|
// Note: NativeScriptViewFactory.getKeyWindow will always be used in SwiftUI app lifecycle based apps
|
||||||
this._window = Utils.ios.getWindow();
|
this._window = getWindow() as UIWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._window;
|
return this._window;
|
||||||
|
@ -1,21 +1,11 @@
|
|||||||
import * as textModule from '../text';
|
import * as textModule from '../text';
|
||||||
import { Application } from '../application';
|
import { getFileExtension, android as androidUtils } from '../utils';
|
||||||
import { getFileExtension } from '../utils';
|
|
||||||
import { SDK_VERSION } from '../utils/constants';
|
import { SDK_VERSION } from '../utils/constants';
|
||||||
|
|
||||||
import type { IFileSystemAccess } from './file-system-access';
|
import type { IFileSystemAccess } from './file-system-access';
|
||||||
|
|
||||||
let applicationContext: android.content.Context;
|
|
||||||
function getApplicationContext() {
|
|
||||||
if (!applicationContext) {
|
|
||||||
applicationContext = Application.android.getNativeApplication().getApplicationContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
return applicationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getOrSetHelper(path: string): org.nativescript.widgets.FileHelper {
|
function getOrSetHelper(path: string): org.nativescript.widgets.FileHelper {
|
||||||
return org.nativescript.widgets.FileHelper.fromString(getApplicationContext(), path);
|
return org.nativescript.widgets.FileHelper.fromString(androidUtils.getApplicationContext(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isContentUri(path: string): boolean {
|
function isContentUri(path: string): boolean {
|
||||||
@ -222,30 +212,30 @@ export class FileSystemAccess implements IFileSystemAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getDocumentsFolderPath(): string {
|
public getDocumentsFolderPath(): string {
|
||||||
const dir = getApplicationContext().getFilesDir();
|
const dir = androidUtils.getApplicationContext().getFilesDir();
|
||||||
|
|
||||||
return dir.getAbsolutePath();
|
return dir.getAbsolutePath();
|
||||||
}
|
}
|
||||||
public getExternalDocumentsFolderPath(): string {
|
public getExternalDocumentsFolderPath(): string {
|
||||||
const dirs = getApplicationContext().getExternalFilesDirs(null);
|
const dirs = androidUtils.getApplicationContext().getExternalFilesDirs(null);
|
||||||
let dir;
|
let dir;
|
||||||
if (dirs && dirs.length > 1) {
|
if (dirs && dirs.length > 1) {
|
||||||
dir = dirs[dirs.length - 1];
|
dir = dirs[dirs.length - 1];
|
||||||
}
|
}
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
dir = getApplicationContext().getExternalFilesDir(null);
|
dir = androidUtils.getApplicationContext().getExternalFilesDir(null);
|
||||||
}
|
}
|
||||||
return dir.getAbsolutePath();
|
return dir.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getLogicalRootPath(): string {
|
public getLogicalRootPath(): string {
|
||||||
const dir = getApplicationContext().getFilesDir();
|
const dir = androidUtils.getApplicationContext().getFilesDir();
|
||||||
|
|
||||||
return dir.getCanonicalPath();
|
return dir.getCanonicalPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTempFolderPath(): string {
|
public getTempFolderPath(): string {
|
||||||
const dir = getApplicationContext().getCacheDir();
|
const dir = androidUtils.getApplicationContext().getCacheDir();
|
||||||
|
|
||||||
return dir.getAbsolutePath();
|
return dir.getAbsolutePath();
|
||||||
}
|
}
|
||||||
@ -258,7 +248,7 @@ export class FileSystemAccess implements IFileSystemAccess {
|
|||||||
|
|
||||||
public copySync(src: string, dest: string, onError?: (error: any) => any) {
|
public copySync(src: string, dest: string, onError?: (error: any) => any) {
|
||||||
try {
|
try {
|
||||||
return org.nativescript.widgets.Async.File.copySync(src, dest, getApplicationContext());
|
return org.nativescript.widgets.Async.File.copySync(src, dest, androidUtils.getApplicationContext());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (onError) {
|
if (onError) {
|
||||||
onError(error);
|
onError(error);
|
||||||
@ -282,7 +272,7 @@ export class FileSystemAccess implements IFileSystemAccess {
|
|||||||
reject(err);
|
reject(err);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
getApplicationContext(),
|
androidUtils.getApplicationContext(),
|
||||||
);
|
);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
reject(ex);
|
reject(ex);
|
||||||
@ -926,7 +916,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
}
|
}
|
||||||
fileExists(path: string): boolean {
|
fileExists(path: string): boolean {
|
||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return org.nativescript.widgets.FileHelper.exists(applicationContext, path);
|
return org.nativescript.widgets.FileHelper.exists(androidUtils.getApplicationContext(), path);
|
||||||
}
|
}
|
||||||
return super.fileExists(path);
|
return super.fileExists(path);
|
||||||
}
|
}
|
||||||
@ -939,7 +929,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
deleteFile(path: string, onError?: (error: any) => any) {
|
deleteFile(path: string, onError?: (error: any) => any) {
|
||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
try {
|
try {
|
||||||
getOrSetHelper(path).delete(applicationContext);
|
getOrSetHelper(path).delete(androidUtils.getApplicationContext());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
onError?.(e);
|
onError?.(e);
|
||||||
}
|
}
|
||||||
@ -968,7 +958,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getOrSetHelper(path).renameSync(applicationContext, newPath, callback);
|
getOrSetHelper(path).renameSync(androidUtils.getApplicationContext(), newPath, callback);
|
||||||
} else {
|
} else {
|
||||||
super.rename(path, newPath, onError);
|
super.rename(path, newPath, onError);
|
||||||
}
|
}
|
||||||
@ -977,7 +967,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
public renameAsync(path: string, newPath: string): Promise<any> {
|
public renameAsync(path: string, newPath: string): Promise<any> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
getOrSetHelper(path).renameSync(
|
getOrSetHelper(path).renameSync(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
newPath,
|
newPath,
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
onSuccess(result) {
|
onSuccess(result) {
|
||||||
@ -1010,7 +1000,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
getOrSetHelper(path).appendBuffer(
|
getOrSetHelper(path).appendBuffer(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
FileSystemAccess.getBuffer(content),
|
FileSystemAccess.getBuffer(content),
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
onSuccess(result) {
|
onSuccess(result) {
|
||||||
@ -1037,7 +1027,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getOrSetHelper(path).appendSync(applicationContext, FileSystemAccess.getBuffer(content), callback);
|
getOrSetHelper(path).appendSync(androidUtils.getApplicationContext(), FileSystemAccess.getBuffer(content), callback);
|
||||||
} else {
|
} else {
|
||||||
super.appendSync(path, content, onError);
|
super.appendSync(path, content, onError);
|
||||||
}
|
}
|
||||||
@ -1049,7 +1039,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
getOrSetHelper(path).append(
|
getOrSetHelper(path).append(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
content,
|
content,
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
onSuccess(result) {
|
onSuccess(result) {
|
||||||
@ -1076,7 +1066,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getOrSetHelper(path).appendSync(applicationContext, content, callback);
|
getOrSetHelper(path).appendSync(androidUtils.getApplicationContext(), content, callback);
|
||||||
} else {
|
} else {
|
||||||
super.appendSync(path, content, onError);
|
super.appendSync(path, content, onError);
|
||||||
}
|
}
|
||||||
@ -1088,7 +1078,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
getOrSetHelper(path).appendText(
|
getOrSetHelper(path).appendText(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
content,
|
content,
|
||||||
encoding ?? null,
|
encoding ?? null,
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
@ -1116,7 +1106,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getOrSetHelper(path).appendTextSync(applicationContext, content, encoding ?? null, callback);
|
getOrSetHelper(path).appendTextSync(androidUtils.getApplicationContext(), content, encoding ?? null, callback);
|
||||||
} else {
|
} else {
|
||||||
super.appendTextSync(path, content, onError);
|
super.appendTextSync(path, content, onError);
|
||||||
}
|
}
|
||||||
@ -1128,7 +1118,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
getOrSetHelper(path).readText(
|
getOrSetHelper(path).readText(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
encoding ?? null,
|
encoding ?? null,
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
onSuccess(result) {
|
onSuccess(result) {
|
||||||
@ -1154,7 +1144,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return getOrSetHelper(path).readTextSync(applicationContext, encoding ?? null, callback);
|
return getOrSetHelper(path).readTextSync(androidUtils.getApplicationContext(), encoding ?? null, callback);
|
||||||
} else {
|
} else {
|
||||||
return super.readTextSync(path, onError, encoding);
|
return super.readTextSync(path, onError, encoding);
|
||||||
}
|
}
|
||||||
@ -1166,7 +1156,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
getOrSetHelper(path).readBuffer(
|
getOrSetHelper(path).readBuffer(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
onSuccess(result) {
|
onSuccess(result) {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
@ -1192,7 +1182,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const ret = getOrSetHelper(path).readBufferSync(applicationContext, callback);
|
const ret = getOrSetHelper(path).readBufferSync(androidUtils.getApplicationContext(), callback);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -1207,7 +1197,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
getOrSetHelper(path).read(
|
getOrSetHelper(path).read(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
onSuccess(result) {
|
onSuccess(result) {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
@ -1233,7 +1223,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return getOrSetHelper(path).readSync(applicationContext, callback);
|
return getOrSetHelper(path).readSync(androidUtils.getApplicationContext(), callback);
|
||||||
}
|
}
|
||||||
return super.readSync(path, onError);
|
return super.readSync(path, onError);
|
||||||
}
|
}
|
||||||
@ -1244,7 +1234,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
getOrSetHelper(path).writeText(
|
getOrSetHelper(path).writeText(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
content,
|
content,
|
||||||
encoding ?? null,
|
encoding ?? null,
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
@ -1272,7 +1262,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getOrSetHelper(path).writeTextSync(applicationContext, content, encoding ?? null, callback);
|
getOrSetHelper(path).writeTextSync(androidUtils.getApplicationContext(), content, encoding ?? null, callback);
|
||||||
} else {
|
} else {
|
||||||
super.writeTextSync(path, content, onError);
|
super.writeTextSync(path, content, onError);
|
||||||
}
|
}
|
||||||
@ -1284,7 +1274,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
getOrSetHelper(path).writeBuffer(
|
getOrSetHelper(path).writeBuffer(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
FileSystemAccess.getBuffer(content),
|
FileSystemAccess.getBuffer(content),
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
onSuccess(result) {
|
onSuccess(result) {
|
||||||
@ -1311,7 +1301,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getOrSetHelper(path).writeSync(applicationContext, FileSystemAccess.getBuffer(content), callback);
|
getOrSetHelper(path).writeSync(androidUtils.getApplicationContext(), FileSystemAccess.getBuffer(content), callback);
|
||||||
} else {
|
} else {
|
||||||
super.writeSync(path, content, onError);
|
super.writeSync(path, content, onError);
|
||||||
}
|
}
|
||||||
@ -1323,7 +1313,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
if (isContentUri(path)) {
|
if (isContentUri(path)) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
getOrSetHelper(path).write(
|
getOrSetHelper(path).write(
|
||||||
applicationContext,
|
androidUtils.getApplicationContext(),
|
||||||
content,
|
content,
|
||||||
new org.nativescript.widgets.FileHelper.Callback({
|
new org.nativescript.widgets.FileHelper.Callback({
|
||||||
onSuccess(result) {
|
onSuccess(result) {
|
||||||
@ -1350,7 +1340,7 @@ export class FileSystemAccess29 extends FileSystemAccess {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getOrSetHelper(path).writeSync(applicationContext, content, callback);
|
getOrSetHelper(path).writeSync(androidUtils.getApplicationContext(), content, callback);
|
||||||
} else {
|
} else {
|
||||||
super.writeSync(path, content, onError);
|
super.writeSync(path, content, onError);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { IFileSystemAccess, FileSystemAccess, FileSystemAccess29 } from './file-system-access';
|
import { IFileSystemAccess, FileSystemAccess, FileSystemAccess29 } from './file-system-access';
|
||||||
import { SDK_VERSION } from '../utils';
|
import { SDK_VERSION } from '../utils/constants';
|
||||||
import { Application } from '../application';
|
import { android as androidUtils } from '../utils';
|
||||||
|
|
||||||
// The FileSystemAccess implementation, used through all the APIs.
|
// The FileSystemAccess implementation, used through all the APIs.
|
||||||
let fileAccess: IFileSystemAccess;
|
let fileAccess: IFileSystemAccess;
|
||||||
@ -182,15 +182,6 @@ export class FileSystemEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let applicationContext;
|
|
||||||
function getApplicationContext() {
|
|
||||||
if (!applicationContext) {
|
|
||||||
applicationContext = Application.android.getNativeApplication().getApplicationContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
return applicationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum AndroidDirectory {
|
export enum AndroidDirectory {
|
||||||
ALARMS = 'alarms',
|
ALARMS = 'alarms',
|
||||||
AUDIOBOOKS = 'audiobooks',
|
AUDIOBOOKS = 'audiobooks',
|
||||||
@ -279,7 +270,7 @@ class Android {
|
|||||||
throw new Error(`createFile is available on Android only!`);
|
throw new Error(`createFile is available on Android only!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const context = getApplicationContext() as android.content.Context;
|
const context = androidUtils.getApplicationContext() as android.content.Context;
|
||||||
|
|
||||||
const meta = new android.content.ContentValues();
|
const meta = new android.content.ContentValues();
|
||||||
meta.put(android.provider.MediaStore.MediaColumns.DISPLAY_NAME, options.name);
|
meta.put(android.provider.MediaStore.MediaColumns.DISPLAY_NAME, options.name);
|
||||||
@ -332,7 +323,7 @@ export class File extends FileSystemEntity {
|
|||||||
// falls back to creating a temp file without a known extension.
|
// falls back to creating a temp file without a known extension.
|
||||||
if (!fileInfo) {
|
if (!fileInfo) {
|
||||||
const tempFile = `${knownFolders.temp().path}/${java.util.UUID.randomUUID().toString()}`;
|
const tempFile = `${knownFolders.temp().path}/${java.util.UUID.randomUUID().toString()}`;
|
||||||
org.nativescript.widgets.Async.File.copySync(path, tempFile, getApplicationContext());
|
org.nativescript.widgets.Async.File.copySync(path, tempFile, androidUtils.getApplicationContext());
|
||||||
path = tempFile;
|
path = tempFile;
|
||||||
} else {
|
} else {
|
||||||
const ext = fileInfo.extension;
|
const ext = fileInfo.extension;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ios } from '../../utils';
|
import { getWindow } from '../../utils/ios-helper';
|
||||||
|
|
||||||
class MainScreen {
|
class MainScreen {
|
||||||
private _screen: UIScreen;
|
private _screen: UIScreen;
|
||||||
@ -6,7 +6,7 @@ class MainScreen {
|
|||||||
private get screen(): UIScreen {
|
private get screen(): UIScreen {
|
||||||
if (!this._screen) {
|
if (!this._screen) {
|
||||||
// NOTE: may not want to cache this value with SwiftUI app lifecycle based apps (using NativeScriptViewFactory) given the potential of multiple scenes
|
// NOTE: may not want to cache this value with SwiftUI app lifecycle based apps (using NativeScriptViewFactory) given the potential of multiple scenes
|
||||||
const window = ios.getWindow();
|
const window = getWindow() as UIWindow;
|
||||||
this._screen = window ? window.screen : UIScreen.mainScreen;
|
this._screen = window ? window.screen : UIScreen.mainScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { Page } from '../../page';
|
|||||||
import { CoreTypes } from '../../../core-types';
|
import { CoreTypes } from '../../../core-types';
|
||||||
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, initNativeView } from '../properties';
|
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, initNativeView } from '../properties';
|
||||||
import { CSSUtils } from '../../../css/system-classes';
|
import { CSSUtils } from '../../../css/system-classes';
|
||||||
import { Source } from '../../../utils/debug';
|
import { Source } from '../../../utils/debug-source';
|
||||||
import { Binding } from '../bindable';
|
import { Binding } from '../bindable';
|
||||||
import { BindingOptions } from '../bindable/bindable-types';
|
import { BindingOptions } from '../bindable/bindable-types';
|
||||||
import { Trace } from '../../../trace';
|
import { Trace } from '../../../trace';
|
||||||
|
73
packages/core/utils/debug-source.ts
Normal file
73
packages/core/utils/debug-source.ts
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// This file exists to break cycles between debug.ts and file-system.
|
||||||
|
// Only put logic here that depends on file-system (e.g., knownFolders).
|
||||||
|
import { knownFolders } from '../file-system';
|
||||||
|
|
||||||
|
let applicationRootPath: string;
|
||||||
|
function ensureAppRootPath() {
|
||||||
|
if (!applicationRootPath) {
|
||||||
|
applicationRootPath = knownFolders.currentApp().path;
|
||||||
|
applicationRootPath = applicationRootPath.substring(0, applicationRootPath.length - 'app/'.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Source {
|
||||||
|
private _uri: string;
|
||||||
|
private _line: number;
|
||||||
|
private _column: number;
|
||||||
|
|
||||||
|
private static _source = Symbol('source');
|
||||||
|
|
||||||
|
constructor(uri: string, line: number, column: number) {
|
||||||
|
ensureAppRootPath();
|
||||||
|
|
||||||
|
if (uri.length > applicationRootPath.length && uri.substring(0, applicationRootPath.length) === applicationRootPath) {
|
||||||
|
this._uri = 'file://' + uri.substring(applicationRootPath.length);
|
||||||
|
} else {
|
||||||
|
this._uri = uri;
|
||||||
|
}
|
||||||
|
this._line = line;
|
||||||
|
this._column = column;
|
||||||
|
}
|
||||||
|
|
||||||
|
get uri(): string {
|
||||||
|
return this._uri;
|
||||||
|
}
|
||||||
|
get line(): number {
|
||||||
|
return this._line;
|
||||||
|
}
|
||||||
|
get column(): number {
|
||||||
|
return this._column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public toString() {
|
||||||
|
return this._uri + ':' + this._line + ':' + this._column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static get(object: any): Source {
|
||||||
|
return object[Source._source];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static set(object: any, src: Source) {
|
||||||
|
object[Source._source] = src;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ScopeError extends Error {
|
||||||
|
constructor(inner: Error, message?: string) {
|
||||||
|
let formattedMessage;
|
||||||
|
if (message && inner.message) {
|
||||||
|
formattedMessage = message + '\n > ' + inner.message.replace('\n', '\n ');
|
||||||
|
} else {
|
||||||
|
formattedMessage = message || inner.message || undefined;
|
||||||
|
}
|
||||||
|
super(formattedMessage);
|
||||||
|
this.stack = __ANDROID__ ? 'Error: ' + this.message + '\n' + inner.stack.substr(inner.stack.indexOf('\n') + 1) : inner.stack;
|
||||||
|
this.message = formattedMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SourceError extends ScopeError {
|
||||||
|
constructor(child: Error, source: Source, message?: string) {
|
||||||
|
super(child, message ? message + ' @' + source + '' : source + '');
|
||||||
|
}
|
||||||
|
}
|
@ -1,73 +1,2 @@
|
|||||||
import { knownFolders } from '../file-system';
|
|
||||||
|
|
||||||
export const debug = true;
|
export const debug = true;
|
||||||
|
export { Source, ScopeError, SourceError } from './debug-source';
|
||||||
let applicationRootPath: string;
|
|
||||||
function ensureAppRootPath() {
|
|
||||||
if (!applicationRootPath) {
|
|
||||||
applicationRootPath = knownFolders.currentApp().path;
|
|
||||||
applicationRootPath = applicationRootPath.substring(0, applicationRootPath.length - 'app/'.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Source {
|
|
||||||
private _uri: string;
|
|
||||||
private _line: number;
|
|
||||||
private _column: number;
|
|
||||||
|
|
||||||
private static _source = Symbol('source');
|
|
||||||
|
|
||||||
constructor(uri: string, line: number, column: number) {
|
|
||||||
ensureAppRootPath();
|
|
||||||
|
|
||||||
if (uri.length > applicationRootPath.length && uri.substring(0, applicationRootPath.length) === applicationRootPath) {
|
|
||||||
this._uri = 'file://' + uri.substring(applicationRootPath.length);
|
|
||||||
} else {
|
|
||||||
this._uri = uri;
|
|
||||||
}
|
|
||||||
this._line = line;
|
|
||||||
this._column = column;
|
|
||||||
}
|
|
||||||
|
|
||||||
get uri(): string {
|
|
||||||
return this._uri;
|
|
||||||
}
|
|
||||||
get line(): number {
|
|
||||||
return this._line;
|
|
||||||
}
|
|
||||||
get column(): number {
|
|
||||||
return this._column;
|
|
||||||
}
|
|
||||||
|
|
||||||
public toString() {
|
|
||||||
return this._uri + ':' + this._line + ':' + this._column;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static get(object: any): Source {
|
|
||||||
return object[Source._source];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static set(object: any, src: Source) {
|
|
||||||
object[Source._source] = src;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ScopeError extends Error {
|
|
||||||
constructor(inner: Error, message?: string) {
|
|
||||||
let formattedMessage;
|
|
||||||
if (message && inner.message) {
|
|
||||||
formattedMessage = message + '\n > ' + inner.message.replace('\n', '\n ');
|
|
||||||
} else {
|
|
||||||
formattedMessage = message || inner.message || undefined;
|
|
||||||
}
|
|
||||||
super(formattedMessage);
|
|
||||||
this.stack = __ANDROID__ ? 'Error: ' + this.message + '\n' + inner.stack.substr(inner.stack.indexOf('\n') + 1) : inner.stack;
|
|
||||||
this.message = formattedMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SourceError extends ScopeError {
|
|
||||||
constructor(child: Error, source: Source, message?: string) {
|
|
||||||
super(child, message ? message + ' @' + source + '' : source + '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -8,7 +8,7 @@ export * from './debug';
|
|||||||
export * from './layout-helper';
|
export * from './layout-helper';
|
||||||
export * from './macrotask-scheduler';
|
export * from './macrotask-scheduler';
|
||||||
export * from './mainthread-helper';
|
export * from './mainthread-helper';
|
||||||
export * from './native-helper';
|
export * from './native-helper'; // do not re-export getWindow here, use ios-helper.ts for that
|
||||||
export * from './types';
|
export * from './types';
|
||||||
export * from './native-helper';
|
export * from './native-helper';
|
||||||
|
|
||||||
|
1
packages/core/utils/ios-helper.ts
Normal file
1
packages/core/utils/ios-helper.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { getWindow } from './native-helper';
|
@ -191,6 +191,10 @@ function getInputMethodManager(): android.view.inputmethod.InputMethodManager {
|
|||||||
return inputMethodManager;
|
return inputMethodManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getWindow() {
|
||||||
|
return getCurrentActivity()?.getWindow();
|
||||||
|
}
|
||||||
|
|
||||||
function showSoftInput(nativeView: android.view.View): void {
|
function showSoftInput(nativeView: android.view.View): void {
|
||||||
const inputManager = getInputMethodManager();
|
const inputManager = getInputMethodManager();
|
||||||
if (inputManager && nativeView instanceof android.view.View) {
|
if (inputManager && nativeView instanceof android.view.View) {
|
||||||
@ -315,6 +319,7 @@ export const androidUtils = {
|
|||||||
getApplication,
|
getApplication,
|
||||||
getCurrentActivity,
|
getCurrentActivity,
|
||||||
getApplicationContext,
|
getApplicationContext,
|
||||||
|
getWindow,
|
||||||
getResources,
|
getResources,
|
||||||
getPackageName,
|
getPackageName,
|
||||||
getInputMethodManager,
|
getInputMethodManager,
|
||||||
|
3
packages/core/utils/native-helper.d.ts
vendored
3
packages/core/utils/native-helper.d.ts
vendored
@ -14,6 +14,8 @@ export function dataDeserialize(nativeData?: any): any;
|
|||||||
*/
|
*/
|
||||||
export function isRealDevice(): boolean;
|
export function isRealDevice(): boolean;
|
||||||
|
|
||||||
|
export function getWindow(): UIWindow | android.view.Window;
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Module with android specific utilities.
|
// * Module with android specific utilities.
|
||||||
// */
|
// */
|
||||||
@ -228,6 +230,7 @@ export const android: {
|
|||||||
getApplication: () => android.app.Application;
|
getApplication: () => android.app.Application;
|
||||||
getCurrentActivity: () => androidx.appcompat.app.AppCompatActivity | android.app.Activity | null;
|
getCurrentActivity: () => androidx.appcompat.app.AppCompatActivity | android.app.Activity | null;
|
||||||
getApplicationContext: () => android.content.Context;
|
getApplicationContext: () => android.content.Context;
|
||||||
|
getWindow: () => android.view.Window;
|
||||||
getResources: () => android.content.res.Resources;
|
getResources: () => android.content.res.Resources;
|
||||||
getPackageName: () => string;
|
getPackageName: () => string;
|
||||||
getInputMethodManager: () => android.view.inputmethod.InputMethodManager;
|
getInputMethodManager: () => android.view.inputmethod.InputMethodManager;
|
||||||
|
@ -173,7 +173,7 @@ function getRootViewController(): UIViewController {
|
|||||||
return vc;
|
return vc;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWindow(): UIWindow {
|
export function getWindow(): UIWindow {
|
||||||
let window: UIWindow;
|
let window: UIWindow;
|
||||||
if (SDK_VERSION >= 15 && typeof NativeScriptViewFactory !== 'undefined') {
|
if (SDK_VERSION >= 15 && typeof NativeScriptViewFactory !== 'undefined') {
|
||||||
// UIWindowScene.keyWindow is only available 15+
|
// UIWindowScene.keyWindow is only available 15+
|
||||||
|
Reference in New Issue
Block a user