queryLayoutByID.js 1.5 KB

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