4
4
5
5
import 'dart:async' ;
6
6
import 'dart:html' ;
7
+ import 'dart:js' ;
7
8
8
9
import 'package:devtools/framework/framework.dart' ;
9
10
import 'package:meta/meta.dart' ;
@@ -13,7 +14,7 @@ import 'utils.dart';
13
14
14
15
// TODO(devoncarew): fixed position header
15
16
16
- class Table <T > extends Object with SetStateMixin , OnAddedToDomMixin {
17
+ class Table <T > extends Object with SetStateMixin {
17
18
Table ()
18
19
: element = div (a: 'flex' , c: 'overflow-y table-border' ),
19
20
_isVirtual = false ,
@@ -28,10 +29,16 @@ class Table<T> extends Object with SetStateMixin, OnAddedToDomMixin {
28
29
_spacerBeforeVisibleRows = new CoreElement ('tr' );
29
30
_spacerAfterVisibleRows = new CoreElement ('tr' );
30
31
31
- element.onScroll.listen ((_) => _scheduleRebuild ());
32
+ // TODO(jacobr): remove call to allowInterop once
33
+ // https://github.com/dart-lang/sdk/issues/35484 is fixed.
34
+ _visibilityObserver = new IntersectionObserver (allowInterop (_visibilityChange));
35
+ _visibilityObserver.observe (_spacerBeforeVisibleRows.element);
36
+ _visibilityObserver.observe (_spacerAfterVisibleRows.element);
37
+ element.onScroll.listen ((_) => _rebuildTable ());
32
38
}
33
39
34
- @override
40
+ IntersectionObserver _visibilityObserver;
41
+
35
42
final CoreElement element;
36
43
final bool _isVirtual;
37
44
@@ -69,9 +76,6 @@ class Table<T> extends Object with SetStateMixin, OnAddedToDomMixin {
69
76
new StreamController <T >.broadcast ();
70
77
71
78
void _init () {
72
- _monitorWindowResizes ();
73
- _rebuildWhenAddedToDom ();
74
-
75
79
element.add (_table);
76
80
_table.onKeyDown.listen ((KeyboardEvent e) {
77
81
int indexOffset;
@@ -98,29 +102,8 @@ class Table<T> extends Object with SetStateMixin, OnAddedToDomMixin {
98
102
});
99
103
}
100
104
101
- StreamSubscription <Event > _windowResizeSubscription;
102
- void _monitorWindowResizes () {
103
- // Monitor Window resizes but don't rebuild if we're not in the DOM.
104
- _windowResizeSubscription = window.onResize.listen ((_) {
105
- if (! isInDom) {
106
- return ;
107
- }
108
- _scheduleRebuild ();
109
- });
110
- }
111
-
112
- StreamSubscription <void > _addToDomSubscription;
113
- void _rebuildWhenAddedToDom () {
114
- // When we're added to the DOM, force a rebuild since we may have
115
- // resized the window while we were not in the DOM.
116
- _addToDomSubscription = onAddedToDom.listen ((_) => _scheduleRebuild ());
117
- }
118
-
119
105
void dispose () {
120
- _windowResizeSubscription? .cancel ();
121
- _windowResizeSubscription = null ;
122
- _addToDomSubscription? .cancel ();
123
- _addToDomSubscription = null ;
106
+ _visibilityObserver.disconnect ();
124
107
}
125
108
126
109
Stream <T > get onSelect => _selectController.stream;
@@ -506,6 +489,10 @@ class Table<T> extends Object with SetStateMixin, OnAddedToDomMixin {
506
489
_doSort ();
507
490
_scheduleRebuild ();
508
491
}
492
+
493
+ void _visibilityChange (List entries, IntersectionObserver observer) {
494
+ _scheduleRebuild ();
495
+ }
509
496
}
510
497
511
498
abstract class Column <T > {
0 commit comments