From 1f790edc8032fd36bde4b7a24e4d1c1c4b4dea49 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Wed, 23 Sep 2020 23:48:19 +0200 Subject: [PATCH 1/4] fix(core): bundle entry points and global handling (#8884) --- packages/core/application/application-common.ts | 5 +---- packages/core/bundle-entry-points.ts | 4 ++-- packages/core/globals/index.ts | 2 +- packages/core/index.ts | 5 ++--- packages/core/inspector_modules.ios.ts | 5 +---- packages/core/ui/frame/activity.android.ts | 7 +------ packages/webpack/bundle-config-loader.ts | 2 +- 7 files changed, 9 insertions(+), 21 deletions(-) diff --git a/packages/core/application/application-common.ts b/packages/core/application/application-common.ts index d27dee9c5..208fbfd6d 100644 --- a/packages/core/application/application-common.ts +++ b/packages/core/application/application-common.ts @@ -1,8 +1,5 @@ // Require globals first so that snapshot takes __extends function. -const nsGlobals = require('../globals'); -if (!global.NativeScriptHasInitGlobal) { - nsGlobals.initGlobal(); -} +import '../globals'; // Types import { AndroidApplication, iOSApplication } from '.'; diff --git a/packages/core/bundle-entry-points.ts b/packages/core/bundle-entry-points.ts index be990c714..ea5bfda33 100644 --- a/packages/core/bundle-entry-points.ts +++ b/packages/core/bundle-entry-points.ts @@ -1,5 +1,5 @@ -const g = require('./globals'); -g.initGlobal(); +// using import is important to ensure webpack keep it in order +import './globals'; // Register "dynamically" loaded module that need to be resolved by the // XML/component builders. diff --git a/packages/core/globals/index.ts b/packages/core/globals/index.ts index d47733635..a5771d05f 100644 --- a/packages/core/globals/index.ts +++ b/packages/core/globals/index.ts @@ -360,4 +360,4 @@ export function initGlobal() { } if (!global.NativeScriptHasInitGlobal) { initGlobal(); -} +} \ No newline at end of file diff --git a/packages/core/index.ts b/packages/core/index.ts index 68f03d56b..6291561c7 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -1,7 +1,6 @@ /// -// Init globals first (use require to ensure it's always at the top) -const nsGlobals = require('./globals'); -nsGlobals.initGlobal(); +// Init globals first (use import to ensure it's always at the top) +import './globals'; export { iOSApplication, AndroidApplication } from './application'; export type { ApplicationEventData, LaunchEventData, OrientationChangedEventData, UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData, AndroidActivityEventData, AndroidActivityBundleEventData, AndroidActivityRequestPermissionsEventData, AndroidActivityResultEventData, AndroidActivityNewIntentEventData, AndroidActivityBackPressedEventData, SystemAppearanceChangedEventData } from './application'; diff --git a/packages/core/inspector_modules.ios.ts b/packages/core/inspector_modules.ios.ts index 5bc188a5a..18deeeebf 100644 --- a/packages/core/inspector_modules.ios.ts +++ b/packages/core/inspector_modules.ios.ts @@ -1,8 +1,5 @@ console.log('Loading inspector modules...'); -import { initGlobal } from './globals'; -if (!global.NativeScriptHasInitGlobal) { - initGlobal(); -} +import './globals'; require('./debugger/webinspector-network'); require('./debugger/webinspector-dom'); require('./debugger/webinspector-css'); diff --git a/packages/core/ui/frame/activity.android.ts b/packages/core/ui/frame/activity.android.ts index 746ec118c..6c7fdead1 100644 --- a/packages/core/ui/frame/activity.android.ts +++ b/packages/core/ui/frame/activity.android.ts @@ -1,12 +1,7 @@ +import '../../globals'; import { setActivityCallbacks, AndroidActivityCallbacks } from '.'; -// use requires to ensure import order -const globals = require('../../globals'); const appModule = require('../../application'); -if (global.__snapshot) { - globals.initGlobal(); -} - /** * 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 diff --git a/packages/webpack/bundle-config-loader.ts b/packages/webpack/bundle-config-loader.ts index df0af080b..8e5412a8c 100644 --- a/packages/webpack/bundle-config-loader.ts +++ b/packages/webpack/bundle-config-loader.ts @@ -52,7 +52,7 @@ const loader: loader.Loader = function (source, map) { } source = ` - require("${sourceModule}/bundle-entry-points"); + import "${sourceModule}/bundle-entry-points"; ${source} `; From 13be3d60d736b1bb5f865e7338e950279a590f0d Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Wed, 23 Sep 2020 14:54:01 -0700 Subject: [PATCH 2/4] chore(release): @nativescript/core@7.0.5 --- CHANGELOG.md | 9 +++++++++ package.json | 2 +- packages/core/package.json | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c722d7c4..26375ca6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [7.0.5](https://github.com/NativeScript/NativeScript/compare/7.0.4-core...7.0.5) (2020-09-23) + + +### Bug Fixes + +* **core:** bundle entry points and global handling ([#8884](https://github.com/NativeScript/NativeScript/issues/8884)) ([1f790ed](https://github.com/NativeScript/NativeScript/commit/1f790edc8032fd36bde4b7a24e4d1c1c4b4dea49)) + + + ## [7.0.4](https://github.com/NativeScript/NativeScript/compare/7.0.3-types-ios...7.0.4) (2020-09-23) diff --git a/package.json b/package.json index e8460e884..ae80705d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript", - "version": "7.0.4", + "version": "7.0.5", "license": "MIT", "scripts": { "setup": "npx rimraf hooks node_modules package-lock.json && npm i && ts-patch install && nx run core:setup", diff --git a/packages/core/package.json b/packages/core/package.json index fa4d816f4..c877bfcc1 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -3,7 +3,7 @@ "main": "index", "types": "index.d.ts", "description": "NativeScript Core Modules", - "version": "7.0.4", + "version": "7.0.5", "homepage": "https://nativescript.org", "repository": { "type": "git", From 29da0fb5f7590f2e68a26106a6a5d79d211b311a Mon Sep 17 00:00:00 2001 From: Nathanael Anderson Date: Wed, 23 Sep 2020 18:01:24 -0500 Subject: [PATCH 3/4] chore: comment for why nativeTextViewProtected (#8886) Explains for future generations why this getter exists. :grinning: --- .../core/ui/text-base/text-base-common.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/core/ui/text-base/text-base-common.ts b/packages/core/ui/text-base/text-base-common.ts index 08e2078e7..5f60c9aea 100644 --- a/packages/core/ui/text-base/text-base-common.ts +++ b/packages/core/ui/text-base/text-base-common.ts @@ -26,6 +26,26 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition public text: string; public formattedText: FormattedString; + /*** + * In the NativeScript Core; by default the nativeTextViewProtected points to the same value as nativeViewProtected. + * At this point no internal NS components need this indirection functionality. + * This indirection is used to allow support usage by third party components so they don't have to duplicate functionality. + * + * A third party component can just override the `nativeTextViewProtected` getter and return a different internal view and that view would be + * what all TextView/TextInput class features would be applied to. + * + * A example is the Android MaterialDesign TextInput class, it has a wrapper view of a TextInputLayout + * https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout + * which wraps the actual TextInput. This wrapper layout (TextInputLayout) must be assigned to the nativeViewProtected as the entire + * NS Core uses nativeViewProtected for everything related to layout, so that it can be measured, added to the parent view as a child, ect. + * + * However, its internal view would be the actual TextView/TextInput and to allow that sub-view to have the normal TextView/TextInput + * class features, which we expose and to allow them to work on it, the internal TextView/TextInput is what the needs to have the class values applied to it. + * + * So all code that works on what is expected to be a TextView/TextInput should use `nativeTextViewProtected` so that any third party + * components that need to have two separate components can work properly without them having to duplicate all the TextBase (and decendants) functionality + * by just overriding the nativeTextViewProtected getter. + **/ get nativeTextViewProtected() { return this.nativeViewProtected; } From 021c0bb9a24f15a9adf9d5e25a981ea53901e600 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Thu, 24 Sep 2020 01:14:39 +0200 Subject: [PATCH 4/4] fix(core): delegate should be set on nativeTextViewProtected (#8881) just like textfields. Fixes components extending this one --- packages/core/ui/text-view/index.ios.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/ui/text-view/index.ios.ts b/packages/core/ui/text-view/index.ios.ts index 349770359..3de66521a 100644 --- a/packages/core/ui/text-view/index.ios.ts +++ b/packages/core/ui/text-view/index.ios.ts @@ -85,6 +85,7 @@ class NoScrollAnimationUITextView extends UITextView { @CSSType('TextView') export class TextView extends TextViewBaseCommon { nativeViewProtected: UITextView; + nativeTextViewProtected: UITextView; private _delegate: UITextViewDelegateImpl; _isShowingHint: boolean; public _isEditing: boolean; @@ -114,11 +115,11 @@ export class TextView extends TextViewBaseCommon { @profile public onLoaded() { super.onLoaded(); - this.ios.delegate = this._delegate; + this.nativeTextViewProtected.delegate = this._delegate; } public onUnloaded() { - this.ios.delegate = null; + this.nativeTextViewProtected.delegate = null; super.onUnloaded(); }