@@ -5,6 +5,7 @@ export default {
5
5
inject: [
6
6
' vscrollData' ,
7
7
' vscrollParent' ,
8
+ ' vscrollResizeObserver' ,
8
9
],
9
10
10
11
props: {
@@ -63,9 +64,31 @@ export default {
63
64
},
64
65
65
66
active (value ) {
67
+ if (! this .size ) {
68
+ if (value) {
69
+ if (! this .vscrollParent .$_undefinedMap [this .id ]) {
70
+ this .vscrollParent .$_undefinedSizes ++
71
+ this .vscrollParent .$_undefinedMap [this .id ] = true
72
+ }
73
+ } else {
74
+ if (this .vscrollParent .$_undefinedMap [this .id ]) {
75
+ this .vscrollParent .$_undefinedSizes --
76
+ this .vscrollParent .$_undefinedMap [this .id ] = false
77
+ }
78
+ }
79
+ }
80
+
66
81
if (value && this .$_pendingVScrollUpdate === this .id ) {
67
82
this .updateSize ()
68
83
}
84
+
85
+ if (this .vscrollResizeObserver ) {
86
+ if (value) {
87
+ this .observeSize ()
88
+ } else {
89
+ this .unobserveSize ()
90
+ }
91
+ }
69
92
},
70
93
},
71
94
@@ -75,23 +98,27 @@ export default {
75
98
this .$_forceNextVScrollUpdate = null
76
99
this .updateWatchData ()
77
100
78
- for (const k in this .sizeDependencies ) {
79
- this .$watch (() => this .sizeDependencies [k], this .onDataUpdate )
80
- }
101
+ if (! this .vscrollResizeObserver ) {
102
+ for (const k in this .sizeDependencies ) {
103
+ this .$watch (() => this .sizeDependencies [k], this .onDataUpdate )
104
+ }
81
105
82
- this .vscrollParent .$on (' vscroll:update' , this .onVscrollUpdate )
83
- this .vscrollParent .$on (' vscroll:update-size' , this .onVscrollUpdateSize )
106
+ this .vscrollParent .$on (' vscroll:update' , this .onVscrollUpdate )
107
+ this .vscrollParent .$on (' vscroll:update-size' , this .onVscrollUpdateSize )
108
+ }
84
109
},
85
110
86
111
mounted () {
87
112
if (this .vscrollData .active ) {
88
113
this .updateSize ()
114
+ this .observeSize ()
89
115
}
90
116
},
91
117
92
118
beforeDestroy () {
93
119
this .vscrollParent .$off (' vscroll:update' , this .onVscrollUpdate )
94
120
this .vscrollParent .$off (' vscroll:update-size' , this .onVscrollUpdateSize )
121
+ this .unobserveSize ()
95
122
},
96
123
97
124
methods: {
@@ -137,26 +164,44 @@ export default {
137
164
},
138
165
139
166
computeSize (id ) {
167
+ if (this .vscrollResizeObserver ) return
140
168
this .$nextTick (() => {
141
169
if (this .id === id) {
142
- const bounds = {
143
- width: this .$el .offsetWidth ,
144
- height: this .$el .offsetHeight ,
145
- }
146
- const size = Math .round (this .vscrollParent .direction === ' vertical' ? bounds .height : bounds .width )
147
- if (size && this .size !== size) {
148
- if (this .vscrollParent .$_undefinedMap [id]) {
149
- this .vscrollParent .$_undefinedSizes --
150
- this .vscrollParent .$_undefinedMap [id] = undefined
151
- }
152
- this .$set (this .vscrollData .sizes , this .id , size)
153
- this .$set (this .vscrollData .validSizes , this .id , true )
154
- if (this .emitResize ) this .$emit (' resize' , this .id )
155
- }
170
+ const width = this .$el .offsetWidth
171
+ const height = this .$el .offsetHeight
172
+ this .applySize (width, height)
156
173
}
157
174
this .$_pendingSizeUpdate = null
158
175
})
159
176
},
177
+
178
+ applySize (width , height ) {
179
+ const size = Math .round (this .vscrollParent .direction === ' vertical' ? height : width)
180
+ if (size && this .size !== size) {
181
+ if (this .vscrollParent .$_undefinedMap [this .id ]) {
182
+ this .vscrollParent .$_undefinedSizes --
183
+ this .vscrollParent .$_undefinedMap [this .id ] = undefined
184
+ }
185
+ this .$set (this .vscrollData .sizes , this .id , size)
186
+ this .$set (this .vscrollData .validSizes , this .id , true )
187
+ if (this .emitResize ) this .$emit (' resize' , this .id )
188
+ }
189
+ },
190
+
191
+ observeSize () {
192
+ this .vscrollResizeObserver .observe (this .$el .parentNode )
193
+ this .$el .parentNode .addEventListener (' resize' , this .onResize )
194
+ },
195
+
196
+ unobserveSize () {
197
+ this .vscrollResizeObserver .unobserve (this .$el .parentNode )
198
+ this .$el .parentNode .removeEventListener (' resize' , this .onResize )
199
+ },
200
+
201
+ onResize (event ) {
202
+ const { width , height } = event .detail .contentRect
203
+ this .applySize (width, height)
204
+ },
160
205
},
161
206
162
207
render (h ) {
0 commit comments