UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

62 lines 1.96 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.measureInWindow = exports.isMeasuredRectBogus = void 0; var _reactNative = require("react-native"); var _reactNativeConstants = require("../../../utils/react-native-constants"); var androidTopInsetCompensation = insets => _reactNative.Platform.OS === 'android' && !_reactNativeConstants.isRN86OrGreater ? insets.top : 0; var SCREEN_BOUND_MULTIPLIER = 2; var isMeasuredRectBogus = (x, y, w, h) => { if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(w) || !Number.isFinite(h)) { return true; } if (w <= 0 || h <= 0) { return true; } var _Dimensions$get = _reactNative.Dimensions.get('screen'), width = _Dimensions$get.width, height = _Dimensions$get.height; if (width <= 0 || height <= 0) { return false; } return Math.abs(x) > width * SCREEN_BOUND_MULTIPLIER || Math.abs(y) > height * SCREEN_BOUND_MULTIPLIER; }; exports.isMeasuredRectBogus = isMeasuredRectBogus; var measureInWindow = (node, insets) => { return new Promise((resolve, reject) => { var handle = node.current; if (!handle) { return reject(new Error('The native handle could not be found while invoking measureInWindow.')); } handle.measureInWindow((x, y, w, h) => { if (!isMeasuredRectBogus(x, y, w, h)) { resolve({ h, w, x, y: y + androidTopInsetCompensation(insets) }); return; } if (typeof handle.measure !== 'function') { resolve({ h, w, x, y: y + androidTopInsetCompensation(insets) }); return; } handle.measure((_x, _y, width, height, pageX, pageY) => { resolve({ h: height, w: width, x: pageX, y: pageY }); }); }); }); }; exports.measureInWindow = measureInWindow; //# sourceMappingURL=measureInWindow.js.map