File tree Expand file tree Collapse file tree 3 files changed +33
-35
lines changed
packages/core/ui/scroll-view Expand file tree Collapse file tree 3 files changed +33
-35
lines changed Original file line number Diff line number Diff line change @@ -130,10 +130,10 @@ export class ScrollView extends ScrollViewBase {
130130
131131 protected attachNative ( ) {
132132 if ( ! this . handler ) {
133- const that = new WeakRef ( this ) ;
133+ const viewRef = new WeakRef ( this ) ;
134134 this . handler = new android . view . ViewTreeObserver . OnScrollChangedListener ( {
135135 onScrollChanged : function ( ) {
136- const owner : ScrollView = that . get ( ) ;
136+ const owner : ScrollView = viewRef . get ( ) ;
137137 if ( owner ) {
138138 owner . _onScrollChanged ( ) ;
139139 }
@@ -166,9 +166,13 @@ export class ScrollView extends ScrollViewBase {
166166 }
167167 }
168168
169- protected dettachNative ( ) {
170- this . nativeViewProtected . getViewTreeObserver ( ) . removeOnScrollChangedListener ( this . handler ) ;
171- this . handler = null ;
169+ protected detachNative ( ) {
170+ if ( this . handler ) {
171+ if ( this . nativeViewProtected ) {
172+ this . nativeViewProtected . getViewTreeObserver ( ) . removeOnScrollChangedListener ( this . handler ) ;
173+ }
174+ this . handler = null ;
175+ }
172176 }
173177}
174178
Original file line number Diff line number Diff line change @@ -49,12 +49,6 @@ export class ScrollView extends ScrollViewBase {
4949 this . _setNativeClipToBounds ( ) ;
5050 }
5151
52- disposeNativeView ( ) {
53- this . dettachNative ( ) ;
54- this . _delegate = null ;
55- super . disposeNativeView ( ) ;
56- }
57-
5852 _setNativeClipToBounds ( ) {
5953 if ( ! this . nativeViewProtected ) {
6054 return ;
@@ -70,9 +64,12 @@ export class ScrollView extends ScrollViewBase {
7064 }
7165 }
7266
73- protected dettachNative ( ) {
74- if ( this . nativeViewProtected ) {
75- this . nativeViewProtected . delegate = null ;
67+ protected detachNative ( ) {
68+ if ( this . _delegate ) {
69+ if ( this . nativeViewProtected ) {
70+ this . nativeViewProtected . delegate = null ;
71+ }
72+ this . _delegate = null ;
7673 }
7774 }
7875
Original file line number Diff line number Diff line change @@ -21,48 +21,45 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe
2121
2222 if ( arg === ScrollViewBase . scrollEvent ) {
2323 this . _scrollChangeCount ++ ;
24- this . attach ( ) ;
24+ if ( this . nativeViewProtected ) {
25+ this . attachNative ( ) ;
26+ }
2527 }
2628 }
2729
2830 public removeEventListener ( arg : string , callback ?: ( data : EventData ) => void , thisArg ?: any ) : void {
2931 super . removeEventListener ( arg , callback , thisArg ) ;
3032
3133 if ( arg === ScrollViewBase . scrollEvent ) {
32- this . _scrollChangeCount -- ;
33- this . dettach ( ) ;
34- }
35- }
36-
37- @profile
38- public onLoaded ( ) {
39- super . onLoaded ( ) ;
40-
41- this . attach ( ) ;
42- }
34+ if ( this . _scrollChangeCount > 0 ) {
35+ this . _scrollChangeCount -- ;
4336
44- public disposeNativeView ( ) {
45- this . dettach ( ) ;
46- super . disposeNativeView ( ) ;
37+ if ( this . nativeViewProtected && this . _scrollChangeCount === 0 ) {
38+ this . detachNative ( ) ;
39+ }
40+ }
41+ }
4742 }
4843
49- private attach ( ) {
50- if ( this . _scrollChangeCount > 0 && this . isLoaded ) {
44+ initNativeView ( ) {
45+ super . initNativeView ( ) ;
46+ if ( this . _scrollChangeCount > 0 ) {
5147 this . attachNative ( ) ;
5248 }
5349 }
5450
55- private dettach ( ) {
56- if ( this . _scrollChangeCount === 0 && this . isLoaded ) {
57- this . dettachNative ( ) ;
51+ public disposeNativeView ( ) {
52+ if ( this . _scrollChangeCount > 0 ) {
53+ this . detachNative ( ) ;
5854 }
55+ super . disposeNativeView ( ) ;
5956 }
6057
6158 protected attachNative ( ) {
6259 //
6360 }
6461
65- protected dettachNative ( ) {
62+ protected detachNative ( ) {
6663 //
6764 }
6865
You can’t perform that action at this time.
0 commit comments