import * as React from "react"; import {BackHandler, KeyboardAvoidingView, Modal, Platform, StyleProp, View, ViewStyle} from "react-native"; import Animated from 'react-native-reanimated'; import {IPopupLayer, IProps} from "./popupLayer"; import {animatedType, configName, directionType, scaleType, storageArr} from "./config"; import _hooks from "./_hooks"; import app from "../app"; import Basic from "../basicPage"; const popupLayer: IPopupLayer = { animated: animatedType, direction: directionType, scale: scaleType, /** * 显示 * @param name 名称 * @param delayTime 延迟时间 */ show: (name: string, delayTime?: number): void => { setTimeout(() => app.emitter.set(`${configName}_${name}`, {display: true}), delayTime ?? 10) }, /** * 隐藏 * @param name 名称 * @param delayTime 延迟时间 */ hide: function (name: string, delayTime?: number): void { setTimeout(() => app.emitter.set(`${configName}_${name}`, {display: false}), delayTime ?? 10) }, has: function (name?: string): boolean { if (typeof name === "string") { const data = storageArr.getByParams({name: `${configName}_${name}`}); return data ? data.display : false } const list = storageArr.queryByParams({display: true}) ?? []; return list.length > 0 }, openingList: function (): string[] { const list = storageArr.queryByParams({display: true}) ?? []; return list.map(item => item.name.substring(configName.length + 1, item.name.length)); } } const PopupLayerView: React.FC = (props) => { const { css, width, height, direction, isClickHide, isDisplay, layerAnimatedXYStyle, layerAnimatedOpacity, } = _hooks.useData(props); // inner 样式 const innerStyle: StyleProp = { width, height, position: 'absolute', overflow: 'hidden', borderWidth: 0.5, borderColor: props.borderColor ?? 'rgba(0,0,0,0)', backgroundColor: props.bg ?? css.color.white, } if (typeof props.edge === "number") { innerStyle.borderRadius = props.borderRadius ?? 15; } // 方向 if (direction === popupLayer.direction.bottom) { // bottom innerStyle.bottom = innerStyle.left = innerStyle.right = typeof props.edge === "number" ? props.edge : 0; if (typeof props.borderRadius !== "number") innerStyle.borderTopLeftRadius = innerStyle.borderTopRightRadius = innerStyle.borderTopStartRadius = innerStyle.borderTopEndRadius = props.borderRadius ?? 15 } else if (direction === popupLayer.direction.top) { // top innerStyle.top = innerStyle.left = innerStyle.right = typeof props.edge === "number" ? props.edge : 0; if (typeof props.borderRadius !== "number") innerStyle.borderBottomLeftRadius = innerStyle.borderBottomRightRadius = innerStyle.borderBottomStartRadius = innerStyle.borderBottomEndRadius = props.borderRadius ?? 15 } else if (direction === popupLayer.direction.left) { // left innerStyle.left = innerStyle.top = innerStyle.bottom = typeof props.edge === "number" ? props.edge : 0; if (typeof props.borderRadius !== "number") innerStyle.borderTopRightRadius = innerStyle.borderTopEndRadius = innerStyle.borderBottomRightRadius = innerStyle.borderBottomEndRadius = props.borderRadius ?? 15 } else if (direction === popupLayer.direction.right) { // right innerStyle.right = innerStyle.top = innerStyle.bottom = typeof props.edge === "number" ? props.edge : 0; if (typeof props.borderRadius !== "number") innerStyle.borderTopLeftRadius = innerStyle.borderTopStartRadius = innerStyle.borderBottomLeftRadius = innerStyle.borderBottomStartRadius = props.borderRadius ?? 15 } else { // none innerStyle.bottom = innerStyle.left = innerStyle.right = typeof props.edge === "number" ? props.edge : 0; } return { if (popupLayer.has()) { const list = popupLayer.openingList(); list.map((item) => popupLayer.hide(item)); } // 退出App if (app.system.exit()) setTimeout(() => BackHandler.exitApp(), 200) }} > { if (isClickHide) popupLayer.hide(props.name); }}/> {props.children} } export default PopupLayerView export { popupLayer }