@@ -82,10 +82,15 @@ class Docs extends Util.mixin(BindMixin) {
82
82
} ;
83
83
this . sectionScrollPositions = { } ;
84
84
this . state = {
85
- activeSection : null ,
86
- pageRef : null
85
+ activeSection : null
87
86
} ;
88
87
this . viewportHeight = 0 ;
88
+
89
+ this . pageRef = React . createRef ( ) ;
90
+ this . nodeRefs . pageHeader = React . createRef ( ) ;
91
+ navigationItems . forEach (
92
+ ( { id } ) => ( this . nodeRefs . sectionRefs [ id ] = React . createRef ( ) )
93
+ ) ;
89
94
}
90
95
91
96
componentDidMount ( ) {
@@ -97,17 +102,16 @@ class Docs extends Util.mixin(BindMixin) {
97
102
}
98
103
99
104
handleNavigationClick ( id ) {
100
- const { pageRef } = this . state ;
101
105
const sectionPosition = this . sectionScrollPositions [ id ] ;
102
106
103
- if ( pageRef && sectionPosition != null ) {
104
- pageRef . scrollTop = sectionPosition ;
107
+ if ( this . pageRef . current && sectionPosition != null ) {
108
+ this . pageRef . current . scrollTop = sectionPosition ;
105
109
}
106
110
}
107
111
108
112
handlePageScroll ( ) {
109
113
let activeSection = null ;
110
- const pageScrollTop = this . state . pageRef . scrollTop ;
114
+ const pageScrollTop = this . pageRef . current . scrollTop ;
111
115
const scrollThreshhold = pageScrollTop + this . viewportHeight / 2 ;
112
116
113
117
Object . keys ( this . sectionScrollPositions ) . forEach ( ref => {
@@ -122,18 +126,13 @@ class Docs extends Util.mixin(BindMixin) {
122
126
}
123
127
}
124
128
125
- setPageRef ( pageRef ) {
126
- if ( this . state . pageRef === null ) {
127
- this . setState ( { pageRef } ) ;
128
- }
129
- }
130
-
131
129
calculateNodePositions ( ) {
132
- const pageHeaderHeight = this . nodeRefs . pageHeader . offsetHeight ;
130
+ const pageHeaderHeight = this . nodeRefs . pageHeader . current . offsetHeight ;
133
131
this . viewportHeight = DOMUtil . getViewportHeight ( ) ;
134
132
135
133
Object . keys ( this . nodeRefs . sectionRefs ) . forEach ( ref => {
136
- const top = this . nodeRefs . sectionRefs [ ref ] . offsetTop + pageHeaderHeight ;
134
+ const top =
135
+ this . nodeRefs . sectionRefs [ ref ] . current . offsetTop + pageHeaderHeight ;
137
136
this . sectionScrollPositions [ ref ] = top ;
138
137
} ) ;
139
138
}
@@ -162,26 +161,20 @@ class Docs extends Util.mixin(BindMixin) {
162
161
163
162
render ( ) {
164
163
let docsContent = null ;
165
- const { pageRef } = this . state ;
166
164
167
165
// Delay the rendering of the components until we have a reference to the
168
166
// scrolling container's DOM node.
169
- if ( pageRef !== null ) {
167
+ if ( this . pageRef !== null ) {
170
168
docsContent = navigationItems . map ( ( navigationItem , index ) => {
171
169
const { id, passScrollContainer } = navigationItem ;
172
170
const props = { } ;
173
171
174
172
if ( passScrollContainer ) {
175
- props . scrollContainer = pageRef ;
173
+ props . scrollContainer = this . pageRef ;
176
174
}
177
175
178
176
return (
179
- < div
180
- key = { index }
181
- ref = { ref => {
182
- this . nodeRefs . sectionRefs [ id ] = ref ;
183
- } }
184
- >
177
+ < div key = { index } ref = { this . nodeRefs . sectionRefs [ id ] } >
185
178
< navigationItem . component { ...props } />
186
179
</ div >
187
180
) ;
@@ -206,12 +199,12 @@ class Docs extends Util.mixin(BindMixin) {
206
199
className = "page flex-item-grow-1"
207
200
id = "page"
208
201
onScroll = { this . handlePageScroll }
209
- ref = { ref => this . setPageRef ( ref ) }
202
+ ref = { this . pageRef }
210
203
>
211
204
< div
212
205
id = "page-header"
213
206
className = "page-header fill fill-light left"
214
- ref = { ref => ( this . nodeRefs . pageHeader = ref ) }
207
+ ref = { this . nodeRefs . pageHeader }
215
208
>
216
209
< div id = "page-header-inner" className = "page-header-inner" >
217
210
< div className = "container-fluid pod" >
0 commit comments