| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 81e1f54 commit dfe7621
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,12 @@ import { ViewBase } from "../view-base"; | |||
| 4 | 4 | ||
| 5 | 5 | // Types. | |
| 6 | 6 | import { WrappedValue, PropertyChangeData } from "../../../data/observable"; | |
| 7 | + import { | ||
| 8 | + write as traceWrite, | ||
| 9 | + categories as traceCategories, | ||
| 10 | + messageType as traceMessageType, | ||
| 11 | + } from "../../../trace"; | ||
| 12 | + | ||
| 7 | 13 | import { Style } from "../../styling/style"; | |
| 8 | 14 | ||
| 9 | 15 | import { profile } from "../../../profiling"; | |
@@ -125,7 +131,7 @@ export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor< | |||
| 125 | 131 | if (affectsLayout) { | |
| 126 | 132 | this.requestLayout(); | |
| 127 | 133 | } | |
| 128 | - | ||
| 134 | + | ||
| 129 | 135 | if (reset) { | |
| 130 | 136 | delete this[key]; | |
| 131 | 137 | if (valueChanged) { | |
@@ -466,6 +472,13 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty< | |||
| 466 | 472 | const property = this; | |
| 467 | 473 | ||
| 468 | 474 | function setLocalValue(this: T, newValue: U | string): void { | |
| 475 | + const view = this.viewRef.get(); | ||
| 476 | + if (!view) { | ||
| 477 | + traceWrite(`${newValue} not set to view because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 478 | + | ||
| 479 | + return; | ||
| 480 | + } | ||
| 481 | + | ||
| 469 | 482 | const reset = newValue === unsetValue || newValue === ""; | |
| 470 | 483 | let value: U; | |
| 471 | 484 | if (reset) { | |
@@ -482,7 +495,6 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty< | |||
| 482 | 495 | const changed: boolean = equalityComparer ? !equalityComparer(oldValue, value) : oldValue !== value; | |
| 483 | 496 | ||
| 484 | 497 | if (changed) { | |
| 485 | - const view = this.view; | ||
| 486 | 498 | if (reset) { | |
| 487 | 499 | delete this[key]; | |
| 488 | 500 | if (valueChanged) { | |
@@ -534,6 +546,13 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty< | |||
| 534 | 546 | } | |
| 535 | 547 | ||
| 536 | 548 | function setCssValue(this: T, newValue: U | string): void { | |
| 549 | + const view = this.viewRef.get(); | ||
| 550 | + if (!view) { | ||
| 551 | + traceWrite(`${newValue} not set to view because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 552 | + | ||
| 553 | + return; | ||
| 554 | + } | ||
| 555 | + | ||
| 537 | 556 | const currentValueSource: number = this[sourceKey] || ValueSource.Default; | |
| 538 | 557 | ||
| 539 | 558 | // We have localValueSource - NOOP. | |
@@ -557,7 +576,6 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty< | |||
| 557 | 576 | const changed: boolean = equalityComparer ? !equalityComparer(oldValue, value) : oldValue !== value; | |
| 558 | 577 | ||
| 559 | 578 | if (changed) { | |
| 560 | - const view = this.view; | ||
| 561 | 579 | if (reset) { | |
| 562 | 580 | delete this[key]; | |
| 563 | 581 | if (valueChanged) { | |
@@ -718,12 +736,18 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css | |||
| 718 | 736 | enumerable, configurable, | |
| 719 | 737 | get: getsComputed ? function (this: T) { return this[computedValue]; } : function (this: T) { return this[symbol]; }, | |
| 720 | 738 | set(this: T, boxedValue: U | string) { | |
| 739 | + const view = this.viewRef.get(); | ||
| 740 | + if (!view) { | ||
| 741 | + traceWrite(`${boxedValue} not set to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn); | ||
| 742 | + | ||
| 743 | + return; | ||
| 744 | + } | ||
| 721 | 745 | ||
| 722 | 746 | const oldValue = this[computedValue]; | |
| 723 | 747 | const oldSource = this[computedSource]; | |
| 724 | 748 | const wasSet = oldSource !== ValueSource.Default; | |
| 725 | 749 | const reset = boxedValue === unsetValue || boxedValue === ""; | |
| 726 | - | ||
| 750 | + | ||
| 727 | 751 | if (reset) { | |
| 728 | 752 | this[symbol] = unsetValue; | |
| 729 | 753 | if (this[computedSource] === propertySource) { | |
@@ -760,7 +784,6 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css | |||
| 760 | 784 | valueChanged(this, oldValue, value); | |
| 761 | 785 | } | |
| 762 | 786 | ||
| 763 | - const view = this.view; | ||
| 764 | 787 | if (view[setNative] && (computedValueChanged || isSet !== wasSet)) { | |
| 765 | 788 | if (view._suspendNativeUpdatesCount) { | |
| 766 | 789 | if (view._suspendedUpdates) { | |
@@ -816,10 +839,16 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css | |||
| 816 | 839 | } | |
| 817 | 840 | ||
| 818 | 841 | public _initDefaultNativeValue(target: T): void { | |
| 842 | + const view = target.viewRef.get(); | ||
| 843 | + if (!view) { | ||
| 844 | + traceWrite(`_initDefaultNativeValue not executed to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn); | ||
| 845 | + | ||
| 846 | + return; | ||
| 847 | + } | ||
| 848 | + | ||
| 819 | 849 | const defaultValueKey = this.defaultValueKey; | |
| 820 | 850 | ||
| 821 | 851 | if (!(defaultValueKey in target)) { | |
| 822 | - const view = target.view; | ||
| 823 | 852 | const getDefault = this.getDefault; | |
| 824 | 853 | target[defaultValueKey] = view[getDefault] ? view[getDefault]() : this.defaultValue; | |
| 825 | 854 | } | |
@@ -862,6 +891,13 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U> | |||
| 862 | 891 | const property = this; | |
| 863 | 892 | ||
| 864 | 893 | const setFunc = (valueSource: ValueSource) => function (this: T, boxedValue: any): void { | |
| 894 | + const view = this.viewRef.get(); | ||
| 895 | + if (!view) { | ||
| 896 | + traceWrite(`${boxedValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 897 | + | ||
| 898 | + return; | ||
| 899 | + } | ||
| 900 | + | ||
| 865 | 901 | const reset = boxedValue === unsetValue || boxedValue === ""; | |
| 866 | 902 | const currentValueSource: number = this[sourceKey] || ValueSource.Default; | |
| 867 | 903 | if (reset) { | |
@@ -876,7 +912,6 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U> | |||
| 876 | 912 | } | |
| 877 | 913 | ||
| 878 | 914 | const oldValue: U = key in this ? this[key] : defaultValue; | |
| 879 | - const view = this.view; | ||
| 880 | 915 | let value: U; | |
| 881 | 916 | let unsetNativeValue = false; | |
| 882 | 917 | if (reset) { | |
@@ -907,7 +942,6 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U> | |||
| 907 | 942 | const changed: boolean = equalityComparer ? !equalityComparer(oldValue, value) : oldValue !== value; | |
| 908 | 943 | ||
| 909 | 944 | if (changed) { | |
| 910 | - const view = this.view; | ||
| 911 | 945 | if (valueChanged) { | |
| 912 | 946 | valueChanged(this, oldValue, value); | |
| 913 | 947 | } | |
@@ -997,15 +1031,29 @@ export class ShorthandProperty<T extends Style, P> implements definitions.Shorth | |||
| 997 | 1031 | const converter = options.converter; | |
| 998 | 1032 | ||
| 999 | 1033 | function setLocalValue(this: T, value: string | P): void { | |
| 1000 | - this.view._batchUpdate(() => { | ||
| 1034 | + const view = this.viewRef.get(); | ||
| 1035 | + if (!view) { | ||
| 1036 | + traceWrite(`setLocalValue not executed to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn); | ||
| 1037 | + | ||
| 1038 | + return; | ||
| 1039 | + } | ||
| 1040 | + | ||
| 1041 | + view._batchUpdate(() => { | ||
| 1001 | 1042 | for (let [p, v] of converter(value)) { | |
| 1002 | 1043 | this[p.name] = v; | |
| 1003 | 1044 | } | |
| 1004 | 1045 | }); | |
| 1005 | 1046 | } | |
| 1006 | 1047 | ||
| 1007 | 1048 | function setCssValue(this: T, value: string): void { | |
| 1008 | - this.view._batchUpdate(() => { | ||
| 1049 | + const view = this.viewRef.get(); | ||
| 1050 | + if (!view) { | ||
| 1051 | + traceWrite(`setCssValue not executed to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn); | ||
| 1052 | + | ||
| 1053 | + return; | ||
| 1054 | + } | ||
| 1055 | + | ||
| 1056 | + view._batchUpdate(() => { | ||
| 1009 | 1057 | for (let [p, v] of converter(value)) { | |
| 1010 | 1058 | this[p.cssName] = v; | |
| 1011 | 1059 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -192,7 +192,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition | |||
| 192 | 192 | public _domId: number; | |
| 193 | 193 | public _context: any; | |
| 194 | 194 | public _isAddedToNativeVisualTree: boolean; | |
| 195 | - public _cssState: ssm.CssState = new ssm.CssState(this); | ||
| 195 | + public _cssState: ssm.CssState = new ssm.CssState(new WeakRef(this)); | ||
| 196 | 196 | public _styleScope: ssm.StyleScope; | |
| 197 | 197 | public _suspendedUpdates: { [propertyName: string]: Property<ViewBase, any> | CssProperty<Style, any> | CssAnimationProperty<Style, any> }; | |
| 198 | 198 | public _suspendNativeUpdatesCount: SuspendType; | |
@@ -249,7 +249,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition | |||
| 249 | 249 | constructor() { | |
| 250 | 250 | super(); | |
| 251 | 251 | this._domId = viewIdCounter++; | |
| 252 | - this._style = new Style(this); | ||
| 252 | + this._style = new Style(new WeakRef(this)); | ||
| 253 | 253 | } | |
| 254 | 254 | ||
| 255 | 255 | // Used in Angular. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -154,6 +154,8 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 154 | 154 | } else { | |
| 155 | 155 | page._tearDownUI(true); | |
| 156 | 156 | } | |
| 157 | + | ||
| 158 | + removed.resolvedPage = null; | ||
| 157 | 159 | } | |
| 158 | 160 | ||
| 159 | 161 | // Attempts to implement https://github.com/NativeScript/NativeScript/issues/1311 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,11 @@ import { | |||
| 25 | 25 | matrixArrayToCssMatrix, | |
| 26 | 26 | multiplyAffine2d, | |
| 27 | 27 | } from "../../matrix"; | |
| 28 | + import { | ||
| 29 | + write as traceWrite, | ||
| 30 | + categories as traceCategories, | ||
| 31 | + messageType as traceMessageType, | ||
| 32 | + } from "../../trace"; | ||
| 28 | 33 | ||
| 29 | 34 | import * as parser from "../../css/parser"; | |
| 30 | 35 | import { LinearGradient } from "./linear-gradient"; | |
@@ -175,15 +180,25 @@ export const zeroLength: Length = { value: 0, unit: "px" }; | |||
| 175 | 180 | export const minWidthProperty = new CssProperty<Style, Length>({ | |
| 176 | 181 | name: "minWidth", cssName: "min-width", defaultValue: zeroLength, affectsLayout: isIOS, equalityComparer: Length.equals, | |
| 177 | 182 | valueChanged: (target, oldValue, newValue) => { | |
| 178 | - target.view.effectiveMinWidth = Length.toDevicePixels(newValue, 0); | ||
| 183 | + const view = target.viewRef.get(); | ||
| 184 | + if (view) { | ||
| 185 | + view.effectiveMinWidth = Length.toDevicePixels(newValue, 0); | ||
| 186 | + } else { | ||
| 187 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 188 | + } | ||
| 179 | 189 | }, valueConverter: Length.parse | |
| 180 | 190 | }); | |
| 181 | 191 | minWidthProperty.register(Style); | |
| 182 | 192 | ||
| 183 | 193 | export const minHeightProperty = new CssProperty<Style, Length>({ | |
| 184 | 194 | name: "minHeight", cssName: "min-height", defaultValue: zeroLength, affectsLayout: isIOS, equalityComparer: Length.equals, | |
| 185 | 195 | valueChanged: (target, oldValue, newValue) => { | |
| 186 | - target.view.effectiveMinHeight = Length.toDevicePixels(newValue, 0); | ||
| 196 | + const view = target.viewRef.get(); | ||
| 197 | + if (view) { | ||
| 198 | + view.effectiveMinHeight = Length.toDevicePixels(newValue, 0); | ||
| 199 | + } else { | ||
| 200 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 201 | + } | ||
| 187 | 202 | }, valueConverter: Length.parse | |
| 188 | 203 | }); | |
| 189 | 204 | minHeightProperty.register(Style); | |
@@ -237,31 +252,51 @@ paddingProperty.register(Style); | |||
| 237 | 252 | export const paddingLeftProperty = new CssProperty<Style, Length>({ | |
| 238 | 253 | name: "paddingLeft", cssName: "padding-left", defaultValue: zeroLength, affectsLayout: isIOS, equalityComparer: Length.equals, | |
| 239 | 254 | valueChanged: (target, oldValue, newValue) => { | |
| 240 | - target.view.effectivePaddingLeft = Length.toDevicePixels(newValue, 0); | ||
| 255 | + const view = target.viewRef.get(); | ||
| 256 | + if (view) { | ||
| 257 | + view.effectivePaddingLeft = Length.toDevicePixels(newValue, 0); | ||
| 258 | + } else { | ||
| 259 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 260 | + } | ||
| 241 | 261 | }, valueConverter: Length.parse | |
| 242 | 262 | }); | |
| 243 | 263 | paddingLeftProperty.register(Style); | |
| 244 | 264 | ||
| 245 | 265 | export const paddingRightProperty = new CssProperty<Style, Length>({ | |
| 246 | 266 | name: "paddingRight", cssName: "padding-right", defaultValue: zeroLength, affectsLayout: isIOS, equalityComparer: Length.equals, | |
| 247 | 267 | valueChanged: (target, oldValue, newValue) => { | |
| 248 | - target.view.effectivePaddingRight = Length.toDevicePixels(newValue, 0); | ||
| 268 | + const view = target.viewRef.get(); | ||
| 269 | + if (view) { | ||
| 270 | + view.effectivePaddingRight = Length.toDevicePixels(newValue, 0); | ||
| 271 | + } else { | ||
| 272 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 273 | + } | ||
| 249 | 274 | }, valueConverter: Length.parse | |
| 250 | 275 | }); | |
| 251 | 276 | paddingRightProperty.register(Style); | |
| 252 | 277 | ||
| 253 | 278 | export const paddingTopProperty = new CssProperty<Style, Length>({ | |
| 254 | 279 | name: "paddingTop", cssName: "padding-top", defaultValue: zeroLength, affectsLayout: isIOS, equalityComparer: Length.equals, | |
| 255 | 280 | valueChanged: (target, oldValue, newValue) => { | |
| 256 | - target.view.effectivePaddingTop = Length.toDevicePixels(newValue, 0); | ||
| 281 | + const view = target.viewRef.get(); | ||
| 282 | + if (view) { | ||
| 283 | + view.effectivePaddingTop = Length.toDevicePixels(newValue, 0); | ||
| 284 | + } else { | ||
| 285 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 286 | + } | ||
| 257 | 287 | }, valueConverter: Length.parse | |
| 258 | 288 | }); | |
| 259 | 289 | paddingTopProperty.register(Style); | |
| 260 | 290 | ||
| 261 | 291 | export const paddingBottomProperty = new CssProperty<Style, Length>({ | |
| 262 | 292 | name: "paddingBottom", cssName: "padding-bottom", defaultValue: zeroLength, affectsLayout: isIOS, equalityComparer: Length.equals, | |
| 263 | 293 | valueChanged: (target, oldValue, newValue) => { | |
| 264 | - target.view.effectivePaddingBottom = Length.toDevicePixels(newValue, 0); | ||
| 294 | + const view = target.viewRef.get(); | ||
| 295 | + if (view) { | ||
| 296 | + view.effectivePaddingBottom = Length.toDevicePixels(newValue, 0); | ||
| 297 | + } else { | ||
| 298 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 299 | + } | ||
| 265 | 300 | }, valueConverter: Length.parse | |
| 266 | 301 | }); | |
| 267 | 302 | paddingBottomProperty.register(Style); | |
@@ -822,7 +857,12 @@ export const borderTopWidthProperty = new CssProperty<Style, Length>({ | |||
| 822 | 857 | throw new Error(`border-top-width should be Non-Negative Finite number. Value: ${value}`); | |
| 823 | 858 | } | |
| 824 | 859 | ||
| 825 | - target.view.effectiveBorderTopWidth = value; | ||
| 860 | + const view = target.viewRef.get(); | ||
| 861 | + if (view) { | ||
| 862 | + view.effectiveBorderTopWidth = value; | ||
| 863 | + } else { | ||
| 864 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 865 | + } | ||
| 826 | 866 | const background = target.backgroundInternal.withBorderTopWidth(value); | |
| 827 | 867 | target.backgroundInternal = background; | |
| 828 | 868 | }, valueConverter: Length.parse | |
@@ -837,7 +877,12 @@ export const borderRightWidthProperty = new CssProperty<Style, Length>({ | |||
| 837 | 877 | throw new Error(`border-right-width should be Non-Negative Finite number. Value: ${value}`); | |
| 838 | 878 | } | |
| 839 | 879 | ||
| 840 | - target.view.effectiveBorderRightWidth = value; | ||
| 880 | + const view = target.viewRef.get(); | ||
| 881 | + if (view) { | ||
| 882 | + view.effectiveBorderRightWidth = value; | ||
| 883 | + } else { | ||
| 884 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 885 | + } | ||
| 841 | 886 | const background = target.backgroundInternal.withBorderRightWidth(value); | |
| 842 | 887 | target.backgroundInternal = background; | |
| 843 | 888 | }, valueConverter: Length.parse | |
@@ -852,7 +897,12 @@ export const borderBottomWidthProperty = new CssProperty<Style, Length>({ | |||
| 852 | 897 | throw new Error(`border-bottom-width should be Non-Negative Finite number. Value: ${value}`); | |
| 853 | 898 | } | |
| 854 | 899 | ||
| 855 | - target.view.effectiveBorderBottomWidth = value; | ||
| 900 | + const view = target.viewRef.get(); | ||
| 901 | + if (view) { | ||
| 902 | + view.effectiveBorderBottomWidth = value; | ||
| 903 | + } else { | ||
| 904 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 905 | + } | ||
| 856 | 906 | const background = target.backgroundInternal.withBorderBottomWidth(value); | |
| 857 | 907 | target.backgroundInternal = background; | |
| 858 | 908 | }, valueConverter: Length.parse | |
@@ -867,7 +917,12 @@ export const borderLeftWidthProperty = new CssProperty<Style, Length>({ | |||
| 867 | 917 | throw new Error(`border-left-width should be Non-Negative Finite number. Value: ${value}`); | |
| 868 | 918 | } | |
| 869 | 919 | ||
| 870 | - target.view.effectiveBorderLeftWidth = value; | ||
| 920 | + const view = target.viewRef.get(); | ||
| 921 | + if (view) { | ||
| 922 | + view.effectiveBorderLeftWidth = value; | ||
| 923 | + } else { | ||
| 924 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 925 | + } | ||
| 871 | 926 | const background = target.backgroundInternal.withBorderLeftWidth(value); | |
| 872 | 927 | target.backgroundInternal = background; | |
| 873 | 928 | }, valueConverter: Length.parse | |
@@ -1095,7 +1150,12 @@ export namespace Visibility { | |||
| 1095 | 1150 | ||
| 1096 | 1151 | export const visibilityProperty = new CssProperty<Style, Visibility>({ | |
| 1097 | 1152 | name: "visibility", cssName: "visibility", defaultValue: Visibility.VISIBLE, affectsLayout: isIOS, valueConverter: Visibility.parse, valueChanged: (target, oldValue, newValue) => { | |
| 1098 | - target.view.isCollapsed = (newValue === Visibility.COLLAPSE); | ||
| 1153 | + const view = target.viewRef.get(); | ||
| 1154 | + if (view) { | ||
| 1155 | + view.isCollapsed = (newValue === Visibility.COLLAPSE); | ||
| 1156 | + } else { | ||
| 1157 | + traceWrite(`${newValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn); | ||
| 1158 | + } | ||
| 1099 | 1159 | } | |
| 1100 | 1160 | }); | |
| 1101 | 1161 | visibilityProperty.register(Style); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments