@@ -15,7 +15,14 @@ import Feature from '../Feature';
15
15
16
16
const initialDimensions = { width : undefined , height : undefined } ;
17
17
18
- let numberOfEvents = 0 ;
18
+ const overridenWebViewProps = {
19
+ scalesPageToFit : false ,
20
+ showsVerticalScrollIndicator : false ,
21
+ disableScrollViewPanResponder : true ,
22
+ contentMode : 'mobile'
23
+ } as const ;
24
+
25
+ const overridenWebViewKeys = Object . keys ( overridenWebViewProps ) ;
19
26
20
27
/**
21
28
* The state of synchronization between viewport and content size:
@@ -131,20 +138,69 @@ const initialState: AutoheightInternalState = {
131
138
viewportWidth : 0
132
139
} ;
133
140
141
+ function useDevFeedbackEffect ( {
142
+ autoHeightParams : { webshellProps } ,
143
+ state : {
144
+ implementation,
145
+ contentSize : { width, height }
146
+ }
147
+ } : {
148
+ autoHeightParams : AutoheightParams < WebshellProps < MinimalWebViewProps , [ ] > > ;
149
+ state : AutoheightInternalState ;
150
+ } ) {
151
+ const numberOfEventsRef = React . useRef ( 0 ) ;
152
+ const { webshellDebug } = webshellProps ;
153
+ const forbiddenWebViewProps = overridenWebViewKeys
154
+ . map ( ( key ) => [ key , webshellProps [ key ] ] )
155
+ . reduce ( ( prev , [ key , value ] ) => {
156
+ prev [ key ] = value ;
157
+ return prev ;
158
+ } , { } as any ) ;
159
+ React . useEffect (
160
+ function warnOverridenProps ( ) {
161
+ for ( const forbiddenKey of overridenWebViewKeys ) {
162
+ if (
163
+ forbiddenWebViewProps [ forbiddenKey ] !== undefined &&
164
+ forbiddenWebViewProps [ forbiddenKey ] !==
165
+ overridenWebViewProps [ forbiddenKey ]
166
+ ) {
167
+ console . warn (
168
+ `${ useAutoheight . name } : You cannot set "${ forbiddenKey } " prop to "${ webshellProps [ forbiddenKey ] } " with autoheight hook. The value will be overriden to "${ overridenWebViewProps [ forbiddenKey ] } ".`
169
+ ) ;
170
+ }
171
+ }
172
+ } ,
173
+ // eslint-disable-next-line react-hooks/exhaustive-deps
174
+ [ webshellDebug , ...Object . values ( forbiddenWebViewProps ) ]
175
+ ) ;
176
+ React . useEffect (
177
+ function debugDOMHTMLDimensions ( ) {
178
+ webshellDebug &&
179
+ console . info (
180
+ `${
181
+ useAutoheight . name
182
+ } : DOMHTMLDimensions event #${ ++ numberOfEventsRef . current } (implementation: ${ implementation } , content width: ${ width } , content height: ${ height } )`
183
+ ) ;
184
+ } ,
185
+ [ webshellDebug , implementation , height , width ]
186
+ ) ;
187
+ }
188
+
134
189
function useAutoheightState <
135
190
S extends WebshellProps <
136
191
MinimalWebViewProps ,
137
192
[ ExtractFeatureFromClass < typeof HandleHTMLDimensionsFeature > ]
138
193
>
139
- > ( { webshellProps, initialHeight } : AutoheightParams < S > ) {
140
- const { scalesPageToFit, source = { } , webshellDebug } = webshellProps ;
194
+ > ( autoHeightParams : AutoheightParams < S > ) {
195
+ const { webshellProps, initialHeight } = autoHeightParams ;
196
+ const { source = { } , webshellDebug } = webshellProps ;
141
197
const [ state , setState ] = React . useState < AutoheightInternalState > (
142
198
initialState
143
199
) ;
144
- const {
145
- implementation ,
146
- contentSize : { width , height }
147
- } = state ;
200
+ if ( __DEV__ ) {
201
+ // eslint-disable-next-line react-hooks/rules-of-hooks
202
+ useDevFeedbackEffect ( { autoHeightParams , state } ) ;
203
+ }
148
204
React . useEffect (
149
205
function resetHeightOnSourceChanges ( ) {
150
206
setState ( ( { contentSize, viewportWidth } ) => ( {
@@ -157,34 +213,16 @@ function useAutoheightState<
157
213
syncState : 'syncing' ,
158
214
lastFrameChangedWidth : false
159
215
} ) ) ;
160
- webshellDebug &&
216
+ __DEV__ &&
217
+ webshellDebug &&
161
218
console . info (
162
219
`${ useAutoheight . name } : source change detected, resetting height to ${ initialHeight } dp.`
163
220
) ;
164
221
} ,
165
222
[ source . uri , source . html , webshellDebug , initialHeight ]
166
223
) ;
167
- React . useEffect (
168
- function debugScalesPageToFit ( ) {
169
- webshellDebug &&
170
- scalesPageToFit === true &&
171
- console . warn (
172
- `${ useAutoheight . name } : You cannot use scalesPageToFit with autoheight hook. The value will be overriden to false`
173
- ) ;
174
- } ,
175
- [ scalesPageToFit , webshellDebug ]
176
- ) ;
177
- React . useEffect (
178
- function debugDOMHTMLDimensions ( ) {
179
- webshellDebug &&
180
- console . info (
181
- `${
182
- useAutoheight . name
183
- } : DOMHTMLDimensions event #${ ++ numberOfEvents } (implementation: ${ implementation } , content width: ${ width } , content height: ${ height } )`
184
- ) ;
185
- } ,
186
- [ webshellDebug , implementation , height , width ]
187
- ) ;
224
+ if ( __DEV__ ) {
225
+ }
188
226
return { state, setState } ;
189
227
}
190
228
@@ -322,10 +360,7 @@ export default function useAutoheight<
322
360
webshellDebug,
323
361
onDOMHTMLDimensions : handleOnDOMHTMLDimensions ,
324
362
style : autoHeightStyle ,
325
- scalesPageToFit : false ,
326
- showsVerticalScrollIndicator : false ,
327
- disableScrollViewPanResponder : true ,
328
- contentMode : 'mobile'
363
+ ...overridenWebViewProps
329
364
} as AutoheightState < S > [ 'autoheightWebshellProps' ] ,
330
365
resizeImplementation : implementation ,
331
366
contentSize : state . contentSize ,
0 commit comments