@@ -226,34 +226,21 @@ class ChildComponent extends React.Component<Props> {
226226Let ’s take a look at an example calling ` UIManager.measure ` . This code might look something like this
227227
228228` ` ` js
229- if (this._scrollView == null || viewRef == null) {
230- return;
231- }
232-
229+ const viewRef: React.ElementRef<typeof View> = // ...
233230const viewHandle = ReactNative.findNodeHandle(viewRef);
234- const scrollViewHandle = ReactNative.findNodeHandle(
235- this._scrollView
236- );
237- UIManager.measure(scrollViewHandle, (x, y, width, height) => {
238- UIManager.measureLayout(
239- viewHandle,
240- scrollViewHandle,
241- emptyFunction,
242- successCallback
243- );
231+ UIManager.measure(viewHandle, (x, y, width, height) => {
232+ // Use layout metrics.
244233});
245234` ` `
246235
247236In order to call ` UIManager.measure* ` we need to call ` findNodeHandle ` first and pass in those handles . With the new API , we instead call ` measure ` directly on native refs without ` findNodeHandle ` . The example above with the new API looks like this :
248237
249238` ` ` js
250- if (this._scrollView == null || viewRef == null) {
251- return;
252- }
253-
254- this._scrollView.measure((x, y, width, height) => {
255- viewRef.measureLayout(this._scrollView, successCallback);
256- });
239+ const viewRef: React.ElementRef<typeof View> = viewRef.measure( // ...
240+ (x, y, width, height) => {
241+ // Use layout metrics.
242+ }
243+ );
257244` ` `
258245
259246` findNodeHandle ` can be called with any component as an argument , but the new ` .measure* ` can only be called on native refs . If the ref originally passed into ` findNodeHandle ` is not a native ref to start with , use the strategies above in _getting a HostComponent_ to find the native ref .
0 commit comments