From 7dd41e5c21c872ee5f9e17cd06c6b86b0cb3f714 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Tue, 19 Dec 2023 15:32:50 -0500 Subject: [PATCH] fix circular imports and change weakref.get->deref --- apps/automated/src/ui-helper.ts | 6 ++-- .../src/ui/core/bindable/bindable-tests.ts | 12 ++++---- .../weak-event-listener-tests.ts | 8 +++--- .../src/ui/list-view/list-view-tests.ts | 14 +++++----- .../accessibility-service-common.ts | 2 +- packages/core/accessibility/index.android.ts | 6 ++-- packages/core/color/index.ios.ts | 2 +- .../core/debugger/devtools-elements.common.ts | 2 +- packages/core/debugger/dom-node.ts | 8 +++--- .../core/ui/action-bar/action-bar-common.ts | 4 +-- packages/core/ui/action-bar/index.android.ts | 4 +-- packages/core/ui/animation/index.android.ts | 4 +-- packages/core/ui/core/bindable/index.ts | 28 +++++++++---------- packages/core/ui/core/properties/index.ts | 14 +++++----- packages/core/ui/core/view-base/index.ts | 2 +- packages/core/ui/core/view/index.android.ts | 6 ++-- packages/core/ui/core/view/view-common.ts | 3 +- .../core/ui/core/weak-event-listener/index.ts | 4 +-- .../ui/editable-text-base/index.android.ts | 10 +++---- packages/core/ui/frame/index.android.ts | 6 ++-- packages/core/ui/gestures/gestures-common.ts | 2 -- packages/core/ui/image-cache/index.android.ts | 4 +-- packages/core/ui/index.ts | 3 +- packages/core/ui/page/index.ios.ts | 2 +- packages/core/ui/scroll-view/index.android.ts | 2 +- packages/core/ui/styling/style-properties.ts | 26 ++++++++--------- packages/core/ui/styling/style-scope.ts | 18 ++++++------ packages/core/ui/styling/style/index.ts | 4 +-- packages/core/ui/tab-view/index.android.ts | 4 +-- packages/core/ui/text-base/index.android.ts | 2 +- packages/core/ui/web-view/index.ios.ts | 3 +- 31 files changed, 108 insertions(+), 107 deletions(-) diff --git a/apps/automated/src/ui-helper.ts b/apps/automated/src/ui-helper.ts index 487ba37cf..10901c4dc 100644 --- a/apps/automated/src/ui-helper.ts +++ b/apps/automated/src/ui-helper.ts @@ -121,9 +121,9 @@ export function buildUIWithWeakRefAndInteract(createFunc: () => clearPage(); const page = getCurrentPage(); const weakRef = new WeakRef(createFunc()); - page.content = weakRef.get(); + page.content = weakRef.deref(); if (interactWithViewFunc) { - interactWithViewFunc(weakRef.get()); + interactWithViewFunc(weakRef.deref()); } page.content = null; // Give a change for native cleanup (e.g. keyboard close, etc.). @@ -141,7 +141,7 @@ export function buildUIWithWeakRefAndInteract(createFunc: () => } Utils.GC(); try { - TKUnit.assert(!weakRef.get(), weakRef.get() + ' leaked!'); + TKUnit.assert(!weakRef.deref(), weakRef.deref() + ' leaked!'); done(null); } catch (ex) { done(ex); diff --git a/apps/automated/src/ui/core/bindable/bindable-tests.ts b/apps/automated/src/ui/core/bindable/bindable-tests.ts index 8007ee0ff..d4f81ad63 100644 --- a/apps/automated/src/ui/core/bindable/bindable-tests.ts +++ b/apps/automated/src/ui/core/bindable/bindable-tests.ts @@ -216,18 +216,18 @@ export function test_bindingContext_Change_IsReflected_Properly() { // const weakRef = createButton(model); // try { -// stack.addChild(weakRef.get()); -// TKUnit.waitUntilReady(() => weakRef.get().isLoaded); +// stack.addChild(weakRef.deref()); +// TKUnit.waitUntilReady(() => weakRef.deref().isLoaded); -// TKUnit.assertEqual(weakRef.get().text, expectedValue, 'Binding is not working properly!'); -// stack.removeChild(weakRef.get()); -// TKUnit.waitUntilReady(() => !weakRef.get().isLoaded); +// TKUnit.assertEqual(weakRef.deref().text, expectedValue, 'Binding is not working properly!'); +// stack.removeChild(weakRef.deref()); +// TKUnit.waitUntilReady(() => !weakRef.deref().isLoaded); // utils.GC(); // // Give time for the GC to kick in // setTimeout(() => { // utils.GC(); -// TKUnit.assert(!weakRef.get(), 'UIElement is still alive!'); +// TKUnit.assert(!weakRef.deref(), 'UIElement is still alive!'); // testFinished = true; // }, 100); // } catch (e) { diff --git a/apps/automated/src/ui/core/weak-event-listener/weak-event-listener-tests.ts b/apps/automated/src/ui/core/weak-event-listener/weak-event-listener-tests.ts index d535584d0..45e9657ea 100644 --- a/apps/automated/src/ui/core/weak-event-listener/weak-event-listener-tests.ts +++ b/apps/automated/src/ui/core/weak-event-listener/weak-event-listener-tests.ts @@ -104,12 +104,12 @@ function getTargetAsWeakRef(): WeakRef { // // with the v8 6.5 the GC does not release WeakRefs so fast if you pass them to a method // // that's why we are making the call to the addWeakEventListener in a closure so that the WeakRef will be easier released // (function () { -// addWeakEventListener(sourceRef.get(), Observable.propertyChangeEvent, emptyHandler, targetRef.get()); +// addWeakEventListener(sourceRef.deref(), Observable.propertyChangeEvent, emptyHandler, targetRef.deref()); // })(); // forceGC(); // try { -// TKUnit.assert(!targetRef.get(), 'Target should be released after GC'); +// TKUnit.assert(!targetRef.deref(), 'Target should be released after GC'); // done(null); // } catch (e) { // done(e); @@ -123,12 +123,12 @@ function getTargetAsWeakRef(): WeakRef { // // with the v8 6.5 the GC does not release WeakRefs so fast if you pass them to a method // // that's why we are making the call to the addWeakEventListener in a closure so that the WeakRef will be easier released // (function () { -// addWeakEventListener(sourceRef.get(), Observable.propertyChangeEvent, targetRef.get().onEvent, targetRef.get()); +// addWeakEventListener(sourceRef.deref(), Observable.propertyChangeEvent, targetRef.deref().onEvent, targetRef.deref()); // })(); // forceGC(); // try { -// TKUnit.assert(!sourceRef.get(), 'Source should be released after GC'); +// TKUnit.assert(!sourceRef.deref(), 'Source should be released after GC'); // done(null); // } catch (e) { // done(e); diff --git a/apps/automated/src/ui/list-view/list-view-tests.ts b/apps/automated/src/ui/list-view/list-view-tests.ts index f5f83dc3d..3fad34db6 100644 --- a/apps/automated/src/ui/list-view/list-view-tests.ts +++ b/apps/automated/src/ui/list-view/list-view-tests.ts @@ -626,9 +626,9 @@ export class ListViewTest extends UITest { public test_no_memory_leak_when_items_is_regular_array() { let weakRef = new WeakRef(this.testView); - weakRef.get().items = FEW_ITEMS; + weakRef.deref().items = FEW_ITEMS; this.waitUntilTestElementIsLoaded(); - TKUnit.assertTrue(weakRef.get().isLoaded, 'ListView should be loaded here'); + TKUnit.assertTrue(weakRef.deref().isLoaded, 'ListView should be loaded here'); this.assertNoMemoryLeak(weakRef); } @@ -637,9 +637,9 @@ export class ListViewTest extends UITest { var colors = new ObservableArray(['red', 'green', 'blue']); let weakRef = new WeakRef(this.testView); - weakRef.get().items = colors; + weakRef.deref().items = colors; this.waitUntilTestElementIsLoaded(); - TKUnit.assertTrue(weakRef.get().isLoaded, 'ListView should be loaded here'); + TKUnit.assertTrue(weakRef.deref().isLoaded, 'ListView should be loaded here'); this.assertNoMemoryLeak(weakRef); } @@ -729,7 +729,7 @@ export class ListViewTest extends UITest { } Utils.GC(); - TKUnit.assert(weakRef.get(), weakRef.get() + ' died prematurely!'); + TKUnit.assert(weakRef.deref(), weakRef.deref() + ' died prematurely!'); } public test_check_if_item_at_index_is_visible() { @@ -772,10 +772,10 @@ export class ListViewTest extends UITest { // } // Utils.GC(); // - // return !weakRef.get(); + // return !weakRef.deref(); // }); - // TKUnit.assert(!weakRef.get(), weakRef.get() + ' leaked!'); + // TKUnit.assert(!weakRef.deref(), weakRef.deref() + ' leaked!'); } private loadViewWithItemNumber(args: ItemEventData) { diff --git a/packages/core/accessibility/accessibility-service-common.ts b/packages/core/accessibility/accessibility-service-common.ts index 8ea7503be..7444ec92e 100644 --- a/packages/core/accessibility/accessibility-service-common.ts +++ b/packages/core/accessibility/accessibility-service-common.ts @@ -14,7 +14,7 @@ export class CommonA11YServiceEnabledObservable extends SharedA11YObservable { let lastValue: boolean; function callback() { - const self = ref?.get(); + const self = ref?.deref(); if (!self) { sharedA11YObservable.off(Observable.propertyChangeEvent, callback); diff --git a/packages/core/accessibility/index.android.ts b/packages/core/accessibility/index.android.ts index cadd85e99..6d8e05589 100644 --- a/packages/core/accessibility/index.android.ts +++ b/packages/core/accessibility/index.android.ts @@ -71,7 +71,7 @@ function accessibilityEventHelper(view: View, eventType: number) { return; } case android.view.accessibility.AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { - const lastView = lastFocusedView?.get(); + const lastView = lastFocusedView?.deref(); if (lastView && view !== lastView) { const lastAndroidView = lastView.nativeViewProtected as android.view.View; if (lastAndroidView) { @@ -89,7 +89,7 @@ function accessibilityEventHelper(view: View, eventType: number) { return; } case android.view.accessibility.AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { - const lastView = lastFocusedView?.get(); + const lastView = lastFocusedView?.deref(); if (lastView && view === lastView) { lastFocusedView = null; androidView.clearFocus(); @@ -145,7 +145,7 @@ function ensureNativeClasses() { } private getTnsView(androidView: android.view.View) { - const view = androidViewToTNSView.get(androidView)?.get(); + const view = androidViewToTNSView.get(androidView)?.deref(); if (!view) { androidViewToTNSView.delete(androidView); diff --git a/packages/core/color/index.ios.ts b/packages/core/color/index.ios.ts index fafa3866c..f865b130b 100644 --- a/packages/core/color/index.ios.ts +++ b/packages/core/color/index.ios.ts @@ -6,7 +6,7 @@ export class Color extends ColorBase { get ios(): UIColor { if (!this._ios) { // iOS Color is using floating-point values in the [0, 1] range, so divide the components by 255 - this._ios = UIColor.alloc().initWithRedGreenBlueAlpha(this.r / 255, this.g / 255, this.b / 255, this.a / 255); + this._ios = UIColor.colorWithRedGreenBlueAlpha(this.r / 255, this.g / 255, this.b / 255, this.a / 255); } return this._ios; diff --git a/packages/core/debugger/devtools-elements.common.ts b/packages/core/debugger/devtools-elements.common.ts index 6859ab4c1..c6be3fe58 100644 --- a/packages/core/debugger/devtools-elements.common.ts +++ b/packages/core/debugger/devtools-elements.common.ts @@ -21,7 +21,7 @@ function getViewById(nodeId: number): ViewBase { const node = getNodeById(nodeId); let view; if (node) { - view = node.viewRef.get(); + view = node.viewRef.deref(); } return view; diff --git a/packages/core/debugger/dom-node.ts b/packages/core/debugger/dom-node.ts index f7f229ffb..f6df1aaea 100644 --- a/packages/core/debugger/dom-node.ts +++ b/packages/core/debugger/dom-node.ts @@ -91,13 +91,13 @@ export class DOMNode { public loadAttributes() { this.attributes = []; - getSetPropertiesLazy()(this.viewRef.get()) + getSetPropertiesLazy()(this.viewRef.deref()) .filter(propertyFilter) .forEach((pair) => this.attributes.push(pair[0], pair[1] + '')); } get children(): DOMNode[] { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { return []; } @@ -116,7 +116,7 @@ export class DOMNode { onChildAdded(childView: ViewBase): void { notifyInspector((ins) => { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); let previousChild: ViewBase; view.eachChild((child) => { @@ -156,7 +156,7 @@ export class DOMNode { } getComputedProperties(): CSSComputedStyleProperty[] { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { return []; } diff --git a/packages/core/ui/action-bar/action-bar-common.ts b/packages/core/ui/action-bar/action-bar-common.ts index 103699c02..938a3eb96 100644 --- a/packages/core/ui/action-bar/action-bar-common.ts +++ b/packages/core/ui/action-bar/action-bar-common.ts @@ -434,7 +434,7 @@ export const androidContentInsetLeftProperty = new CssProperty { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.effectiveContentInsetLeft = Length.toDevicePixels(newValue); } else { @@ -451,7 +451,7 @@ export const androidContentInsetRightProperty = new CssProperty { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.effectiveContentInsetRight = Length.toDevicePixels(newValue); } else { diff --git a/packages/core/ui/action-bar/index.android.ts b/packages/core/ui/action-bar/index.android.ts index 994f87f85..734d9e534 100644 --- a/packages/core/ui/action-bar/index.android.ts +++ b/packages/core/ui/action-bar/index.android.ts @@ -293,7 +293,7 @@ export class ActionBar extends ActionBarBase { this.nativeViewProtected.setNavigationOnClickListener( new android.view.View.OnClickListener({ onClick: function (v) { - const owner = navBtn?.get(); + const owner = navBtn?.deref(); if (owner) { owner._raiseTap(); } @@ -382,7 +382,7 @@ export class ActionBar extends ActionBarBase { item.actionView.android.setOnClickListener( new android.view.View.OnClickListener({ onClick: function (v: android.view.View) { - const owner = weakRef?.get(); + const owner = weakRef?.deref(); if (owner) { owner._raiseTap(); } diff --git a/packages/core/ui/animation/index.android.ts b/packages/core/ui/animation/index.android.ts index b335774af..12f3e2387 100644 --- a/packages/core/ui/animation/index.android.ts +++ b/packages/core/ui/animation/index.android.ts @@ -143,7 +143,7 @@ export class Animation extends AnimationBase { if (Trace.isEnabled()) { Trace.write('MainAnimatorListener.onAnimationEnd(' + animator + ')', Trace.categories.Animation); } - const thisRef = that?.get(); + const thisRef = that?.deref(); if (thisRef) { thisRef._onAndroidAnimationEnd(); } @@ -152,7 +152,7 @@ export class Animation extends AnimationBase { if (Trace.isEnabled()) { Trace.write('MainAnimatorListener.onAnimationCancel(' + animator + ')', Trace.categories.Animation); } - const thisRef = that?.get(); + const thisRef = that?.deref(); if (thisRef) { thisRef._onAndroidAnimationCancel(); } diff --git a/packages/core/ui/core/bindable/index.ts b/packages/core/ui/core/bindable/index.ts index a737f80f2..460d4c471 100644 --- a/packages/core/ui/core/bindable/index.ts +++ b/packages/core/ui/core/bindable/index.ts @@ -136,7 +136,7 @@ export class Binding { } if (options.twoWay) { - const target = this.targetOptions.instance.get(); + const target = this.targetOptions.instance.deref(); if (target instanceof Observable) { target.on(`${this.targetOptions.property}Change`, this.onTargetPropertyChanged, this); } @@ -189,7 +189,7 @@ export class Binding { } private bindingContextChanged(data: PropertyChangeData): void { - const target = this.targetOptions.instance.get(); + const target = this.targetOptions.instance.deref(); if (!target) { this.unbind(); @@ -209,7 +209,7 @@ export class Binding { } public bind(source: any): void { - const target = this.targetOptions.instance.get(); + const target = this.targetOptions.instance.deref(); if (this.sourceIsBindingContext && target instanceof Observable && this.targetOptions.property !== 'bindingContext') { target.on('bindingContextChange', this.bindingContextChanged, this); } @@ -238,7 +238,7 @@ export class Binding { } public unbind() { - const target = this.targetOptions.instance.get(); + const target = this.targetOptions.instance.deref(); if (target instanceof Observable) { if (this.options.twoWay) { target.off(`${this.targetOptions.property}Change`, this.onTargetPropertyChanged, this); @@ -273,11 +273,11 @@ export class Binding { } if (property === bc.parentValueKey || property.indexOf(bc.parentsValueKey) === 0) { - const parentView = this.getParentView(this.target.get(), property).view; + const parentView = this.getParentView(this.target.deref(), property).view; if (parentView) { currentObject = parentView.bindingContext; } else { - const targetInstance = this.target.get(); + const targetInstance = this.target.deref(); targetInstance.off('loaded', this.loadedHandlerVisualTreeBinding, this); targetInstance.on('loaded', this.loadedHandlerVisualTreeBinding, this); } @@ -303,7 +303,7 @@ export class Binding { } private addPropertyChangeListeners(source: WeakRef, sourceProperty: Array, parentProperies?: string) { - const objectsAndProperties = this.resolveObjectsAndProperties(source.get(), sourceProperty); + const objectsAndProperties = this.resolveObjectsAndProperties(source.deref(), sourceProperty); let prop = parentProperies || ''; for (let i = 0, length = objectsAndProperties.length; i < length; i++) { @@ -345,7 +345,7 @@ export class Binding { if (__UI_USE_EXTERNAL_RENDERER__) { } else if (this.options.expression) { const changedModel = {}; - const targetInstance = this.target.get(); + const targetInstance = this.target.deref(); let sourcePropertyName = ''; if (this.sourceOptions) { sourcePropertyName = this.sourceOptions.property; @@ -382,7 +382,7 @@ export class Binding { if (!__UI_USE_EXTERNAL_RENDERER__) { let context; - const targetInstance = this.target.get(); + const targetInstance = this.target.deref(); const addedProps = []; try { let exp; @@ -393,7 +393,7 @@ export class Binding { } if (exp) { - context = (this.source && this.source.get && this.source.get()) || global; + context = (this.source && this.source.deref && this.source.deref()) || global; const resources = bindableResources.get(); for (const prop in resources) { if (resources.hasOwnProperty(prop) && !context.hasOwnProperty(prop)) { @@ -526,7 +526,7 @@ export class Binding { if (__UI_USE_EXTERNAL_RENDERER__) { } else if (this.options.expression) { const changedModel = {}; - changedModel[bc.bindingValueKey] = this.source ? this.source.get() : undefined; + changedModel[bc.bindingValueKey] = this.source ? this.source.deref() : undefined; const expressionValue = this._getExpressionValue(this.options.expression, false, changedModel); if (expressionValue instanceof Error) { Trace.write((expressionValue).message, Trace.categories.Binding, Trace.messageType.error); @@ -536,7 +536,7 @@ export class Binding { } if (this.sourceOptions) { - const sourceOptionsInstance = this.sourceOptions.instance.get(); + const sourceOptionsInstance = this.sourceOptions.instance.deref(); if (this.sourceOptions.property === bc.bindingValueKey) { return sourceOptionsInstance; } else if (sourceOptionsInstance instanceof Observable && this.sourceOptions.property && this.sourceOptions.property !== '') { @@ -565,7 +565,7 @@ export class Binding { } private updateSource(value: any) { - if (this.updating || !this.source || !this.source.get()) { + if (this.updating || !this.source || !this.source.deref()) { return; } @@ -624,7 +624,7 @@ export class Binding { private updateOptions(options: { instance: WeakRef; property: string }, value: any) { let optionsInstance; if (options && options.instance) { - optionsInstance = options.instance.get(); + optionsInstance = options.instance.deref(); } if (!optionsInstance) { diff --git a/packages/core/ui/core/properties/index.ts b/packages/core/ui/core/properties/index.ts index 1eedb390e..2f7078b6d 100644 --- a/packages/core/ui/core/properties/index.ts +++ b/packages/core/ui/core/properties/index.ts @@ -645,7 +645,7 @@ export class CssProperty implements CssProperty { const property = this; function setLocalValue(this: T, newValue: U | string): void { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`${newValue} not set to view because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn); @@ -723,7 +723,7 @@ export class CssProperty implements CssProperty { } function setCssValue(this: T, newValue: U | string): void { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`${newValue} not set to view because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn); @@ -925,7 +925,7 @@ export class CssAnimationProperty implements CssAnimationPro return this[symbol]; }, set(this: T, boxedValue: U | string) { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`${boxedValue} not set to view because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn); @@ -1034,7 +1034,7 @@ export class CssAnimationProperty implements CssAnimationPro } public _initDefaultNativeValue(target: T): void { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (!view) { Trace.write(`_initDefaultNativeValue not executed to view because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn); @@ -1102,7 +1102,7 @@ export class InheritedCssProperty extends CssProperty const setFunc = (valueSource: ValueSource) => function (this: T, boxedValue: any): void { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`${boxedValue} not set to view's property because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn); @@ -1249,7 +1249,7 @@ export class ShorthandProperty implements ShorthandProperty< const converter = options.converter; function setLocalValue(this: T, value: string | P): void { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`setLocalValue not executed to view because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn); @@ -1264,7 +1264,7 @@ export class ShorthandProperty implements ShorthandProperty< } function setCssValue(this: T, value: string): void { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`setCssValue not executed to view because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn); diff --git a/packages/core/ui/core/view-base/index.ts b/packages/core/ui/core/view-base/index.ts index d458e1d04..746b2482d 100644 --- a/packages/core/ui/core/view-base/index.ts +++ b/packages/core/ui/core/view-base/index.ts @@ -270,7 +270,7 @@ let viewIdCounter = 1; // let nativeView; // while (array.length > 0) { // const weakRef = array.pop(); -// nativeView = weakRef.get(); +// nativeView = weakRef.deref(); // if (nativeView) { // return nativeView; // } diff --git a/packages/core/ui/core/view/index.android.ts b/packages/core/ui/core/view/index.android.ts index f6e67654f..ddab7f3ad 100644 --- a/packages/core/ui/core/view/index.android.ts +++ b/packages/core/ui/core/view/index.android.ts @@ -97,7 +97,7 @@ function initializeTouchListener(): void { } onTouch(view: android.view.View, event: android.view.MotionEvent): boolean { - const owner = this.owner.get(); + const owner = this.owner.deref(); if (!owner) { return; } @@ -259,7 +259,7 @@ function initializeDialogFragment() { public onDismiss(dialog: android.content.DialogInterface): void { super.onDismiss(dialog); const manager = this.getFragmentManager(); - const activity = this.activity?.get(); + const activity = this.activity?.deref(); if (manager && !activity?.isChangingConfigurations()) { removeModal(this.owner._domId); this._dismissCallback(); @@ -274,7 +274,7 @@ function initializeDialogFragment() { public onDestroy(): void { super.onDestroy(); const owner = this.owner; - const activity = this.activity?.get(); + const activity = this.activity?.deref(); if (!activity?.isChangingConfigurations()) { this.activity = null; } diff --git a/packages/core/ui/core/view/view-common.ts b/packages/core/ui/core/view/view-common.ts index ad3e3cf26..fada71c52 100644 --- a/packages/core/ui/core/view/view-common.ts +++ b/packages/core/ui/core/view/view-common.ts @@ -15,7 +15,7 @@ import { ViewHelper } from './view-helper'; import { PercentLength } from '../../styling/style-properties'; -import { observe as gestureObserve, GesturesObserver, GestureTypes, GestureEventData, fromString as gestureFromString, TouchManager, TouchAnimationOptions } from '../../gestures'; +import { observe as gestureObserve, GesturesObserver, GestureTypes, GestureEventData, fromString as gestureFromString, type TouchAnimationOptions } from '../../gestures'; import { CSSUtils } from '../../../css/system-classes'; import { Builder } from '../../builder'; @@ -170,6 +170,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { onLoaded() { if (!this.isLoaded) { + const { TouchManager } = require('../../gestures/touch-manager'); const enableTapAnimations = TouchManager.enableGlobalTapAnimations && (this.hasListeners('tap') || this.hasListeners('tapChange') || this.getGestureObservers(GestureTypes.tap)); if (!this.ignoreTouchAnimation && (this.touchAnimation || enableTapAnimations)) { // console.log('view:', Object.keys((this)._observers)); diff --git a/packages/core/ui/core/weak-event-listener/index.ts b/packages/core/ui/core/weak-event-listener/index.ts index 41b5ec8a3..c48d1bba0 100644 --- a/packages/core/ui/core/weak-event-listener/index.ts +++ b/packages/core/ui/core/weak-event-listener/index.ts @@ -36,7 +36,7 @@ function getHandlerForEventName(eventName: string): (eventData: EventData) => vo let target; for (let i = 0; i < targetHandlerPairList.length; i++) { pair = targetHandlerPairList[i]; - target = pair.tagetRef.get(); + target = pair.tagetRef.deref(); if (target) { pair.handler.call(target, eventData); } else { @@ -130,7 +130,7 @@ export function removeWeakEventListener(source: Observable, eventName: string, h for (let i = 0; i < targetHandlerPairList.length; i++) { pair = targetHandlerPairList[i]; - registeredTarget = pair.tagetRef.get(); + registeredTarget = pair.tagetRef.deref(); if (!registeredTarget || (registeredTarget === target && handler === pair.handler)) { targetHandlerPairsToRemove.push(i); } diff --git a/packages/core/ui/editable-text-base/index.android.ts b/packages/core/ui/editable-text-base/index.android.ts index cab7db0e1..45f29e4dd 100644 --- a/packages/core/ui/editable-text-base/index.android.ts +++ b/packages/core/ui/editable-text-base/index.android.ts @@ -60,23 +60,23 @@ function initializeEditTextListeners(): void { } public beforeTextChanged(text: string, start: number, count: number, after: number): void { - this.owner?.get()?.beforeTextChanged(text, start, count, after); + this.owner?.deref()?.beforeTextChanged(text, start, count, after); } public onTextChanged(text: string, start: number, before: number, count: number): void { - this.owner?.get()?.onTextChanged(text, start, before, count); + this.owner?.deref()?.onTextChanged(text, start, before, count); } public afterTextChanged(editable: android.text.Editable): void { - this.owner?.get()?.afterTextChanged(editable); + this.owner?.deref()?.afterTextChanged(editable); } public onFocusChange(view: android.view.View, hasFocus: boolean): void { - this.owner?.get()?.onFocusChange(view, hasFocus); + this.owner?.deref()?.onFocusChange(view, hasFocus); } public onEditorAction(textView: android.widget.TextView, actionId: number, event: android.view.KeyEvent): boolean { - return this.owner?.get()?.onEditorAction(textView, actionId, event) || false; + return this.owner?.deref()?.onEditorAction(textView, actionId, event) || false; } } diff --git a/packages/core/ui/frame/index.android.ts b/packages/core/ui/frame/index.android.ts index 340604e53..f04d504aa 100644 --- a/packages/core/ui/frame/index.android.ts +++ b/packages/core/ui/frame/index.android.ts @@ -807,7 +807,7 @@ function startActivity(activity: androidx.appcompat.app.AppCompatActivity, frame function getFrameByNumberId(frameId: number): Frame { // Find the frame for this activity. for (let i = 0; i < framesCache.length; i++) { - const aliveFrame = framesCache[i].get(); + const aliveFrame = framesCache[i].deref(); if (aliveFrame && aliveFrame.frameId === frameId) { return aliveFrame.owner; } @@ -1050,7 +1050,7 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { // also, to be compatible with fragments 1.2.x we need this setTimeout as animations haven't run on onResume yet const weakRef = new WeakRef(this); setTimeout(() => { - const owner = weakRef.get(); + const owner = weakRef.deref(); if (!owner) { return; } @@ -1133,7 +1133,7 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks { if (savedInstanceState) { const rootViewId = savedInstanceState.getInt(ROOT_VIEW_ID_EXTRA, -1); if (rootViewId !== -1 && activityRootViewsMap.has(rootViewId)) { - this._rootView = activityRootViewsMap.get(rootViewId)?.get(); + this._rootView = activityRootViewsMap.get(rootViewId)?.deref(); } } diff --git a/packages/core/ui/gestures/gestures-common.ts b/packages/core/ui/gestures/gestures-common.ts index 434b80bd5..623eb930a 100644 --- a/packages/core/ui/gestures/gestures-common.ts +++ b/packages/core/ui/gestures/gestures-common.ts @@ -2,8 +2,6 @@ import type { View } from '../core/view'; import type { EventData } from '../../data/observable'; -export * from './touch-manager'; - /** * Events emitted during gesture lifecycle */ diff --git a/packages/core/ui/image-cache/index.android.ts b/packages/core/ui/image-cache/index.android.ts index 00a1c6775..a43400c84 100644 --- a/packages/core/ui/image-cache/index.android.ts +++ b/packages/core/ui/image-cache/index.android.ts @@ -42,7 +42,7 @@ export class Cache extends common.Cache { const that = new WeakRef(this); this._callback = new org.nativescript.widgets.Async.CompleteCallback({ onComplete: function (result: any, context: any) { - const instance = that?.get(); + const instance = that?.deref(); if (instance) { if (result) { instance._onDownloadCompleted(context, result); @@ -52,7 +52,7 @@ export class Cache extends common.Cache { } }, onError: function (err: string, context: any) { - const instance = that?.get(); + const instance = that?.deref(); if (instance) { instance._onDownloadError(context, new Error(err)); } diff --git a/packages/core/ui/index.ts b/packages/core/ui/index.ts index 703df4784..9c135942d 100644 --- a/packages/core/ui/index.ts +++ b/packages/core/ui/index.ts @@ -27,7 +27,8 @@ export * from './editable-text-base'; export { Frame, setActivityCallbacks } from './frame'; export type { NavigationEntry, NavigationContext, NavigationTransition, BackstackEntry, ViewEntry, AndroidActivityCallbacks } from './frame'; -export { GesturesObserver, TouchAction, GestureTypes, GestureStateTypes, SwipeDirection, GestureEvents, TouchManager } from './gestures'; +export { GesturesObserver, TouchAction, GestureTypes, GestureStateTypes, SwipeDirection, GestureEvents } from './gestures'; +export { TouchManager } from './gestures/touch-manager'; export type { GestureEventData, GestureEventDataWithState, TapGestureEventData, PanGestureEventData, PinchGestureEventData, RotationGestureEventData, SwipeGestureEventData, TouchGestureEventData, TouchAnimationOptions } from './gestures'; export { HtmlView } from './html-view'; diff --git a/packages/core/ui/page/index.ios.ts b/packages/core/ui/page/index.ios.ts index 48063ee9a..e83c420c2 100644 --- a/packages/core/ui/page/index.ios.ts +++ b/packages/core/ui/page/index.ios.ts @@ -371,7 +371,7 @@ class UIViewControllerImpl extends UIViewController { // TODO: a11y // public accessibilityPerformEscape() { - // const owner = this._owner.get(); + // const owner = this._owner.deref(); // if (!owner) { // return false; // } diff --git a/packages/core/ui/scroll-view/index.android.ts b/packages/core/ui/scroll-view/index.android.ts index 5b0b2b1e6..a82dc0a05 100644 --- a/packages/core/ui/scroll-view/index.android.ts +++ b/packages/core/ui/scroll-view/index.android.ts @@ -133,7 +133,7 @@ export class ScrollView extends ScrollViewBase { const viewRef = new WeakRef(this); this.handler = new android.view.ViewTreeObserver.OnScrollChangedListener({ onScrollChanged: function () { - const owner: ScrollView = viewRef.get(); + const owner: ScrollView = viewRef.deref(); if (owner) { owner._onScrollChanged(); } diff --git a/packages/core/ui/styling/style-properties.ts b/packages/core/ui/styling/style-properties.ts index 0ee71247a..f6ad2d7c3 100644 --- a/packages/core/ui/styling/style-properties.ts +++ b/packages/core/ui/styling/style-properties.ts @@ -191,7 +191,7 @@ export const minWidthProperty = new CssProperty({ affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.effectiveMinWidth = Length.toDevicePixels(newValue, 0); } else { @@ -209,7 +209,7 @@ export const minHeightProperty = new CssProperty({ affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.effectiveMinHeight = Length.toDevicePixels(newValue, 0); } else { @@ -229,7 +229,7 @@ export const widthProperty = new CssAnimationProperty { if (global.isIOS) { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.requestLayout(); } @@ -248,7 +248,7 @@ export const heightProperty = new CssAnimationProperty { if (global.isIOS) { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.requestLayout(); } @@ -333,7 +333,7 @@ export const paddingLeftProperty = new CssProperty( affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.effectivePaddingLeft = Length.toDevicePixels(newValue, 0); } else { @@ -351,7 +351,7 @@ export const paddingRightProperty = new CssProperty affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.effectivePaddingRight = Length.toDevicePixels(newValue, 0); } else { @@ -369,7 +369,7 @@ export const paddingTopProperty = new CssProperty({ affectsLayout: global.isIOS, equalityComparer: Length.equals, valueChanged: (target, oldValue, newValue) => { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.effectivePaddingTop = Length.toDevicePixels(newValue, 0); } else { @@ -387,7 +387,7 @@ export const paddingBottomProperty = new CssProperty { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.effectivePaddingBottom = Length.toDevicePixels(newValue, 0); } else { @@ -1041,7 +1041,7 @@ export const borderTopWidthProperty = new CssProperty { - const view = target.viewRef.get(); + const view = target.viewRef.deref(); if (view) { view.isCollapsed = newValue === CoreTypes.Visibility.collapse; } else { diff --git a/packages/core/ui/styling/style-scope.ts b/packages/core/ui/styling/style-scope.ts index a71ff6f9e..60804ba61 100644 --- a/packages/core/ui/styling/style-scope.ts +++ b/packages/core/ui/styling/style-scope.ts @@ -427,7 +427,7 @@ export class CssState { * As a result, at some point in time, the selectors matched have to be requerried from the style scope and applied to the view. */ public onChange(): void { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (view && view.isLoaded) { this.unsubscribeFromDynamicUpdates(); this.updateMatch(); @@ -439,14 +439,14 @@ export class CssState { } public isSelectorsLatestVersionApplied(): boolean { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`isSelectorsLatestVersionApplied returns default value "false" because "this.viewRef" cleared.`, Trace.categories.Style, Trace.messageType.warn); return false; } - return this.viewRef.get()._styleScope.getSelectorsVersion() === this._appliedSelectorsVersion; + return this.viewRef.deref()._styleScope.getSelectorsVersion() === this._appliedSelectorsVersion; } public onLoaded(): void { @@ -464,7 +464,7 @@ export class CssState { @profile private updateMatch() { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (view && view._styleScope) { this._match = view._styleScope.matchSelectors(view); this._appliedSelectorsVersion = view._styleScope.getSelectorsVersion(); @@ -477,7 +477,7 @@ export class CssState { @profile private updateDynamicState(): void { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`updateDynamicState not executed to view because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn); @@ -515,7 +515,7 @@ export class CssState { }); if ((this._playsKeyframeAnimations = animations.length > 0)) { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`KeyframeAnimations cannot play because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn); @@ -536,7 +536,7 @@ export class CssState { this._appliedAnimations.filter((animation) => animation.isPlaying).forEach((animation) => animation.cancel()); this._appliedAnimations = CssState.emptyAnimationArray; - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (view) { view.style['keyframe:rotate'] = unsetValue; view.style['keyframe:rotateX'] = unsetValue; @@ -561,7 +561,7 @@ export class CssState { * @param matchingSelectors */ private setPropertyValues(matchingSelectors: SelectorCore[]): void { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`${matchingSelectors} not set to view's property because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn); return; @@ -688,7 +688,7 @@ export class CssState { } toString(): string { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`toString() of CssState cannot execute correctly because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn); diff --git a/packages/core/ui/styling/style/index.ts b/packages/core/ui/styling/style/index.ts index 3d501521b..53ca31dad 100644 --- a/packages/core/ui/styling/style/index.ts +++ b/packages/core/ui/styling/style/index.ts @@ -95,7 +95,7 @@ export class Style extends Observable implements StyleDefinition { } toString() { - const view = this.viewRef.get(); + const view = this.viewRef.deref(); if (!view) { Trace.write(`toString() of Style cannot execute correctly because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn); @@ -249,7 +249,7 @@ export class Style extends Observable implements StyleDefinition { public get view(): ViewBase { if (this.viewRef) { - return this.viewRef.get(); + return this.viewRef.deref(); } return undefined; diff --git a/packages/core/ui/tab-view/index.android.ts b/packages/core/ui/tab-view/index.android.ts index 030bfd6f9..f7dff0410 100644 --- a/packages/core/ui/tab-view/index.android.ts +++ b/packages/core/ui/tab-view/index.android.ts @@ -33,12 +33,12 @@ function makeFragmentName(viewId: number, id: number): string { function getTabById(id: number): TabView { const ref = tabs.find((ref) => { - const tab = ref.get(); + const tab = ref.deref(); return tab && tab._domId === id; }); - return ref && ref.get(); + return ref && ref.deref(); } function initializeNativeClasses() { diff --git a/packages/core/ui/text-base/index.android.ts b/packages/core/ui/text-base/index.android.ts index 6c1535573..bdffcd20e 100644 --- a/packages/core/ui/text-base/index.android.ts +++ b/packages/core/ui/text-base/index.android.ts @@ -83,7 +83,7 @@ function initializeClickableSpan(): void { return global.__native(this); } onClick(view: android.view.View): void { - const owner = this.owner?.get(); + const owner = this.owner?.deref(); if (owner) { owner._emit(Span.linkTapEvent); } diff --git a/packages/core/ui/web-view/index.ios.ts b/packages/core/ui/web-view/index.ios.ts index 9e8f4acc2..0047e3c2a 100644 --- a/packages/core/ui/web-view/index.ios.ts +++ b/packages/core/ui/web-view/index.ios.ts @@ -116,8 +116,9 @@ class WKUIDelegateImpl extends NSObject implements WKUIDelegate { } @NativeClass -@ObjCClass(UIScrollViewDelegate) class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate { + public static ObjCProtocols = [UIScrollViewDelegate]; + public static initWithOwner(owner: WeakRef): UIScrollViewDelegateImpl { const handler = UIScrollViewDelegateImpl.new(); handler._owner = owner;