UNPKG

@uiw/react-native

Version:
56 lines 1.55 kB
import { Dimensions } from 'react-native'; export let MainWidth = Dimensions.get('window').width; export let MainHeight = Dimensions.get('window').height; export let xLocation; (function (xLocation) { xLocation["start"] = "flex-start"; xLocation["center"] = "center"; xLocation["end"] = "flex-end"; })(xLocation || (xLocation = {})); /** * 得到 cloud 位置 * @returns getLocationReturn */ export function getLocation(width, height, pageOffsetX, pageOffsetY, _W, _H) { let isDown = false; let isStart = xLocation.start; let triangle = 0; let style = {}; let halfWidth = width / 2; // 得到 三角上下位置 if (pageOffsetY > MainHeight / 2) { isDown = true; style.top = pageOffsetY - _H; } else { isDown = false; style.top = pageOffsetY + height; } // 得到 三角 x 位置 if (pageOffsetX === (MainWidth - width) / 2) { isStart = xLocation.center; style.left = (MainWidth - _W) / 2; } if (MainWidth - width - pageOffsetX > pageOffsetX) { isStart = xLocation.start; style.left = pageOffsetX + halfWidth - 16; } if (MainWidth - width - pageOffsetX < pageOffsetX) { isStart = xLocation.end; style.left = pageOffsetX - halfWidth + 16; } // cloud 宽度超出屏幕 if (_W + pageOffsetX >= MainWidth - 40) { style.width = MainWidth - 40; triangle = pageOffsetX + halfWidth - 20 - 10 - 6; style.left = 20; if (pageOffsetY > MainHeight / 2) { style.top = pageOffsetY; } } return { style, isDown, isStart, triangle }; }