mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
fix circular imports and change weakref.get->deref
This commit is contained in:
@ -121,9 +121,9 @@ export function buildUIWithWeakRefAndInteract<T extends View>(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<T extends View>(createFunc: () =>
|
||||
}
|
||||
Utils.GC();
|
||||
try {
|
||||
TKUnit.assert(!weakRef.get(), weakRef.get() + ' leaked!');
|
||||
TKUnit.assert(!weakRef.deref(), weakRef.deref() + ' leaked!');
|
||||
done(null);
|
||||
} catch (ex) {
|
||||
done(ex);
|
||||
|
@ -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) {
|
||||
|
@ -104,12 +104,12 @@ function getTargetAsWeakRef(): WeakRef<Target> {
|
||||
// // 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<Target> {
|
||||
// // 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);
|
||||
|
@ -626,9 +626,9 @@ export class ListViewTest extends UITest<ListView> {
|
||||
|
||||
public test_no_memory_leak_when_items_is_regular_array() {
|
||||
let weakRef = new WeakRef<ListView>(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<ListView> {
|
||||
var colors = new ObservableArray(['red', 'green', 'blue']);
|
||||
|
||||
let weakRef = new WeakRef<ListView>(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<ListView> {
|
||||
}
|
||||
|
||||
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<ListView> {
|
||||
// }
|
||||
// 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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 [];
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ export const androidContentInsetLeftProperty = new CssProperty<Style, CoreTypes.
|
||||
defaultValue: 'auto',
|
||||
equalityComparer: Length.equals,
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
const view = <ActionBarBase>target.viewRef.get();
|
||||
const view = <ActionBarBase>target.viewRef.deref();
|
||||
if (view) {
|
||||
view.effectiveContentInsetLeft = Length.toDevicePixels(newValue);
|
||||
} else {
|
||||
@ -451,7 +451,7 @@ export const androidContentInsetRightProperty = new CssProperty<Style, CoreTypes
|
||||
defaultValue: 'auto',
|
||||
equalityComparer: Length.equals,
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
const view = <ActionBarBase>target.viewRef.get();
|
||||
const view = <ActionBarBase>target.viewRef.deref();
|
||||
if (view) {
|
||||
view.effectiveContentInsetRight = Length.toDevicePixels(newValue);
|
||||
} else {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<Object>, sourceProperty: Array<string>, 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((<Error>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<any>; property: string }, value: any) {
|
||||
let optionsInstance;
|
||||
if (options && options.instance) {
|
||||
optionsInstance = options.instance.get();
|
||||
optionsInstance = options.instance.deref();
|
||||
}
|
||||
|
||||
if (!optionsInstance) {
|
||||
|
@ -645,7 +645,7 @@ export class CssProperty<T extends Style, U> implements CssProperty<T, U> {
|
||||
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<T extends Style, U> implements CssProperty<T, U> {
|
||||
}
|
||||
|
||||
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<T extends Style, U> 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<T extends Style, U> 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<T extends Style, U> extends CssProperty<T, U>
|
||||
|
||||
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<T extends Style, P> 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<T extends Style, P> 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);
|
||||
|
||||
|
@ -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;
|
||||
// }
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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((<any>this)._observers));
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
// }
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ export const minWidthProperty = new CssProperty<Style, CoreTypes.LengthType>({
|
||||
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<Style, CoreTypes.LengthType>({
|
||||
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<Style, CoreTypes.PercentLe
|
||||
// on the animation property, so fake it here. x_x
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
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<Style, CoreTypes.PercentL
|
||||
// on the animation property, so fake it here. -_-
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
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<Style, CoreTypes.LengthType>(
|
||||
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<Style, CoreTypes.LengthType>
|
||||
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<Style, CoreTypes.LengthType>({
|
||||
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<Style, CoreTypes.LengthType
|
||||
affectsLayout: global.isIOS,
|
||||
equalityComparer: Length.equals,
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
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<Style, CoreTypes.LengthTyp
|
||||
throw new Error(`border-top-width should be Non-Negative Finite number. Value: ${value}`);
|
||||
}
|
||||
|
||||
const view = target.viewRef.get();
|
||||
const view = target.viewRef.deref();
|
||||
if (view) {
|
||||
view.effectiveBorderTopWidth = value;
|
||||
} else {
|
||||
@ -1065,7 +1065,7 @@ export const borderRightWidthProperty = new CssProperty<Style, CoreTypes.LengthT
|
||||
throw new Error(`border-right-width should be Non-Negative Finite number. Value: ${value}`);
|
||||
}
|
||||
|
||||
const view = target.viewRef.get();
|
||||
const view = target.viewRef.deref();
|
||||
if (view) {
|
||||
view.effectiveBorderRightWidth = value;
|
||||
} else {
|
||||
@ -1089,7 +1089,7 @@ export const borderBottomWidthProperty = new CssProperty<Style, CoreTypes.Length
|
||||
throw new Error(`border-bottom-width should be Non-Negative Finite number. Value: ${value}`);
|
||||
}
|
||||
|
||||
const view = target.viewRef.get();
|
||||
const view = target.viewRef.deref();
|
||||
if (view) {
|
||||
view.effectiveBorderBottomWidth = value;
|
||||
} else {
|
||||
@ -1113,7 +1113,7 @@ export const borderLeftWidthProperty = new CssProperty<Style, CoreTypes.LengthTy
|
||||
throw new Error(`border-left-width should be Non-Negative Finite number. Value: ${value}`);
|
||||
}
|
||||
|
||||
const view = target.viewRef.get();
|
||||
const view = target.viewRef.deref();
|
||||
if (view) {
|
||||
view.effectiveBorderLeftWidth = value;
|
||||
} else {
|
||||
@ -1448,7 +1448,7 @@ export const visibilityProperty = new CssProperty<Style, CoreTypes.VisibilityTyp
|
||||
affectsLayout: global.isIOS,
|
||||
valueConverter: CoreTypes.Visibility.parse,
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
const view = target.viewRef.get();
|
||||
const view = target.viewRef.deref();
|
||||
if (view) {
|
||||
view.isCollapsed = newValue === CoreTypes.Visibility.collapse;
|
||||
} else {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<WebView>): UIScrollViewDelegateImpl {
|
||||
const handler = <UIScrollViewDelegateImpl>UIScrollViewDelegateImpl.new();
|
||||
handler._owner = owner;
|
||||
|
Reference in New Issue
Block a user