queryLayoutByID.js
1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule queryLayoutByID
* @flow
* @format
*/
'use strict';
var UIManager = require('UIManager');
type OnSuccessCallback = (
left: number,
top: number,
width: number,
height: number,
pageX: number,
pageY: number,
) => void;
// I don't know what type error is...
type OnErrorCallback = (error: any) => void;
/**
* Queries the layout of a view. The layout does not reflect the element as
* seen by the user, rather it reflects the position within the layout system,
* before any transforms are applied.
*
* The only other requirement is that the `pageX, pageY` values be in the same
* coordinate system that events' `pageX/Y` are reported. That means that for
* the web, `pageXOffset/pageYOffset` should be added to to
* getBoundingClientRect to make consistent with touches.
*
* var pageXOffset = window.pageXOffset;
* var pageYOffset = window.pageYOffset;
*
* This is an IOS specific implementation.
*
* @param {number} tag ID of the platform specific node to be measured.
* @param {function} onError `func(error)`
* @param {function} onSuccess `func(left, top, width, height, pageX, pageY)`
*/
var queryLayoutByID = function(
tag: ?number,
onError: OnErrorCallback,
onSuccess: OnSuccessCallback,
): void {
if (tag == null) {
return;
}
// Native bridge doesn't *yet* surface errors.
UIManager.measure(tag, onSuccess);
};
module.exports = queryLayoutByID;