From 6bbd6804da01215b0a6a697b81c2b1c10970062e Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 27 Jul 2020 12:10:09 -0700 Subject: [PATCH] chore: cleanup --- apps/automated/tsconfig.tns.json | 7 - apps/playground/tsconfig.tns.json | 7 - apps/ui/tsconfig.tns.json | 7 - .../core/application/application-common.ts | 24 ++-- packages/core/application/index.android.ts | 6 - packages/core/connectivity/index.ios.ts | 1 + packages/core/file-system/index.ts | 3 +- packages/core/global-types.d.ts | 21 +++ packages/core/globals/index.ts | 7 +- packages/core/index.d.ts | 2 +- packages/core/index.ts | 2 +- packages/core/inspector_modules.ios.ts | 2 +- packages/core/platform/index.android.ts | 4 +- packages/core/platform/index.ios.ts | 4 +- packages/core/ui/content-view/index.ts | 3 +- packages/core/ui/core/view-base/index.ts | 13 +- packages/core/ui/dialogs/dialogs-common.ts | 7 +- packages/core/ui/frame/activity.android.ts | 124 +----------------- packages/core/ui/frame/fragment.android.ts | 65 --------- packages/core/ui/frame/frame-common.ts | 7 +- packages/core/ui/frame/index.android.ts | 56 +------- packages/core/ui/image/image-common.ts | 3 +- .../layouts/dock-layout/dock-layout-common.ts | 3 +- .../flexbox-layout/flexbox-layout-common.ts | 11 +- .../layouts/flexbox-layout/index.android.ts | 1 - .../stack-layout/stack-layout-common.ts | 3 +- .../layouts/wrap-layout/wrap-layout-common.ts | 7 +- packages/core/ui/page/page-common.ts | 5 +- .../core/ui/search-bar/search-bar-common.ts | 3 +- packages/core/ui/slider/slider-common.ts | 7 +- .../core/ui/styling/background.android.ts | 6 +- packages/core/ui/styling/style-properties.ts | 55 ++++---- packages/core/ui/styling/style-scope.ts | 8 +- .../tab-navigation-base/index.d.ts | 1 - .../tab-navigation-base/index.ts | 3 +- .../tab-strip-item/index.ts | 3 +- packages/core/ui/tab-view/tab-view-common.ts | 5 +- .../core/ui/text-base/text-base-common.ts | 9 +- packages/core/utils/debug.ts | 3 +- packages/webpack/projectFilesManager.js | 15 +-- packages/webpack/templates/tsconfig.tns.json | 7 - packages/webpack/templates/webpack.angular.js | 4 +- .../webpack/templates/webpack.javascript.js | 2 + .../webpack/templates/webpack.typescript.js | 4 +- packages/webpack/templates/webpack.vue.js | 2 + 45 files changed, 145 insertions(+), 397 deletions(-) delete mode 100644 apps/automated/tsconfig.tns.json delete mode 100644 apps/playground/tsconfig.tns.json delete mode 100644 apps/ui/tsconfig.tns.json delete mode 100644 packages/webpack/templates/tsconfig.tns.json diff --git a/apps/automated/tsconfig.tns.json b/apps/automated/tsconfig.tns.json deleted file mode 100644 index a96f6bbc6..000000000 --- a/apps/automated/tsconfig.tns.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "module": "ESNext", - "moduleResolution": "node" - } -} diff --git a/apps/playground/tsconfig.tns.json b/apps/playground/tsconfig.tns.json deleted file mode 100644 index fafd21554..000000000 --- a/apps/playground/tsconfig.tns.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "module": "esnext", - "moduleResolution": "node" - } -} diff --git a/apps/ui/tsconfig.tns.json b/apps/ui/tsconfig.tns.json deleted file mode 100644 index 6e64d1da8..000000000 --- a/apps/ui/tsconfig.tns.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "module": "esnext", - "moduleResolution": "node" - } -} diff --git a/packages/core/application/application-common.ts b/packages/core/application/application-common.ts index c05bb38d1..2a083eb32 100644 --- a/packages/core/application/application-common.ts +++ b/packages/core/application/application-common.ts @@ -1,6 +1,6 @@ // Require globals first so that snapshot takes __extends function. const nsGlobals = require('../globals'); -if (!(global).hasInitGlobal) { +if (!global.NativeScriptHasInitGlobal) { nsGlobals.initGlobal(); } @@ -19,7 +19,7 @@ import { Enums } from '../ui/enums'; export * from './application-interfaces'; export function hasLaunched(): boolean { - return (global).NativeScriptGlobals && (global).NativeScriptGlobals.launched; + return global.NativeScriptGlobals && global.NativeScriptGlobals.launched; } export const launchEvent = 'launch'; @@ -50,20 +50,20 @@ export function setResources(res: any) { export let android: AndroidApplication = undefined; export let ios: iOSApplication = undefined; -export const on = (global).NativeScriptGlobals.events.on.bind((global).NativeScriptGlobals.events); -export const off = (global).NativeScriptGlobals.events.off.bind((global).NativeScriptGlobals.events); -export const notify = (global).NativeScriptGlobals.events.notify.bind((global).NativeScriptGlobals.events); -export const hasListeners = (global).NativeScriptGlobals.events.hasListeners.bind((global).NativeScriptGlobals.events); +export const on = global.NativeScriptGlobals.events.on.bind(global.NativeScriptGlobals.events); +export const off = global.NativeScriptGlobals.events.off.bind(global.NativeScriptGlobals.events); +export const notify = global.NativeScriptGlobals.events.notify.bind(global.NativeScriptGlobals.events); +export const hasListeners = global.NativeScriptGlobals.events.hasListeners.bind(global.NativeScriptGlobals.events); let app: iOSApplication | AndroidApplication; export function setApplication(instance: iOSApplication | AndroidApplication): void { app = instance; // signal when the application instance is ready globally - (global).NativeScriptGlobals.appInstanceReady = true; + global.NativeScriptGlobals.appInstanceReady = true; } export function livesync(rootView: View, context?: ModuleContext) { - (global).NativeScriptGlobals.events.notify({ eventName: 'livesync', object: app }); + global.NativeScriptGlobals.events.notify({ eventName: 'livesync', object: app }); const liveSyncCore = global.__onLiveSyncCore; let reapplyAppStyles = false; @@ -85,7 +85,7 @@ export function livesync(rootView: View, context?: ModuleContext) { export function setCssFileName(cssFileName: string) { cssFile = cssFileName; - (global).NativeScriptGlobals.events.notify({ + global.NativeScriptGlobals.events.notify({ eventName: 'cssChanged', object: app, cssFile: cssFileName, @@ -98,7 +98,7 @@ export function getCssFileName(): string { export function loadAppCss(): void { try { - (global).NativeScriptGlobals.events.notify({ + global.NativeScriptGlobals.events.notify({ eventName: 'loadAppCss', object: app, cssFile: getCssFileName(), @@ -164,7 +164,7 @@ export function systemAppearanceChanged(rootView: View, newSystemAppearance: 'da } global.__onUncaughtError = function (error: NativeScriptError) { - (global).NativeScriptGlobals.events.notify({ + global.NativeScriptGlobals.events.notify({ eventName: uncaughtErrorEvent, object: app, android: error, @@ -174,7 +174,7 @@ global.__onUncaughtError = function (error: NativeScriptError) { }; global.__onDiscardedError = function (error: NativeScriptError) { - (global).NativeScriptGlobals.events.notify({ + global.NativeScriptGlobals.events.notify({ eventName: discardedErrorEvent, object: app, error: error, diff --git a/packages/core/application/index.android.ts b/packages/core/application/index.android.ts index cbef14c4c..15bd26ce6 100644 --- a/packages/core/application/index.android.ts +++ b/packages/core/application/index.android.ts @@ -61,12 +61,8 @@ export class AndroidApplication extends Observable implements AndroidApplication this.nativeApp = nativeApp; this.packageName = nativeApp.getPackageName(); this.context = nativeApp.getApplicationContext(); - console.log('this.nativeApp:', this.nativeApp); - console.log('this.packageName:', this.packageName); - console.log('this.context:', this.context); // we store those callbacks and add a function for clearing them later so that the objects will be eligable for GC this.callbacks.lifecycleCallbacks = initLifecycleCallbacks(); - console.log('this.callbacks.lifecycleCallbacks:', this.callbacks.lifecycleCallbacks); this.callbacks.componentCallbacks = initComponentCallbacks(); this.nativeApp.registerActivityLifecycleCallbacks(this.callbacks.lifecycleCallbacks); this.nativeApp.registerComponentCallbacks(this.callbacks.componentCallbacks); @@ -170,8 +166,6 @@ export function run(entry?: NavigationEntry | string) { started = true; mainEntry = typeof entry === 'string' ? { moduleName: entry } : entry; - console.log('run mainEntry:', mainEntry); - console.log('androidApp.nativeApp:', androidApp.nativeApp); if (!androidApp.nativeApp) { const nativeApp = getNativeApplication(); androidApp.init(nativeApp); diff --git a/packages/core/connectivity/index.ios.ts b/packages/core/connectivity/index.ios.ts index 2ba654b84..7f03acdc7 100644 --- a/packages/core/connectivity/index.ios.ts +++ b/packages/core/connectivity/index.ios.ts @@ -58,6 +58,7 @@ function _getConnectionTypeFromFlags(flags: number): number { let keys: any; if (typeof CFNetworkCopySystemProxySettings !== 'undefined') { const cfDict = CFNetworkCopySystemProxySettings(); + // Only works on iOS device so guarded to help Simulator testing if (cfDict && cfDict.takeUnretainedValue) { const nsDict = cfDict.takeUnretainedValue(); keys = nsDict.objectForKey('__SCOPED__'); diff --git a/packages/core/file-system/index.ts b/packages/core/file-system/index.ts index fdcd69a10..f83e335aa 100644 --- a/packages/core/file-system/index.ts +++ b/packages/core/file-system/index.ts @@ -1,5 +1,4 @@ import { FileSystemAccess } from './file-system-access'; -import { isIOS } from '../platform'; // The FileSystemAccess implementation, used through all the APIs. let fileAccess: FileSystemAccess; @@ -572,7 +571,7 @@ export module knownFolders { export module ios { function _checkPlatform(knownFolderName: string) { - if (!isIOS) { + if (!global.isIOS) { console.log(`The "${knownFolderName}" known folder is available on iOS only!`); } } diff --git a/packages/core/global-types.d.ts b/packages/core/global-types.d.ts index d574728ca..3e0c01d5e 100644 --- a/packages/core/global-types.d.ts +++ b/packages/core/global-types.d.ts @@ -21,6 +21,24 @@ declare interface NativeScriptError extends Error { //Augment the NodeJS global type with our own extensions declare namespace NodeJS { interface Global { + NativeScriptHasInitGlobal?: boolean; + NativeScriptGlobals?: { + /** + * Global framework event handling + */ + events: Observable; + launched: boolean; + // used by various classes to setup callbacks to wire up global app event handling when the app instance is ready + appEventWiring: Array; + // determines if the app instance is ready upon bootstrap + appInstanceReady: boolean; + + /** + * Ability for classes to initialize app event handling early even before the app instance is ready during boot cycle avoiding boot race conditions + * @param callback wire up any global event handling inside the callback + */ + addEventWiring(callback: () => void): void; + }; android?: any; require(id: string): any; @@ -91,6 +109,9 @@ declare namespace NodeJS { __onUncaughtError: (error: NativeScriptError) => void; __onDiscardedError: (error: NativeScriptError) => void; __snapshot?: boolean; + TNS_WEBPACK?: boolean; + isIOS?: boolean; + isAndroid?: boolean; __requireOverride?: (name: string, dir: string) => any; } } diff --git a/packages/core/globals/index.ts b/packages/core/globals/index.ts index f16ce591d..9ccbf5fba 100644 --- a/packages/core/globals/index.ts +++ b/packages/core/globals/index.ts @@ -1,6 +1,5 @@ import * as tslibType from 'tslib'; const tslib: typeof tslibType = require('tslib'); -import { isIOS, isAndroid } from '../platform'; import { Observable } from '../data/observable'; import { trace as profilingTrace, time, uptime, level as profilingLevel } from '../profiling'; @@ -109,10 +108,10 @@ export function installPolyfills(moduleName: string, exportNames: string[]) { } export function initGlobal() { - if (!(global).hasInitGlobal) { - (global).hasInitGlobal = true; + if (!global.NativeScriptHasInitGlobal) { + global.NativeScriptHasInitGlobal = true; // init global state handler - (global).NativeScriptGlobals = new NativeScriptGlobalState(); + global.NativeScriptGlobals = new NativeScriptGlobalState(); // ts-helpers // Required by V8 snapshot generator diff --git a/packages/core/index.d.ts b/packages/core/index.d.ts index 02238aeeb..c456cbb50 100644 --- a/packages/core/index.d.ts +++ b/packages/core/index.d.ts @@ -68,7 +68,7 @@ export declare const Http: { export { ImageAsset, ImageAssetOptions } from './image-asset'; export { ImageSource } from './image-source'; export { ModuleNameResolver, ModuleListProvider, PlatformContext, _setResolver } from './module-name-resolver'; -export { isAndroid, isIOS, Screen, IDevice, Device, platformNames } from './platform'; +export { Screen, IDevice, Device, platformNames } from './platform'; // Profiling export { InstrumentationMode, TimerInfo, profile, enable as profilingEnable, disable as profilingDisable, time as profilingTime, uptime as profilingUptime, start as profilingStart, stop as profilingStop, isRunning as profilingIsRunning, dumpProfiles as profilingDumpProfiles, resetProfiles as profilingResetProfiles, startCPUProfile as profilingStartCPU, stopCPUProfile as profilingStopCPU } from './profiling'; export { encoding } from './text'; diff --git a/packages/core/index.ts b/packages/core/index.ts index 4289d38f5..c21c6a2ae 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -89,7 +89,7 @@ export { ImageAsset, ImageAssetOptions } from './image-asset'; export { ImageSource } from './image-source'; export { ModuleNameResolver, ModuleListProvider, PlatformContext, _setResolver } from './module-name-resolver'; -export { isAndroid, isIOS, Screen, IDevice, Device, platformNames } from './platform'; +export { Screen, IDevice, Device, platformNames } from './platform'; // Profiling export { InstrumentationMode, TimerInfo, profile, enable as profilingEnable, disable as profilingDisable, time as profilingTime, uptime as profilingUptime, start as profilingStart, stop as profilingStop, isRunning as profilingIsRunning, dumpProfiles as profilingDumpProfiles, resetProfiles as profilingResetProfiles, startCPUProfile as profilingStartCPU, stopCPUProfile as profilingStopCPU } from './profiling'; diff --git a/packages/core/inspector_modules.ios.ts b/packages/core/inspector_modules.ios.ts index 3bc8d65f9..103692323 100644 --- a/packages/core/inspector_modules.ios.ts +++ b/packages/core/inspector_modules.ios.ts @@ -1,6 +1,6 @@ console.log('Loading inspector modules...'); import { initGlobal } from './globals'; -if (!(global).hasInitGlobal) { +if (global.NativeScriptHasInitGlobal) { initGlobal(); } require('./debugger/webinspector-network'); diff --git a/packages/core/platform/index.android.ts b/packages/core/platform/index.android.ts index 27d733f5b..f414bf909 100644 --- a/packages/core/platform/index.android.ts +++ b/packages/core/platform/index.android.ts @@ -145,5 +145,5 @@ class DeviceRef { export const Device = new DeviceRef(); -export const isAndroid = true; -export const isIOS = false; +export const isAndroid = global.isAndroid; +export const isIOS = global.isIOS; diff --git a/packages/core/platform/index.ios.ts b/packages/core/platform/index.ios.ts index ba7c91697..ef1de6bc1 100644 --- a/packages/core/platform/index.ios.ts +++ b/packages/core/platform/index.ios.ts @@ -123,5 +123,5 @@ export class Screen { static mainScreen = new MainScreen(); } -export const isIOS = true; -export const isAndroid = false; +export const isAndroid = global.isAndroid; +export const isIOS = global.isIOS; diff --git a/packages/core/ui/content-view/index.ts b/packages/core/ui/content-view/index.ts index 55a1e78e1..925c2d5b6 100644 --- a/packages/core/ui/content-view/index.ts +++ b/packages/core/ui/content-view/index.ts @@ -1,6 +1,5 @@ import { View, CustomLayoutView, AddChildFromBuilder } from '../core/view'; import { layout } from '../../utils'; -import { isIOS } from '../../platform'; /** * Represents a View that has a single child - content. @@ -28,7 +27,7 @@ export class ContentView extends CustomLayoutView implements AddChildFromBuilder } this._onContentChanged(oldView, value); - if (isIOS && oldView !== value) { + if (global.isIOS && oldView !== value) { this.requestLayout(); } } diff --git a/packages/core/ui/core/view-base/index.ts b/packages/core/ui/core/view-base/index.ts index b9abed739..dd7e6031a 100644 --- a/packages/core/ui/core/view-base/index.ts +++ b/packages/core/ui/core/view-base/index.ts @@ -10,7 +10,6 @@ import { Binding, BindingOptions } from '../bindable'; import { Trace } from '../../../trace'; import { Observable, PropertyChangeData, WrappedValue } from '../../../data/observable'; import { Style } from '../../styling/style'; -import { isAndroid } from '../../../platform'; import { Length, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty } from '../../styling/style-properties'; // TODO: Remove this import! @@ -736,7 +735,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition private resetNativeViewInternal(): void { // const nativeView = this.nativeViewProtected; - // if (nativeView && isAndroid) { + // if (nativeView && global.isAndroid) { // const recycle = this.recycleNativeView; // if (recycle === "always" || (recycle === "auto" && !this._disableNativeViewRecycling)) { // resetNativeView(this); @@ -771,7 +770,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition // or for backward compatability - set before _setupUI in iOS contructor. let nativeView = this.nativeViewProtected; - // if (isAndroid) { + // if (global.isAndroid) { // const recycle = this.recycleNativeView; // if (recycle === "always" || (recycle === "auto" && !this._disableNativeViewRecycling)) { // nativeView = getNativeView(context, this.typeName); @@ -781,7 +780,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition nativeView = this.createNativeView(); } - if (isAndroid) { + if (global.isAndroid) { this._androidView = nativeView; if (nativeView) { if (this._isPaddingRelative === undefined) { @@ -871,7 +870,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition } // const nativeView = this.nativeViewProtected; - // if (nativeView && isAndroid) { + // if (nativeView && global.isAndroid) { // const recycle = this.recycleNativeView; // let shouldRecycle = false; // if (recycle === "always") { @@ -881,7 +880,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition // shouldRecycle = propertiesSet <= this.recyclePropertyCounter; // } - // // const nativeParent = isAndroid ? (nativeView).getParent() : (nativeView).superview; + // // const nativeParent = global.isAndroid ? (nativeView).getParent() : (nativeView).superview; // const nativeParent = (nativeView).getParent(); // const animation = (nativeView).getAnimation(); // if (shouldRecycle && !nativeParent && !animation) { @@ -893,7 +892,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition this._suspendNativeUpdates(SuspendType.UISetup); - if (isAndroid) { + if (global.isAndroid) { this.setNativeView(null); this._androidView = null; } diff --git a/packages/core/ui/dialogs/dialogs-common.ts b/packages/core/ui/dialogs/dialogs-common.ts index 2b90d2826..293ee015b 100644 --- a/packages/core/ui/dialogs/dialogs-common.ts +++ b/packages/core/ui/dialogs/dialogs-common.ts @@ -2,7 +2,6 @@ import { View } from '../core/view'; import { Color } from '../../color'; import { Page } from '../page'; -import { isIOS } from '../../platform'; import { Frame } from '../frame'; import { isObject, isString } from '../../utils/types'; @@ -266,7 +265,7 @@ export function getButtonColors(): { color: Color; backgroundColor: Color } { if (!button) { const Button = require('../button').Button; button = new Button(); - if (isIOS) { + if (global.isIOS) { button._setupUI({}); } } @@ -285,7 +284,7 @@ export function getLabelColor(): Color { if (!label) { const Label = require('../label').Label; label = new Label(); - if (isIOS) { + if (global.isIOS) { label._setupUI({}); } } @@ -302,7 +301,7 @@ export function getTextFieldColor(): Color { if (!textField) { const TextField = require('../text-field').TextField; textField = new TextField(); - if (isIOS) { + if (global.isIOS) { textField._setupUI({}); } } diff --git a/packages/core/ui/frame/activity.android.ts b/packages/core/ui/frame/activity.android.ts index bf211d3f6..746ec118c 100644 --- a/packages/core/ui/frame/activity.android.ts +++ b/packages/core/ui/frame/activity.android.ts @@ -6,64 +6,15 @@ const appModule = require('../../application'); if (global.__snapshot) { globals.initGlobal(); } -/** - * Option 1: the exact es5 compiled version of what this normally looks like - */ -// var NativeScriptActivity = (function (_super) { -// __extends(NativeScriptActivity, _super); -// function NativeScriptActivity() { -// console.log('construct NativeScriptActivity'); -// var _this = _super.call(this) || this; -// return global.__native(_this); -// } -// NativeScriptActivity.prototype.init = function () { -// // return new NativeScriptActivity(); -// }; -// NativeScriptActivity.prototype.onCreate = function (savedInstanceState) { -// appModule.android.init(this.getApplication()); -// this.isNativeScriptActivity = true; -// if (!this._callbacks) { -// setActivityCallbacks(this); -// } -// this._callbacks.onCreate(this, savedInstanceState, this.getIntent(), _super.prototype.onCreate); -// }; -// NativeScriptActivity.prototype.onNewIntent = function (intent) { -// this._callbacks.onNewIntent(this, intent, _super.prototype.setIntent, _super.prototype.onNewIntent); -// }; -// NativeScriptActivity.prototype.onSaveInstanceState = function (outState) { -// this._callbacks.onSaveInstanceState(this, outState, _super.prototype.onSaveInstanceState); -// }; -// NativeScriptActivity.prototype.onStart = function () { -// this._callbacks.onStart(this, _super.prototype.onStart); -// }; -// NativeScriptActivity.prototype.onStop = function () { -// this._callbacks.onStop(this, _super.prototype.onStop); -// }; -// NativeScriptActivity.prototype.onDestroy = function () { -// this._callbacks.onDestroy(this, _super.prototype.onDestroy); -// }; -// NativeScriptActivity.prototype.onPostResume = function () { -// this._callbacks.onPostResume(this, _super.prototype.onPostResume); -// }; -// NativeScriptActivity.prototype.onBackPressed = function () { -// this._callbacks.onBackPressed(this, _super.prototype.onBackPressed); -// }; -// NativeScriptActivity.prototype.onRequestPermissionsResult = function (requestCode, permissions, grantResults) { -// this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined); -// }; -// NativeScriptActivity.prototype.onActivityResult = function (requestCode, resultCode, data) { -// this._callbacks.onActivityResult(this, requestCode, resultCode, data, _super.prototype.onActivityResult); -// }; -// NativeScriptActivity = __decorate([JavaProxy('com.tns.NativeScriptActivity')], NativeScriptActivity); -// return NativeScriptActivity; -// })(androidx.appcompat.app.AppCompatActivity); -// Option 2: the manual es5 way - results in same as above +/** + * NOTE: We cannot use NativeClass here because this is used in appComponents in webpack.config + * Whereby it bypasses the decorator transformation, hence pure es5 style written here + */ const superProto = androidx.appcompat.app.AppCompatActivity.prototype; -const NativeScriptActivity = (androidx.appcompat.app.AppCompatActivity).extend('com.tns.NativeScriptActivity', { +(androidx.appcompat.app.AppCompatActivity).extend('com.tns.NativeScriptActivity', { init() { - // superProto(); - // return global.__native(this); + // init must at least be defined }, onCreate(savedInstanceState: android.os.Bundle): void { appModule.android.init(this.getApplication()); @@ -114,66 +65,3 @@ const NativeScriptActivity = (androidx.appcompat.app.AppCompatActivity).ext this._callbacks.onActivityResult(this, requestCode, resultCode, data, superProto.onActivityResult); }, }); - -/** - * Option 3: The way which worked when using es5 compile target however when targeting es2017, this source code won't work due to the extends from native class so trying options 1 and 2 to achieve same - */ -// @JavaProxy('com.tns.NativeScriptActivity') -// class NativeScriptActivity extends androidx.appcompat.app.AppCompatActivity { -// private _callbacks: AndroidActivityCallbacks; -// public isNativeScriptActivity; -// constructor() { -// super(); - -// return global.__native(this); -// } - -// public onCreate(savedInstanceState: android.os.Bundle): void { -// appModule.android.init(this.getApplication()); - -// // Set isNativeScriptActivity in onCreate. -// // The JS constructor might not be called because the activity is created from Android. -// this.isNativeScriptActivity = true; -// if (!this._callbacks) { -// setActivityCallbacks(this); -// } - -// this._callbacks.onCreate(this, savedInstanceState, this.getIntent(), super.onCreate); -// } - -// public onNewIntent(intent: android.content.Intent): void { -// this._callbacks.onNewIntent(this, intent, super.setIntent, super.onNewIntent); -// } - -// public onSaveInstanceState(outState: android.os.Bundle): void { -// this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState); -// } - -// public onStart(): void { -// this._callbacks.onStart(this, super.onStart); -// } - -// public onStop(): void { -// this._callbacks.onStop(this, super.onStop); -// } - -// public onDestroy(): void { -// this._callbacks.onDestroy(this, super.onDestroy); -// } - -// public onPostResume(): void { -// this._callbacks.onPostResume(this, super.onPostResume); -// } - -// public onBackPressed(): void { -// this._callbacks.onBackPressed(this, super.onBackPressed); -// } - -// public onRequestPermissionsResult(requestCode: number, permissions: Array, grantResults: Array): void { -// this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/); -// } - -// public onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void { -// this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult); -// } -// } diff --git a/packages/core/ui/frame/fragment.android.ts b/packages/core/ui/frame/fragment.android.ts index 652f31b7a..a1bea72e9 100644 --- a/packages/core/ui/frame/fragment.android.ts +++ b/packages/core/ui/frame/fragment.android.ts @@ -56,69 +56,4 @@ const FragmentClass = (org.nativescript.widgets.FragmentBase).extend('com.t }, }); -// @NativeClass -// @JavaProxy('com.tns.FragmentClass') -// class FragmentClass extends org.nativescript.widgets.FragmentBase { -// // This field is updated in the frame module upon `new` (although hacky this eases the Fragment->callbacks association a lot) -// private _callbacks: AndroidFragmentCallbacks; - -// constructor() { -// super(); - -// return global.__native(this); -// } - -// public onHiddenChanged(hidden: boolean): void { -// this._callbacks.onHiddenChanged(this, hidden, super.onHiddenChanged); -// } - -// public onCreateAnimator(transit: number, enter: boolean, nextAnim: number): android.animation.Animator { -// return this._callbacks.onCreateAnimator(this, transit, enter, nextAnim, super.onCreateAnimator); -// } - -// public onStop(): void { -// this._callbacks.onStop(this, super.onStop); -// } - -// public onPause(): void { -// this._callbacks.onPause(this, super.onStop); -// } - -// public onCreate(savedInstanceState: android.os.Bundle) { -// if (!this._callbacks) { -// setFragmentCallbacks(this); -// } - -// this.setHasOptionsMenu(true); -// this._callbacks.onCreate(this, savedInstanceState, super.onCreate); -// } - -// public onCreateView(inflater: android.view.LayoutInflater, container: android.view.ViewGroup, savedInstanceState: android.os.Bundle) { -// let result = this._callbacks.onCreateView(this, inflater, container, savedInstanceState, super.onCreateView); - -// return result; -// } - -// public onSaveInstanceState(outState: android.os.Bundle) { -// this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState); -// } - -// public onDestroyView() { -// this._callbacks.onDestroyView(this, super.onDestroyView); -// } - -// public onDestroy() { -// this._callbacks.onDestroy(this, super.onDestroy); -// } - -// public toString(): string { -// const callbacks = this._callbacks; -// if (callbacks) { -// return callbacks.toStringOverride(this, super.toString); -// } else { -// super.toString(); -// } -// } -// } - setFragmentClass(FragmentClass); diff --git a/packages/core/ui/frame/frame-common.ts b/packages/core/ui/frame/frame-common.ts index bc045c6d5..1ca5cdf19 100644 --- a/packages/core/ui/frame/frame-common.ts +++ b/packages/core/ui/frame/frame-common.ts @@ -3,7 +3,6 @@ import { BackstackEntry, NavigationContext, NavigationEntry, NavigationTransitio import { Page } from '../page'; import { View, CustomLayoutView, CSSType } from '../core/view'; import { Property } from '../core/properties'; -import { isIOS, isAndroid } from '../../platform'; import { Trace } from '../../trace'; // Requires. @@ -525,11 +524,11 @@ export class FrameBase extends CustomLayoutView { public _getNavigationTransition(entry: NavigationEntry): NavigationTransition { if (entry) { - if (isIOS && entry.transitioniOS !== undefined) { + if (global.isIOS && entry.transitioniOS !== undefined) { return entry.transitioniOS; } - if (isAndroid && entry.transitionAndroid !== undefined) { + if (global.isAndroid && entry.transitionAndroid !== undefined) { return entry.transitionAndroid; } @@ -721,5 +720,5 @@ export const defaultPage = new Property({ }); defaultPage.register(FrameBase); -export const actionBarVisibilityProperty = new Property({ name: 'actionBarVisibility', defaultValue: 'auto', affectsLayout: isIOS }); +export const actionBarVisibilityProperty = new Property({ name: 'actionBarVisibility', defaultValue: 'auto', affectsLayout: global.isIOS }); actionBarVisibilityProperty.register(FrameBase); diff --git a/packages/core/ui/frame/index.android.ts b/packages/core/ui/frame/index.android.ts index b41b7827b..b9dc51db7 100644 --- a/packages/core/ui/frame/index.android.ts +++ b/packages/core/ui/frame/index.android.ts @@ -48,40 +48,18 @@ export let attachStateChangeListener: android.view.View.OnAttachStateChangeListe function getAttachListener(): android.view.View.OnAttachStateChangeListener { if (!attachStateChangeListener) { - // var AttachListener = (function (_super) { - // __extends(AttachListener, _super); - // function AttachListener() { - // var _this = _super.call(this) || this; - // return global.__native(_this); - // } - // AttachListener.prototype.onViewAttachedToWindow = function (view) { - // var owner = view[ownerSymbol]; - // if (owner) { - // owner._onAttachedToWindow(); - // } - // }; - // AttachListener.prototype.onViewDetachedFromWindow = function (view) { - // var owner = view[ownerSymbol]; - // if (owner) { - // owner._onDetachedFromWindow(); - // } - // }; - // AttachListener = __decorate([Interfaces([android.view.View.OnAttachStateChangeListener])], AttachListener); - // return AttachListener; - // })(java.lang.Object); - + /** + * NOTE: We cannot use NativeClass here because this is used in appComponents in webpack.config + * Whereby it bypasses the decorator transformation, hence pure es5 style written here + */ const AttachListener = (java.lang.Object).extend({ interfaces: [android.view.View.OnAttachStateChangeListener], init() { - // this.super(this); - // return global.__native(this); + // init must be defined at least }, onViewAttachedToWindow(view: android.view.View): void { - console.log('onViewAttachedToWindow'); const owner: View = view[ownerSymbol]; - console.log('owner:', owner); if (owner) { - // console.log('owner._onAttachedToWindow:', owner._onAttachedToWindow) owner._onAttachedToWindow(); } }, @@ -92,30 +70,8 @@ function getAttachListener(): android.view.View.OnAttachStateChangeListener { } }, }); - // class AttachListener extends java.lang.Object implements android.view.View.OnAttachStateChangeListener { - // constructor() { - // super(); - - // return global.__native(this); - // } - - // onViewAttachedToWindow(view: android.view.View): void { - // const owner: View = view[ownerSymbol]; - // if (owner) { - // owner._onAttachedToWindow(); - // } - // } - - // onViewDetachedFromWindow(view: android.view.View): void { - // const owner: View = view[ownerSymbol]; - // if (owner) { - // owner._onDetachedFromWindow(); - // } - // } - // } attachStateChangeListener = new AttachListener(); - console.log('attachStateChangeListener:', attachStateChangeListener); } return attachStateChangeListener; @@ -531,8 +487,6 @@ export class Frame extends FrameBase { public initNativeView(): void { super.initNativeView(); const listener = getAttachListener(); - console.log('listener:', listener); - console.log(' this.nativeViewProtected:', this.nativeViewProtected); this.nativeViewProtected.addOnAttachStateChangeListener(listener); this.nativeViewProtected[ownerSymbol] = this; this._android.rootViewGroup = this.nativeViewProtected; diff --git a/packages/core/ui/image/image-common.ts b/packages/core/ui/image/image-common.ts index f7d959655..c21242734 100644 --- a/packages/core/ui/image/image-common.ts +++ b/packages/core/ui/image/image-common.ts @@ -5,7 +5,6 @@ import { ImageAsset } from '../../image-asset'; import { ImageSource } from '../../image-source'; import { isDataURI, isFontIconURI, isFileOrResourcePath, RESOURCE_PREFIX } from '../../utils'; import { Color } from '../../color'; -import { isIOS } from '../../platform'; import { Style } from '../styling/style'; import { Length } from '../styling/style-properties'; import { Property, InheritedCssProperty } from '../core/properties'; @@ -147,7 +146,7 @@ isLoadingProperty.register(ImageBase); export const stretchProperty = new Property({ name: 'stretch', defaultValue: 'aspectFit', - affectsLayout: isIOS, + affectsLayout: global.isIOS, }); stretchProperty.register(ImageBase); diff --git a/packages/core/ui/layouts/dock-layout/dock-layout-common.ts b/packages/core/ui/layouts/dock-layout/dock-layout-common.ts index cd2aaf682..c8ccb09d0 100644 --- a/packages/core/ui/layouts/dock-layout/dock-layout-common.ts +++ b/packages/core/ui/layouts/dock-layout/dock-layout-common.ts @@ -3,7 +3,6 @@ import { LayoutBase } from '../layout-base'; import { View, CSSType } from '../../core/view'; import { Property, makeValidator, makeParser } from '../../core/properties'; import { booleanConverter } from '../../core/view-base'; -import { isIOS } from '../../../platform'; function validateArgs(element: View): View { if (!element) { @@ -53,7 +52,7 @@ dockProperty.register(View); export const stretchLastChildProperty = new Property({ name: 'stretchLastChild', defaultValue: true, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: booleanConverter, }); stretchLastChildProperty.register(DockLayoutBase); diff --git a/packages/core/ui/layouts/flexbox-layout/flexbox-layout-common.ts b/packages/core/ui/layouts/flexbox-layout/flexbox-layout-common.ts index 272569e64..23dd97473 100644 --- a/packages/core/ui/layouts/flexbox-layout/flexbox-layout-common.ts +++ b/packages/core/ui/layouts/flexbox-layout/flexbox-layout-common.ts @@ -2,7 +2,6 @@ import { LayoutBase } from '../layout-base'; import { View, CSSType } from '../../core/view'; import { CssProperty, ShorthandProperty, makeParser, makeValidator, unsetValue } from '../../core/properties'; import { Style } from '../../styling/style'; -import { isIOS } from '../../../platform'; export type Basis = 'auto' | number; @@ -223,7 +222,7 @@ export const flexDirectionProperty = new CssProperty({ name: 'flexDirection', cssName: 'flex-direction', defaultValue: FlexDirection.ROW, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: FlexDirection.parse, }); flexDirectionProperty.register(Style); @@ -232,7 +231,7 @@ export const flexWrapProperty = new CssProperty({ name: 'flexWrap', cssName: 'flex-wrap', defaultValue: 'nowrap', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: FlexWrap.parse, }); flexWrapProperty.register(Style); @@ -241,7 +240,7 @@ export const justifyContentProperty = new CssProperty({ name: 'justifyContent', cssName: 'justify-content', defaultValue: JustifyContent.FLEX_START, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: JustifyContent.parse, }); justifyContentProperty.register(Style); @@ -250,7 +249,7 @@ export const alignItemsProperty = new CssProperty({ name: 'alignItems', cssName: 'align-items', defaultValue: AlignItems.STRETCH, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: AlignItems.parse, }); alignItemsProperty.register(Style); @@ -259,7 +258,7 @@ export const alignContentProperty = new CssProperty({ name: 'alignContent', cssName: 'align-content', defaultValue: AlignContent.STRETCH, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: AlignContent.parse, }); alignContentProperty.register(Style); diff --git a/packages/core/ui/layouts/flexbox-layout/index.android.ts b/packages/core/ui/layouts/flexbox-layout/index.android.ts index ccc2cb578..38484e8b2 100644 --- a/packages/core/ui/layouts/flexbox-layout/index.android.ts +++ b/packages/core/ui/layouts/flexbox-layout/index.android.ts @@ -1,7 +1,6 @@ import { FlexDirection, FlexWrap, JustifyContent, AlignItems, AlignContent, FlexboxLayoutBase, orderProperty, Order, flexGrowProperty, FlexGrow, flexShrinkProperty, FlexShrink, flexWrapBeforeProperty, FlexWrapBefore, alignSelfProperty, AlignSelf, flexDirectionProperty, flexWrapProperty, justifyContentProperty, alignItemsProperty, alignContentProperty } from './flexbox-layout-common'; import { View } from '../../core/view'; import { Length, minHeightProperty, minWidthProperty } from '../../styling/style-properties'; -import { isIOS } from '../../../platform'; export * from './flexbox-layout-common'; diff --git a/packages/core/ui/layouts/stack-layout/stack-layout-common.ts b/packages/core/ui/layouts/stack-layout/stack-layout-common.ts index e60ea593c..6135fa1f8 100644 --- a/packages/core/ui/layouts/stack-layout/stack-layout-common.ts +++ b/packages/core/ui/layouts/stack-layout/stack-layout-common.ts @@ -2,7 +2,6 @@ import { LayoutBase } from '../layout-base'; import { CSSType } from '../../core/view'; import { Property, makeParser, makeValidator } from '../../core/properties'; -import { isIOS } from '../../../platform'; @CSSType('StackLayout') export class StackLayoutBase extends LayoutBase implements StackLayoutDefinition { @@ -16,7 +15,7 @@ const converter = makeParser(makeValidator('horizontal', 'vertical' export const orientationProperty = new Property({ name: 'orientation', defaultValue: 'vertical', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: converter, }); orientationProperty.register(StackLayoutBase); diff --git a/packages/core/ui/layouts/wrap-layout/wrap-layout-common.ts b/packages/core/ui/layouts/wrap-layout/wrap-layout-common.ts index f42c9333f..85c9055db 100644 --- a/packages/core/ui/layouts/wrap-layout/wrap-layout-common.ts +++ b/packages/core/ui/layouts/wrap-layout/wrap-layout-common.ts @@ -3,7 +3,6 @@ import { LayoutBase } from '../layout-base'; import { CSSType } from '../../core/view'; import { Property, makeValidator, makeParser } from '../../core/properties'; import { Length } from '../../styling/style-properties'; -import { isIOS } from '../../../platform'; export * from '../layout-base'; @@ -21,7 +20,7 @@ WrapLayoutBase.prototype.recycleNativeView = 'auto'; export const itemWidthProperty = new Property({ name: 'itemWidth', defaultValue: 'auto', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: (v) => Length.parse(v), valueChanged: (target, oldValue, newValue) => (target.effectiveItemWidth = Length.toDevicePixels(newValue, -1)), }); @@ -30,7 +29,7 @@ itemWidthProperty.register(WrapLayoutBase); export const itemHeightProperty = new Property({ name: 'itemHeight', defaultValue: 'auto', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: (v) => Length.parse(v), valueChanged: (target, oldValue, newValue) => (target.effectiveItemHeight = Length.toDevicePixels(newValue, -1)), }); @@ -40,7 +39,7 @@ const converter = makeParser(makeValidator('horizontal export const orientationProperty = new Property({ name: 'orientation', defaultValue: 'horizontal', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: converter, }); orientationProperty.register(WrapLayoutBase); diff --git a/packages/core/ui/page/page-common.ts b/packages/core/ui/page/page-common.ts index 54414b091..62c574842 100644 --- a/packages/core/ui/page/page-common.ts +++ b/packages/core/ui/page/page-common.ts @@ -6,7 +6,6 @@ import { Property, CssProperty } from '../core/properties'; import { Style } from '../styling/style'; import { Color } from '../../color'; import { EventData } from '../../data/observable'; -import { isIOS } from '../../platform'; import { Frame } from '../frame'; import { ActionBar } from '../action-bar'; import { KeyframeAnimationInfo } from '../animation/keyframe-animation'; @@ -171,7 +170,7 @@ export interface PageBase { */ export const actionBarHiddenProperty = new Property({ name: 'actionBarHidden', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: booleanConverter, }); actionBarHiddenProperty.register(PageBase); @@ -182,7 +181,7 @@ actionBarHiddenProperty.register(PageBase); export const backgroundSpanUnderStatusBarProperty = new Property({ name: 'backgroundSpanUnderStatusBar', defaultValue: false, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: booleanConverter, }); backgroundSpanUnderStatusBarProperty.register(PageBase); diff --git a/packages/core/ui/search-bar/search-bar-common.ts b/packages/core/ui/search-bar/search-bar-common.ts index a8355c0aa..71574d027 100644 --- a/packages/core/ui/search-bar/search-bar-common.ts +++ b/packages/core/ui/search-bar/search-bar-common.ts @@ -2,7 +2,6 @@ import { View, CSSType } from '../core/view'; import { Property } from '../core/properties'; import { Color } from '../../color'; -import { isIOS } from '../../platform'; @CSSType('SearchBar') export abstract class SearchBarBase extends View implements SearchBarDefinition { @@ -21,7 +20,7 @@ SearchBarBase.prototype.recycleNativeView = 'auto'; export const textProperty = new Property({ name: 'text', defaultValue: '', - affectsLayout: isIOS, + affectsLayout: global.isIOS, }); textProperty.register(SearchBarBase); diff --git a/packages/core/ui/slider/slider-common.ts b/packages/core/ui/slider/slider-common.ts index 11bd29e8a..8430d35f0 100644 --- a/packages/core/ui/slider/slider-common.ts +++ b/packages/core/ui/slider/slider-common.ts @@ -1,6 +1,5 @@ import { Slider as SliderDefinition } from '.'; import { View, CSSType } from '../core/view'; -import { isIOS } from '../../platform'; import { Property, CoercibleProperty } from '../core/properties'; // TODO: Extract base Range class for slider and progress @@ -25,7 +24,7 @@ export const valueProperty = new CoercibleProperty({ return value; }, - valueConverter: (v) => (isIOS ? parseFloat(v) : parseInt(v)), + valueConverter: (v) => (global.isIOS ? parseFloat(v) : parseInt(v)), }); valueProperty.register(SliderBase); @@ -39,7 +38,7 @@ export const minValueProperty = new Property({ maxValueProperty.coerce(target); valueProperty.coerce(target); }, - valueConverter: (v) => (isIOS ? parseFloat(v) : parseInt(v)), + valueConverter: (v) => (global.isIOS ? parseFloat(v) : parseInt(v)), }); minValueProperty.register(SliderBase); @@ -58,6 +57,6 @@ export const maxValueProperty = new CoercibleProperty({ return value; }, valueChanged: (target, oldValue, newValue) => valueProperty.coerce(target), - valueConverter: (v) => (isIOS ? parseFloat(v) : parseInt(v)), + valueConverter: (v) => (global.isIOS ? parseFloat(v) : parseInt(v)), }); maxValueProperty.register(SliderBase); diff --git a/packages/core/ui/styling/background.android.ts b/packages/core/ui/styling/background.android.ts index 8ce81f744..3c5a57f41 100644 --- a/packages/core/ui/styling/background.android.ts +++ b/packages/core/ui/styling/background.android.ts @@ -248,9 +248,9 @@ function onLivesync(args): void { } } -(global).NativeScriptGlobals.events.on('livesync', onLivesync); +global.NativeScriptGlobals.events.on('livesync', onLivesync); -(global).NativeScriptGlobals.addEventWiring(() => { +global.NativeScriptGlobals.addEventWiring(() => { application.android.on('activityStarted', (args) => { if (!imageFetcher) { initImageCache(args.activity); @@ -260,7 +260,7 @@ function onLivesync(args): void { }); }); -(global).NativeScriptGlobals.addEventWiring(() => { +global.NativeScriptGlobals.addEventWiring(() => { application.android.on('activityStopped', (args) => { if (imageFetcher) { imageFetcher.closeCache(); diff --git a/packages/core/ui/styling/style-properties.ts b/packages/core/ui/styling/style-properties.ts index fb0677806..198a88293 100644 --- a/packages/core/ui/styling/style-properties.ts +++ b/packages/core/ui/styling/style-properties.ts @@ -9,7 +9,6 @@ import { Color } from '../../color'; import { Font, parseFont, FontStyle, FontWeight } from '../../ui/styling/font'; import { layout, hasDuplicates } from '../../utils'; import { Background } from '../../ui/styling/background'; -import { isIOS } from '../../platform'; import { radiansToDegrees } from '../../utils/number-utils'; @@ -198,7 +197,7 @@ export const minWidthProperty = new CssProperty({ name: 'minWidth', cssName: 'min-width', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { const view = target.viewRef.get(); @@ -216,7 +215,7 @@ export const minHeightProperty = new CssProperty({ name: 'minHeight', cssName: 'min-height', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { const view = target.viewRef.get(); @@ -238,7 +237,7 @@ export const widthProperty = new CssAnimationProperty({ // TODO: CSSAnimationProperty was needed for keyframe (copying other impls), but `affectsLayout` does not exist // on the animation property, so fake it here. x_x valueChanged: (target, oldValue, newValue) => { - if (isIOS) { + if (global.isIOS) { const view = target.viewRef.get(); if (view) { view.requestLayout(); @@ -257,7 +256,7 @@ export const heightProperty = new CssAnimationProperty({ // TODO: CSSAnimationProperty was needed for keyframe (copying other impls), but `affectsLayout` does not exist // on the animation property, so fake it here. -_- valueChanged: (target, oldValue, newValue) => { - if (isIOS) { + if (global.isIOS) { const view = target.viewRef.get(); if (view) { view.requestLayout(); @@ -286,7 +285,7 @@ export const marginLeftProperty = new CssProperty({ name: 'marginLeft', cssName: 'margin-left', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueConverter: PercentLength.parse, }); @@ -296,7 +295,7 @@ export const marginRightProperty = new CssProperty({ name: 'marginRight', cssName: 'margin-right', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueConverter: PercentLength.parse, }); @@ -306,7 +305,7 @@ export const marginTopProperty = new CssProperty({ name: 'marginTop', cssName: 'margin-top', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueConverter: PercentLength.parse, }); @@ -316,7 +315,7 @@ export const marginBottomProperty = new CssProperty({ name: 'marginBottom', cssName: 'margin-bottom', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueConverter: PercentLength.parse, }); @@ -340,7 +339,7 @@ export const paddingLeftProperty = new CssProperty({ name: 'paddingLeft', cssName: 'padding-left', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { const view = target.viewRef.get(); @@ -358,7 +357,7 @@ export const paddingRightProperty = new CssProperty({ name: 'paddingRight', cssName: 'padding-right', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { const view = target.viewRef.get(); @@ -376,7 +375,7 @@ export const paddingTopProperty = new CssProperty({ name: 'paddingTop', cssName: 'padding-top', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { const view = target.viewRef.get(); @@ -394,7 +393,7 @@ export const paddingBottomProperty = new CssProperty({ name: 'paddingBottom', cssName: 'padding-bottom', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { const view = target.viewRef.get(); @@ -422,7 +421,7 @@ export const horizontalAlignmentProperty = new CssProperty({ name: 'borderTopWidth', cssName: 'border-top-width', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { let value = Length.toDevicePixels(newValue, 0); @@ -1104,7 +1103,7 @@ export const borderRightWidthProperty = new CssProperty({ name: 'borderRightWidth', cssName: 'border-right-width', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { let value = Length.toDevicePixels(newValue, 0); @@ -1129,7 +1128,7 @@ export const borderBottomWidthProperty = new CssProperty({ name: 'borderBottomWidth', cssName: 'border-bottom-width', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { let value = Length.toDevicePixels(newValue, 0); @@ -1154,7 +1153,7 @@ export const borderLeftWidthProperty = new CssProperty({ name: 'borderLeftWidth', cssName: 'border-left-width', defaultValue: zeroLength, - affectsLayout: isIOS, + affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { let value = Length.toDevicePixels(newValue, 0); @@ -1212,7 +1211,7 @@ export const borderTopLeftRadiusProperty = new CssProperty({ name: 'borderTopLeftRadius', cssName: 'border-top-left-radius', defaultValue: 0, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueChanged: (target, oldValue, newValue) => { let value = Length.toDevicePixels(newValue, 0); if (!isNonNegativeFiniteNumber(value)) { @@ -1229,7 +1228,7 @@ export const borderTopRightRadiusProperty = new CssProperty({ name: 'borderTopRightRadius', cssName: 'border-top-right-radius', defaultValue: 0, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueChanged: (target, oldValue, newValue) => { let value = Length.toDevicePixels(newValue, 0); if (!isNonNegativeFiniteNumber(value)) { @@ -1246,7 +1245,7 @@ export const borderBottomRightRadiusProperty = new CssProperty({ name: 'borderBottomRightRadius', cssName: 'border-bottom-right-radius', defaultValue: 0, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueChanged: (target, oldValue, newValue) => { let value = Length.toDevicePixels(newValue, 0); if (!isNonNegativeFiniteNumber(value)) { @@ -1263,7 +1262,7 @@ export const borderBottomLeftRadiusProperty = new CssProperty({ name: 'borderBottomLeftRadius', cssName: 'border-bottom-left-radius', defaultValue: 0, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueChanged: (target, oldValue, newValue) => { let value = Length.toDevicePixels(newValue, 0); if (!isNonNegativeFiniteNumber(value)) { @@ -1354,7 +1353,7 @@ fontInternalProperty.register(Style); export const fontFamilyProperty = new InheritedCssProperty({ name: 'fontFamily', cssName: 'font-family', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueChanged: (target, oldValue, newValue) => { let currentFont = target.fontInternal || Font.default; if (currentFont.fontFamily !== newValue) { @@ -1368,7 +1367,7 @@ fontFamilyProperty.register(Style); export const fontSizeProperty = new InheritedCssProperty({ name: 'fontSize', cssName: 'font-size', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueChanged: (target, oldValue, newValue) => { if (target.viewRef['handleFontSize'] === true) { return; @@ -1386,7 +1385,7 @@ fontSizeProperty.register(Style); export const fontStyleProperty = new InheritedCssProperty({ name: 'fontStyle', cssName: 'font-style', - affectsLayout: isIOS, + affectsLayout: global.isIOS, defaultValue: FontStyle.NORMAL, valueConverter: FontStyle.parse, valueChanged: (target, oldValue, newValue) => { @@ -1402,7 +1401,7 @@ fontStyleProperty.register(Style); export const fontWeightProperty = new InheritedCssProperty({ name: 'fontWeight', cssName: 'font-weight', - affectsLayout: isIOS, + affectsLayout: global.isIOS, defaultValue: FontWeight.NORMAL, valueConverter: FontWeight.parse, valueChanged: (target, oldValue, newValue) => { @@ -1458,7 +1457,7 @@ export const visibilityProperty = new CssProperty({ name: 'visibility', cssName: 'visibility', defaultValue: Visibility.VISIBLE, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: Visibility.parse, valueChanged: (target, oldValue, newValue) => { const view = target.viewRef.get(); diff --git a/packages/core/ui/styling/style-scope.ts b/packages/core/ui/styling/style-scope.ts index eccddc74a..76b74e55c 100644 --- a/packages/core/ui/styling/style-scope.ts +++ b/packages/core/ui/styling/style-scope.ts @@ -355,8 +355,8 @@ const loadCss = profile(`"style-scope".loadCss`, (cssModule: string) => { } }); -(global).NativeScriptGlobals.events.on('cssChanged', onCssChanged); -(global).NativeScriptGlobals.events.on('livesync', onLiveSync); +global.NativeScriptGlobals.events.on('cssChanged', onCssChanged); +global.NativeScriptGlobals.events.on('livesync', onLiveSync); // Call to this method is injected in the application in: // - no-snapshot - code injected in app.ts by [bundle-config-loader](https://github.com/NativeScript/nativescript-dev-webpack/blob/9b1e34d8ef838006c9b575285c42d2304f5f02b5/bundle-config-loader.ts#L85-L92) @@ -365,7 +365,7 @@ const loadCss = profile(`"style-scope".loadCss`, (cssModule: string) => { // when the snapshot is created - there is no way to use file qualifiers or change the name of on app.css export const loadAppCSS = profile('"style-scope".loadAppCSS', (args: application.LoadAppCSSEventData) => { loadCss(args.cssFile, null, null); - (global).NativeScriptGlobals.events.off('loadAppCss', loadAppCSS); + global.NativeScriptGlobals.events.off('loadAppCss', loadAppCSS); }); if (application.hasLaunched()) { @@ -379,7 +379,7 @@ if (application.hasLaunched()) { null ); } else { - (global).NativeScriptGlobals.events.on('loadAppCss', loadAppCSS); + global.NativeScriptGlobals.events.on('loadAppCss', loadAppCSS); } export class CssState { diff --git a/packages/core/ui/tab-navigation-base/tab-navigation-base/index.d.ts b/packages/core/ui/tab-navigation-base/tab-navigation-base/index.d.ts index 7412d4148..20475c072 100644 --- a/packages/core/ui/tab-navigation-base/tab-navigation-base/index.d.ts +++ b/packages/core/ui/tab-navigation-base/tab-navigation-base/index.d.ts @@ -1,5 +1,4 @@ import { View, AddArrayFromBuilder, AddChildFromBuilder } from '../../core/view'; -import { isIOS } from '../../../platform'; import { TabStrip } from '../tab-strip'; import { TabStripItem } from '../tab-strip-item'; import { TabContentItem } from '../tab-content-item'; diff --git a/packages/core/ui/tab-navigation-base/tab-navigation-base/index.ts b/packages/core/ui/tab-navigation-base/tab-navigation-base/index.ts index 6f58b64d7..e8513b7af 100644 --- a/packages/core/ui/tab-navigation-base/tab-navigation-base/index.ts +++ b/packages/core/ui/tab-navigation-base/tab-navigation-base/index.ts @@ -8,7 +8,6 @@ import { Color } from '../../../color'; import { ViewBase } from '../../core/view-base'; import { Property, CoercibleProperty } from '../../core/properties'; import { EventData } from '../../../data/observable'; -import { isIOS } from '../../../platform'; import { TabContentItem } from '../tab-content-item'; import { TabStrip } from '../tab-strip'; @@ -296,7 +295,7 @@ export function getIconSpecSize(size: { width: number; height: number }): { widt export const selectedIndexProperty = new CoercibleProperty({ name: 'selectedIndex', defaultValue: -1, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueChanged: (target, oldValue, newValue) => { target.onSelectedIndexChanged(oldValue, newValue); }, diff --git a/packages/core/ui/tab-navigation-base/tab-strip-item/index.ts b/packages/core/ui/tab-navigation-base/tab-strip-item/index.ts index f1710becd..32a555709 100644 --- a/packages/core/ui/tab-navigation-base/tab-strip-item/index.ts +++ b/packages/core/ui/tab-navigation-base/tab-strip-item/index.ts @@ -10,7 +10,6 @@ import { AddChildFromBuilder, PseudoClassHandler } from '../../core/view'; import { View, CSSType } from '../../core/view'; import { ViewBase } from '../../core/view-base'; import { backgroundColorProperty, backgroundInternalProperty } from '../../styling/style-properties'; -import { isIOS } from '../../../platform'; import { Image } from '../../image'; import { Label } from '../../label'; import { textTransformProperty, TextTransform } from '../../text-base'; @@ -246,7 +245,7 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi const parent = this.parent; const tabStripParent = parent && parent.parent; - if (this._index === tabStripParent.selectedIndex && !(isIOS && tabStripParent.cssType.toLowerCase() === 'tabs')) { + if (this._index === tabStripParent.selectedIndex && !(global.isIOS && tabStripParent.cssType.toLowerCase() === 'tabs')) { // HACK: tabStripParent instanceof Tabs creates a circular dependency // HACK: tabStripParent.cssType === "Tabs" is a hacky workaround this._goToVisualState('highlighted'); diff --git a/packages/core/ui/tab-view/tab-view-common.ts b/packages/core/ui/tab-view/tab-view-common.ts index 2c376851e..a4c985bb0 100644 --- a/packages/core/ui/tab-view/tab-view-common.ts +++ b/packages/core/ui/tab-view/tab-view-common.ts @@ -4,7 +4,6 @@ import { ViewBase, booleanConverter } from '../core/view-base'; import { Style } from '../styling/style'; import { EventData } from '../../data/observable'; import { Color } from '../../color'; -import { isIOS } from '../../platform'; import { Property, CssProperty, CoercibleProperty } from '../core/properties'; import { TextTransform } from '../text-base'; import { Trace } from '../../trace'; @@ -220,7 +219,7 @@ export function traceMissingIcon(icon: string) { export const selectedIndexProperty = new CoercibleProperty({ name: 'selectedIndex', defaultValue: -1, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueChanged: (target, oldValue, newValue) => { target.onSelectedIndexChanged(oldValue, newValue); }, @@ -258,7 +257,7 @@ iosIconRenderingModeProperty.register(TabViewBase); export const androidOffscreenTabLimitProperty = new Property({ name: 'androidOffscreenTabLimit', defaultValue: 1, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: (v) => parseInt(v), }); androidOffscreenTabLimitProperty.register(TabViewBase); diff --git a/packages/core/ui/text-base/text-base-common.ts b/packages/core/ui/text-base/text-base-common.ts index 7f0b30d16..08e2078e7 100644 --- a/packages/core/ui/text-base/text-base-common.ts +++ b/packages/core/ui/text-base/text-base-common.ts @@ -10,7 +10,6 @@ import { View } from '../core/view'; import { Property, CssProperty, InheritedCssProperty, makeValidator, makeParser } from '../core/properties'; import { Style } from '../styling/style'; import { Length } from '../styling/style-properties'; -import { isAndroid, isIOS } from '../../platform'; import { Observable } from '../../data/observable'; import { TextAlignment, TextDecoration, TextTransform, WhiteSpace } from './text-base-interfaces'; @@ -182,7 +181,7 @@ export function isBold(fontWeight: FontWeight): boolean { export const textProperty = new Property({ name: 'text', defaultValue: '', - affectsLayout: isAndroid, + affectsLayout: global.isAndroid, }); textProperty.register(TextBaseCommon); @@ -245,7 +244,7 @@ export const whiteSpaceProperty = new CssProperty({ name: 'whiteSpace', cssName: 'white-space', defaultValue: 'initial', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: whiteSpaceConverter, }); whiteSpaceProperty.register(Style); @@ -263,7 +262,7 @@ export const letterSpacingProperty = new InheritedCssProperty({ name: 'letterSpacing', cssName: 'letter-spacing', defaultValue: 0, - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: (v) => parseFloat(v), }); letterSpacingProperty.register(Style); @@ -271,7 +270,7 @@ letterSpacingProperty.register(Style); export const lineHeightProperty = new InheritedCssProperty({ name: 'lineHeight', cssName: 'line-height', - affectsLayout: isIOS, + affectsLayout: global.isIOS, valueConverter: (v) => parseFloat(v), }); lineHeightProperty.register(Style); diff --git a/packages/core/utils/debug.ts b/packages/core/utils/debug.ts index d7f8fdad4..435f63960 100644 --- a/packages/core/utils/debug.ts +++ b/packages/core/utils/debug.ts @@ -1,5 +1,4 @@ import { knownFolders } from '../file-system'; -import { isAndroid } from '../platform'; export let debug = true; @@ -62,7 +61,7 @@ export class ScopeError extends Error { formattedMessage = message || inner.message || undefined; } super(formattedMessage); - this.stack = isAndroid ? 'Error: ' + this.message + '\n' + inner.stack.substr(inner.stack.indexOf('\n') + 1) : inner.stack; + this.stack = global.isAndroid ? 'Error: ' + this.message + '\n' + inner.stack.substr(inner.stack.indexOf('\n') + 1) : inner.stack; this.message = formattedMessage; } } diff --git a/packages/webpack/projectFilesManager.js b/packages/webpack/projectFilesManager.js index 409a95dca..5c7ca131b 100644 --- a/packages/webpack/projectFilesManager.js +++ b/packages/webpack/projectFilesManager.js @@ -58,19 +58,18 @@ function copyTemplate(templateName, destinationPath) { function getProjectTemplates(projectDir) { const WEBPACK_CONFIG_NAME = "webpack.config.js"; - const TSCONFIG_TNS_NAME = "tsconfig.tns.json"; let templates; if (isAngular({ projectDir })) { if (isShared({ projectDir })) { templates = getSharedAngularTemplates(WEBPACK_CONFIG_NAME); } else { - templates = getAngularTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_TNS_NAME); + templates = getAngularTemplates(WEBPACK_CONFIG_NAME); } } else if (isVue({ projectDir })) { templates = getVueTemplates(WEBPACK_CONFIG_NAME); } else if (isTypeScript({ projectDir })) { - templates = getTypeScriptTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_TNS_NAME); + templates = getTypeScriptTemplates(WEBPACK_CONFIG_NAME); } else { templates = getJavaScriptTemplates(WEBPACK_CONFIG_NAME); } @@ -84,17 +83,15 @@ function getSharedAngularTemplates(webpackConfigName) { }; } -function getAngularTemplates(webpackConfigName, tsconfigName) { +function getAngularTemplates(webpackConfigName) { return { - "webpack.angular.js": webpackConfigName, - [tsconfigName]: tsconfigName, + "webpack.angular.js": webpackConfigName }; } -function getTypeScriptTemplates(webpackConfigName, tsconfigName) { +function getTypeScriptTemplates(webpackConfigName) { return { - "webpack.typescript.js": webpackConfigName, - [tsconfigName]: tsconfigName, + "webpack.typescript.js": webpackConfigName }; } diff --git a/packages/webpack/templates/tsconfig.tns.json b/packages/webpack/templates/tsconfig.tns.json deleted file mode 100644 index a96f6bbc6..000000000 --- a/packages/webpack/templates/tsconfig.tns.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "module": "ESNext", - "moduleResolution": "node" - } -} diff --git a/packages/webpack/templates/webpack.angular.js b/packages/webpack/templates/webpack.angular.js index 96db6ac35..d6840c7d7 100644 --- a/packages/webpack/templates/webpack.angular.js +++ b/packages/webpack/templates/webpack.angular.js @@ -70,7 +70,7 @@ module.exports = env => { const externals = nsWebpack.getConvertedExternals(env.externals); const appFullPath = resolve(projectRoot, appPath); const appResourcesFullPath = resolve(projectRoot, appResourcesPath); - const tsConfigName = 'tsconfig.tns.json'; + const tsConfigName = 'tsconfig.json'; const entryModule = `${nsWebpack.getEntryModule(appFullPath, platform)}.ts`; const entryPath = `.${sep}${entryModule}`; const entries = { bundle: entryPath }; @@ -349,6 +349,8 @@ module.exports = env => { // Define useful constants like TNS_WEBPACK new webpack.DefinePlugin({ 'global.TNS_WEBPACK': 'true', + 'global.isAndroid': platform === 'android', + 'global.isIOS': platform === 'ios', process: 'global.process' }), // Remove all files from the out dir. diff --git a/packages/webpack/templates/webpack.javascript.js b/packages/webpack/templates/webpack.javascript.js index e54ecfa0f..4c5dad35e 100644 --- a/packages/webpack/templates/webpack.javascript.js +++ b/packages/webpack/templates/webpack.javascript.js @@ -232,6 +232,8 @@ module.exports = env => { // Define useful constants like TNS_WEBPACK new webpack.DefinePlugin({ "global.TNS_WEBPACK": "true", + "global.isAndroid": platform === 'android', + "global.isIOS": platform === 'ios', "process": "global.process", }), // Remove all files from the out dir. diff --git a/packages/webpack/templates/webpack.typescript.js b/packages/webpack/templates/webpack.typescript.js index 743a6585f..7c8067d6c 100644 --- a/packages/webpack/templates/webpack.typescript.js +++ b/packages/webpack/templates/webpack.typescript.js @@ -85,7 +85,7 @@ module.exports = env => { const entries = env.entries || {}; entries.bundle = entryPath; - const tsConfigPath = resolve(projectRoot, "tsconfig.tns.json"); + const tsConfigPath = resolve(projectRoot, "tsconfig.json"); const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("@nativescript") > -1); if (platform === "ios" && !areCoreModulesExternal) { @@ -260,6 +260,8 @@ module.exports = env => { // Define useful constants like TNS_WEBPACK new webpack.DefinePlugin({ "global.TNS_WEBPACK": "true", + "global.isAndroid": platform === 'android', + "global.isIOS": platform === 'ios', "process": "global.process", }), // Remove all files from the out dir. diff --git a/packages/webpack/templates/webpack.vue.js b/packages/webpack/templates/webpack.vue.js index f18804189..0dc4da83a 100644 --- a/packages/webpack/templates/webpack.vue.js +++ b/packages/webpack/templates/webpack.vue.js @@ -287,6 +287,8 @@ module.exports = env => { // Define useful constants like TNS_WEBPACK new webpack.DefinePlugin({ "global.TNS_WEBPACK": "true", + "global.isAndroid": platform === 'android', + "global.isIOS": platform === 'ios', "TNS_ENV": JSON.stringify(mode), "process": "global.process" }),