1
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minSdkVersion": "21"
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
import LinearLayout from 'android.widget.LinearLayout';
|
||||
import Context from 'android.content.Context'
|
||||
import RelativeLayout from 'android.widget.RelativeLayout';
|
||||
import ViewGroup from 'android.view.ViewGroup';
|
||||
import View from 'android.view.View';
|
||||
import { XTIPS_TYPE, XTIPS_TYPE_PRIVATE } from "../interface.uts"
|
||||
import Color from 'android.graphics.Color';
|
||||
import Gravity from 'android.view.Gravity';
|
||||
import GradientDrawable from 'android.graphics.drawable.GradientDrawable';
|
||||
import TextView from 'android.widget.TextView';
|
||||
import Typeface from 'android.graphics.Typeface';
|
||||
import TextUtils from 'android.text.TextUtils';
|
||||
import Uri from 'android.net.Uri';
|
||||
import ObjectAnimator from 'android.animation.ObjectAnimator';
|
||||
import ValueAnimator from 'android.animation.ValueAnimator';
|
||||
import TimeInterpolator from 'android.animation.TimeInterpolator';
|
||||
import MotionEvent from 'android.view.MotionEvent';
|
||||
import { hexToRgb } from "../libs/color.uts"
|
||||
import { defaultConfig, configCover } from "../libs/config.uts"
|
||||
import ViewPropertyAnimator from 'android.view.ViewPropertyAnimator';
|
||||
import LayoutParams from 'android.widget.RelativeLayout.LayoutParams';
|
||||
// #ifdef UNI-APP-X
|
||||
import getCurrentPages from 'io.dcloud.uniapp.framework.getCurrentPages';
|
||||
import onReady from 'io.dcloud.uniapp.framework.onReady';
|
||||
import onUnload from 'io.dcloud.uniapp.framework.onUnload';
|
||||
import onShow from 'io.dcloud.uniapp.framework.onShow';
|
||||
import AccelerateDecelerateInterpolator from 'android.view.animation.AccelerateDecelerateInterpolator';
|
||||
// #endif
|
||||
|
||||
|
||||
let tid : number | null = 0
|
||||
let maskDomId = 388
|
||||
let currentOpts:XTIPS_TYPE | null = null;
|
||||
function px2dp(n : number) : number {
|
||||
|
||||
const mets = UTSAndroid.getAppContext()!.resources!.getDisplayMetrics()
|
||||
|
||||
return mets.density * n
|
||||
}
|
||||
|
||||
export function hideTips() {
|
||||
UTSAndroid.getDispatcher("main").async(function (_) {
|
||||
let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
|
||||
let mk = decorView.findViewById<View>((maskDomId).toInt())
|
||||
if (mk != null) {
|
||||
decorView.removeView(mk)
|
||||
}
|
||||
if (tid != null) {
|
||||
clearTimeout(tid!)
|
||||
}
|
||||
currentOpts?.close?.()
|
||||
})
|
||||
}
|
||||
function __hideTips__(decorView : ViewGroup) {
|
||||
UTSAndroid.getDispatcher("main").async(function (_) {
|
||||
let mk = decorView.findViewById<View>((maskDomId).toInt())
|
||||
if (mk != null) {
|
||||
decorView.removeView(mk)
|
||||
}
|
||||
if (tid != null) {
|
||||
clearTimeout(tid!)
|
||||
}
|
||||
currentOpts?.close?.()
|
||||
})
|
||||
}
|
||||
function _showTips_(opts : XTIPS_TYPE | null) {
|
||||
let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
|
||||
UTSAndroid.getDispatcher("main").async(function (_) {
|
||||
try {
|
||||
let mk = decorView.findViewById<View>((maskDomId).toInt())
|
||||
if (mk != null) {
|
||||
decorView.removeView(mk)
|
||||
}
|
||||
if (tid != null) {
|
||||
clearTimeout(tid!)
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
//TODO handle the exception
|
||||
}
|
||||
let realopts = opts == null ? ({ title: '' } as XTIPS_TYPE) : (opts!)
|
||||
let config = configCover(realopts)
|
||||
let rmbgColor = hexToRgb(config.maskBgColor);
|
||||
let textColor = hexToRgb(config.iconColor);
|
||||
let wrapColor = hexToRgb(config.contentBgColor);
|
||||
let titleColorRgb = hexToRgb(config.titleColor);
|
||||
|
||||
let mbgColor = rmbgColor == null ? Color.parseColor(config.maskBgColor) : Color.argb((rmbgColor!.a * 255).toInt(), rmbgColor!.r.toInt(), rmbgColor!.g.toInt(), rmbgColor!.b.toInt())
|
||||
let fontColor = textColor == null ? Color.parseColor(config.iconColor) : Color.argb((textColor!.a * 255).toInt(), textColor!.r.toInt(), textColor!.g.toInt(), textColor!.b.toInt())
|
||||
let contentColor = rmbgColor == null ? Color.parseColor(config.contentBgColor) : Color.argb((wrapColor!.a * 255).toInt(), wrapColor!.r.toInt(), wrapColor!.g.toInt(), wrapColor!.b.toInt())
|
||||
let titleColor = titleColorRgb == null ? Color.parseColor(config.titleColor) : Color.argb((titleColorRgb!.a * 255).toInt(), titleColorRgb!.r.toInt(), titleColorRgb!.g.toInt(), titleColorRgb!.b.toInt())
|
||||
|
||||
const context = UTSAndroid.getAppContext()! as Context
|
||||
let maskerDom = new RelativeLayout(context)
|
||||
|
||||
class MaskerDomClickListsner extends View.OnTouchListener {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
override onTouch(view : View, event : MotionEvent) : Boolean {
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
maskerDom.setOnTouchListener(new MaskerDomClickListsner())
|
||||
|
||||
let maskerDomLayrPrams : LayoutParams = new RelativeLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
|
||||
if (config.position == 'top') {
|
||||
maskerDomLayrPrams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE)
|
||||
maskerDom.setPadding(px2dp(16).toInt(), px2dp(config.offset).toInt(), px2dp(16).toInt(), 0)
|
||||
maskerDom.setGravity(Gravity.CENTER_HORIZONTAL)
|
||||
} else if (config.position == 'bottom') {
|
||||
maskerDomLayrPrams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE)
|
||||
maskerDom.setPadding(px2dp(16).toInt(), 0, px2dp(16).toInt(), px2dp(config.offset).toInt())
|
||||
maskerDom.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL)
|
||||
}
|
||||
maskerDom.setLayoutParams(maskerDomLayrPrams)
|
||||
maskerDom.setBackgroundColor(mbgColor)
|
||||
maskerDom.setId((maskDomId).toInt())
|
||||
|
||||
let contentWrapDiv = new LinearLayout(context);
|
||||
// 设置圆角背景
|
||||
let bg = new GradientDrawable()
|
||||
bg.setColor(contentColor)
|
||||
bg.setCornerRadius((px2dp(16)).toFloat())
|
||||
contentWrapDiv.setBackground(bg)
|
||||
// contentWrapDiv.setBackgroundColor(Color.parseColor(config.contentBgColor))
|
||||
let wpx = px2dp(config.size + 16).toInt();
|
||||
let minHeight = px2dp(Math.max(config.titleSize, config.iconSize) + 16).toInt();
|
||||
contentWrapDiv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
contentWrapDiv.setMinimumHeight(minHeight)
|
||||
contentWrapDiv.setMinimumWidth(wpx)
|
||||
let wpadingx = px2dp(8).toInt();
|
||||
contentWrapDiv.setPadding(wpadingx, wpadingx, wpadingx, wpadingx)
|
||||
|
||||
contentWrapDiv.setGravity(Gravity.CENTER)
|
||||
contentWrapDiv.setOrientation(LinearLayout.HORIZONTAL)
|
||||
// 创建图标。
|
||||
let iconDiv = new TextView(context)
|
||||
// iconDiv.setLineHeight(1)
|
||||
iconDiv.setTextColor(fontColor)
|
||||
let assetManager = context!.getAssets();
|
||||
let typeface = Typeface.createFromAsset(assetManager, "remixicon.ttf")
|
||||
iconDiv.setTypeface(typeface)
|
||||
iconDiv.setGravity(Gravity.CENTER)
|
||||
iconDiv.setTextSize(config.iconSize.toFloat())
|
||||
if (!TextUtils.isEmpty(config.iconCode) && config.iconCode != '') {
|
||||
let codePoint = Integer.parseInt(config.iconCode, 16);
|
||||
let charArray = Character.toChars(codePoint);
|
||||
let text = new String(charArray);
|
||||
iconDiv.setText(text);
|
||||
contentWrapDiv.addView(iconDiv)
|
||||
}
|
||||
|
||||
|
||||
if (config.title != "") {
|
||||
// 添加一个title
|
||||
let titleDiv = new TextView(context)
|
||||
titleDiv.setText(config.title)
|
||||
titleDiv.setTextSize((config.titleSize).toFloat())
|
||||
titleDiv.setTextColor(titleColor)
|
||||
titleDiv.setGravity(Gravity.CENTER)
|
||||
titleDiv.setPadding(px2dp(10).toInt(), 0, 0, 0)
|
||||
contentWrapDiv.addView(titleDiv)
|
||||
}
|
||||
|
||||
maskerDom.addView(contentWrapDiv)
|
||||
|
||||
decorView.addView(maskerDom!)
|
||||
|
||||
try {
|
||||
let s0 = (0).toFloat()
|
||||
let s1 = (1).toFloat()
|
||||
contentWrapDiv.setAlpha(s0)
|
||||
contentWrapDiv.setScaleX(s0)
|
||||
contentWrapDiv.setScaleY(s0)
|
||||
let ani = contentWrapDiv.animate() as ViewPropertyAnimator;
|
||||
ani.alpha(s1)
|
||||
.scaleX(s1)
|
||||
.scaleY(s1)
|
||||
.setDuration(300)
|
||||
.setInterpolator(AccelerateDecelerateInterpolator())
|
||||
.start()
|
||||
} catch (e) {
|
||||
//TODO handle the exception
|
||||
}
|
||||
|
||||
if (config.duration == 0) return;
|
||||
tid = setTimeout(function () {
|
||||
tid = null;
|
||||
__hideTips__(decorView)
|
||||
}, (config.duration + 300).toInt());
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
export function showTips(opts : XTIPS_TYPE | null) {
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 0) {
|
||||
const page = pages[pages.length - 1].vm!
|
||||
const instance = page.$
|
||||
if (page.$isReady) {
|
||||
currentOpts = opts;
|
||||
_showTips_(opts)
|
||||
} else {
|
||||
hideTips()
|
||||
}
|
||||
onUnload(() => {
|
||||
hideTips()
|
||||
}, instance)
|
||||
}else{
|
||||
currentOpts = opts;
|
||||
_showTips_(opts)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"x_tips_s": "./lib/x_tips_s.har"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { XTIPS_TYPE, XTIPS_TYPE_PRIVATE } from "../interface.uts"
|
||||
import { defaultConfig, configCover } from "../libs/config.uts"
|
||||
import { hexToRgb } from "../libs/color.uts"
|
||||
import { xshowtips,xhideTips } from "x_tips_s";
|
||||
|
||||
|
||||
|
||||
export const hideTips = () => {
|
||||
xhideTips(UTSHarmony.getCurrentWindow()!.getUIContext())
|
||||
}
|
||||
export function showTips(opts : XTIPS_TYPE|null) {
|
||||
let config = configCover(opts==null ? ({} as XTIPS_TYPE) : (opts!))
|
||||
xshowtips(UTSHarmony.getCurrentWindow()!.getUIContext(),config)
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>UIAppFonts</key>
|
||||
<array>
|
||||
<string>remixicon.ttf</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "12"
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
import { XTIPS_TYPE, XTIPS_TYPE_PRIVATE } from "../interface.uts"
|
||||
import { defaultConfig, configCover } from "../libs/config.uts"
|
||||
import { UIView,UIEdgeInsets, UIViewController, NSLayoutConstraint,UILayoutPriority, UITextView, UIFont, UILabel, NSTextAlignment, NSLineBreakMode , Distribution, UIColor } from 'UIKit';
|
||||
import { CGRect, CGPoint, CGFloat, CGSize, CFDictionary } from 'CoreFoundation';
|
||||
import { CGSizeMake } from 'CoreGraphics';
|
||||
import { Alignment } from 'SwiftUI';
|
||||
import { UInt32, KeyPath } from 'Swift';
|
||||
import { NSString } from 'Foundation';
|
||||
import { CABasicAnimation , CAMediaTiming , CAMediaTimingFunction , CAMediaTimingFunctionName } from 'QuartzCore';
|
||||
|
||||
let maskerDom : null | UIView = null;
|
||||
let tid : number | null = 0
|
||||
let currentOpts:XTIPS_TYPE | null = null;
|
||||
export function hideTips() {
|
||||
DispatchQueue.main.async(execute = () : void => {
|
||||
if (maskerDom != null) {
|
||||
maskerDom!.removeFromSuperview()
|
||||
}
|
||||
if (tid != null) {
|
||||
clearTimeout(tid!)
|
||||
}
|
||||
currentOpts?.close?.()
|
||||
})
|
||||
}
|
||||
|
||||
export function showTips(opts : XTIPS_TYPE | null) {
|
||||
DispatchQueue.main.async(execute = () : void => {
|
||||
currentOpts = opts;
|
||||
if (tid != null) {
|
||||
clearTimeout(tid!)
|
||||
tid = null;
|
||||
}
|
||||
if (maskerDom != null) {
|
||||
maskerDom!.removeFromSuperview()
|
||||
}
|
||||
let parent = UTSiOS.getCurrentViewController() as UIViewController;
|
||||
let parentView = parent.view as UIView
|
||||
|
||||
let realopts = opts == null ? ({} as XTIPS_TYPE) : (opts!)
|
||||
let config = configCover(realopts)
|
||||
|
||||
maskerDom = new UIView()
|
||||
|
||||
// 允许遮罩穿透.
|
||||
maskerDom!.isUserInteractionEnabled = !config.maskDisableClik;
|
||||
|
||||
|
||||
if (maskerDom == null) return;
|
||||
let cg = parentView.frame as CGRect
|
||||
maskerDom!.frame = cg
|
||||
maskerDom!.backgroundColor = UTSiOS.colorWithString(config.maskBgColor)
|
||||
maskerDom!.layoutMargins = new UIEdgeInsets(top=0,left=16,bottom=0,right=16)
|
||||
|
||||
let contetDiv = new UIView();
|
||||
contetDiv.layer.cornerRadius = 16
|
||||
contetDiv.layer.masksToBounds = true;
|
||||
contetDiv.backgroundColor = UTSiOS.colorWithString(config.contentBgColor)
|
||||
|
||||
// 添加投影
|
||||
|
||||
contetDiv.layer.shadowColor = UIColor.black.cgColor
|
||||
contetDiv.layer.shadowOpacity = 0.5
|
||||
contetDiv.layer.shadowOffset = new CGSize(width= 10, height= 10)
|
||||
contetDiv.layer.shadowRadius = 20
|
||||
|
||||
|
||||
|
||||
let textView = new UILabel()
|
||||
textView.frame = new CGRect(x = 0, y = 0, width = config.iconSize.toInt(), height = config.iconSize.toInt())
|
||||
textView.font = new UIFont(name = "remixicon", size = new CGFloat(config.iconSize))
|
||||
textView.textColor = UTSiOS.colorWithString(config.iconColor)
|
||||
textView.textAlignment = NSTextAlignment.center
|
||||
|
||||
if (config.iconCode != "") {
|
||||
let codePoint = new UInt32(config.iconCode, radix = 16)
|
||||
let stricon = new NSString(format = "%C", codePoint!)
|
||||
textView.text = new String(stricon);
|
||||
// 添加动画图标旋转
|
||||
let spinAni = new CABasicAnimation(keyPath = "transform.scale")
|
||||
spinAni.fromValue = 0.4
|
||||
spinAni.toValue = 1
|
||||
spinAni.duration = 0.5
|
||||
textView.layer.add(spinAni, forKey = "scaleAnimation")
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 添加内容缩放动画
|
||||
let scaleAni = new CABasicAnimation(keyPath = "transform.scale")
|
||||
scaleAni.fromValue = 0
|
||||
scaleAni.toValue = 1
|
||||
scaleAni.duration = 0.3
|
||||
scaleAni.timingFunction = new CAMediaTimingFunction(name = CAMediaTimingFunctionName.easeInEaseOut)
|
||||
|
||||
let scaleOpacity = new CABasicAnimation(keyPath = "opacity")
|
||||
scaleOpacity.fromValue = 0
|
||||
scaleOpacity.toValue = 1
|
||||
scaleOpacity.duration = 0.3
|
||||
scaleOpacity.timingFunction = new CAMediaTimingFunction(name = CAMediaTimingFunctionName.easeInEaseOut)
|
||||
|
||||
contetDiv.layer.add(scaleAni, forKey = "scaleAnimation")
|
||||
contetDiv.layer.add(scaleAni, forKey = "opacityAnimation")
|
||||
|
||||
// 两个都不空
|
||||
if (config.title != "" && config.iconCode != "") {
|
||||
|
||||
textView.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
let titleView = new UILabel()
|
||||
titleView.text = new String(config.title);
|
||||
titleView.textAlignment = NSTextAlignment.center
|
||||
titleView.lineBreakMode = NSLineBreakMode.byWordWrapping
|
||||
titleView.numberOfLines = 0
|
||||
titleView.font = UIFont.systemFont(ofSize = new CGFloat(config.titleSize))
|
||||
titleView.textColor = UTSiOS.colorWithString(config.titleColor)
|
||||
titleView.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
|
||||
let contetDivWrap = new UIStackView(arrangedSubviews = [textView,titleView])
|
||||
contetDivWrap.axis = NSLayoutConstraint.Axis.horizontal
|
||||
contetDivWrap.distribution = UIStackView.Distribution.fill
|
||||
contetDivWrap.alignment = UIStackView.Alignment.center
|
||||
contetDivWrap.spacing = 5
|
||||
|
||||
|
||||
contetDivWrap.translatesAutoresizingMaskIntoConstraints = false
|
||||
contetDiv.addSubview(contetDivWrap)
|
||||
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
// 中心约束
|
||||
// contetDivWrap.centerXAnchor.constraint(equalTo = contetDiv.centerXAnchor),
|
||||
contetDivWrap.centerYAnchor.constraint(equalTo = contetDiv.centerYAnchor),
|
||||
// 左侧约束
|
||||
contetDivWrap.leadingAnchor.constraint(equalTo = contetDiv.safeAreaLayoutGuide.leadingAnchor, constant = 16),
|
||||
// 右侧约束
|
||||
contetDivWrap.trailingAnchor.constraint(equalTo = contetDiv.safeAreaLayoutGuide.trailingAnchor, constant = -16),
|
||||
contetDivWrap.topAnchor.constraint(equalTo = contetDiv.safeAreaLayoutGuide.topAnchor, constant = 16),
|
||||
contetDivWrap.widthAnchor.constraint(lessThanOrEqualToConstant = cg.width-32),
|
||||
// contetDivWrap.bottomAnchor.constraint(equalTo = contetDiv.safeAreaLayoutGuide.bottomAnchor, constant = -16),
|
||||
])
|
||||
|
||||
|
||||
// 图标空,标题不空
|
||||
} else if (config.iconCode == "" && config.title != "") {
|
||||
let titleView = new UILabel()
|
||||
titleView.text = new String(config.title);
|
||||
titleView.textAlignment = NSTextAlignment.center
|
||||
titleView.lineBreakMode = NSLineBreakMode.byWordWrapping
|
||||
titleView.numberOfLines = 0
|
||||
titleView.font = UIFont.systemFont(ofSize = new CGFloat(config.titleSize))
|
||||
titleView.textColor = UTSiOS.colorWithString(config.titleColor)
|
||||
titleView.translatesAutoresizingMaskIntoConstraints = false
|
||||
contetDiv.addSubview(titleView)
|
||||
NSLayoutConstraint.activate([
|
||||
// 顶部约束
|
||||
titleView.topAnchor.constraint(equalTo = contetDiv.safeAreaLayoutGuide.topAnchor, constant = 16),
|
||||
titleView.bottomAnchor.constraint(equalTo = contetDiv.safeAreaLayoutGuide.bottomAnchor, constant = -16),
|
||||
// 左侧约束
|
||||
titleView.leadingAnchor.constraint(equalTo = contetDiv.safeAreaLayoutGuide.leadingAnchor, constant = 16),
|
||||
// 右侧约束
|
||||
titleView.trailingAnchor.constraint(equalTo = contetDiv.safeAreaLayoutGuide.trailingAnchor, constant = -16)
|
||||
])
|
||||
// 图标不空,文字空。
|
||||
} else {
|
||||
textView.translatesAutoresizingMaskIntoConstraints = false
|
||||
contetDiv.addSubview(textView)
|
||||
NSLayoutConstraint.activate([
|
||||
// 中心约束
|
||||
textView.centerXAnchor.constraint(equalTo = contetDiv.centerXAnchor),
|
||||
textView.centerYAnchor.constraint(equalTo = contetDiv.centerYAnchor),
|
||||
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
contetDiv.translatesAutoresizingMaskIntoConstraints = false
|
||||
maskerDom!.addSubview(contetDiv)
|
||||
|
||||
if(config.position == 'top'){
|
||||
NSLayoutConstraint.activate([
|
||||
// 中心约束
|
||||
contetDiv.centerXAnchor.constraint(equalTo = maskerDom!.centerXAnchor),
|
||||
contetDiv.topAnchor.constraint(equalTo = maskerDom!.safeAreaLayoutGuide.topAnchor, constant = new CGFloat(config.offset!)),
|
||||
// 宽约束100
|
||||
contetDiv.widthAnchor.constraint(greaterThanOrEqualToConstant = new CGFloat(config.size!)),
|
||||
contetDiv.widthAnchor.constraint(lessThanOrEqualToConstant = cg.width-32),
|
||||
|
||||
])
|
||||
}else if(config.position == 'bottom'){
|
||||
NSLayoutConstraint.activate([
|
||||
// 中心约束
|
||||
contetDiv.centerXAnchor.constraint(equalTo = maskerDom!.centerXAnchor),
|
||||
contetDiv.bottomAnchor.constraint(equalTo = maskerDom!.safeAreaLayoutGuide.bottomAnchor, constant = new CGFloat((config.offset!) * -1)),
|
||||
// 宽约束100
|
||||
contetDiv.widthAnchor.constraint(greaterThanOrEqualToConstant = new CGFloat(config.size!)),
|
||||
contetDiv.widthAnchor.constraint(lessThanOrEqualToConstant = cg.width-32),
|
||||
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
parentView.addSubview(maskerDom!)
|
||||
|
||||
if (config.duration == 0) return;
|
||||
tid = setTimeout(function () {
|
||||
tid = null;
|
||||
hideTips()
|
||||
}, (config.duration + 300).toInt());
|
||||
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
export type XTIPS_TYPE = {
|
||||
iconColor?:string,
|
||||
contentBgColor?:string,
|
||||
maskBgColor?:string,
|
||||
iconSize?:number,
|
||||
/**
|
||||
* 正常应该填写图标的16进制符号如:EEC4
|
||||
* 本组件允许几个状态名称使用默认图标,为空是info图标。
|
||||
* warn,error,success,info
|
||||
*/
|
||||
iconCode?:string,
|
||||
/**
|
||||
* 标题为空不显示。
|
||||
*/
|
||||
title:string,
|
||||
titleSize?:number,
|
||||
titleColor?:string,
|
||||
/**
|
||||
* 几秒后消失,0 表示永不消失
|
||||
* @default 2000
|
||||
*/
|
||||
duration?:number,
|
||||
close?:()=>void,
|
||||
/** 宽 */
|
||||
size?:number,
|
||||
/**
|
||||
* 禁用遮罩穿透点击事件
|
||||
* @default false
|
||||
*/
|
||||
maskDisableClik?:boolean,
|
||||
position?:'top'|'bottom',
|
||||
/**
|
||||
* 偏移量
|
||||
* @default 50
|
||||
*/
|
||||
offset?:number
|
||||
}
|
||||
export type XTIPS_TYPE_PRIVATE = {
|
||||
iconColor:string,
|
||||
contentBgColor:string,
|
||||
maskBgColor:string,
|
||||
iconSize:number,
|
||||
iconCode:string,
|
||||
title:string,
|
||||
titleSize:number,
|
||||
titleColor:string,
|
||||
duration:number,
|
||||
close:()=>void,
|
||||
size:number,
|
||||
maskDisableClik:boolean,
|
||||
position:'top'|'bottom',
|
||||
//偏移量
|
||||
offset:number
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
type RGBA = { r : number, g : number, b : number, a : number }
|
||||
export function hexToRgb(sColors : string) : RGBA | null {
|
||||
if (sColors == "") {
|
||||
return null
|
||||
}
|
||||
let reg = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/;
|
||||
let sColor : string = sColors.toLowerCase();
|
||||
|
||||
if (sColor != '' && reg.test(sColor)) {
|
||||
if (sColor.length == 4) {
|
||||
let sColorNew = "#";
|
||||
for (let i = 1; i < 4; i += 1) {
|
||||
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
|
||||
}
|
||||
sColor = sColorNew;
|
||||
}
|
||||
|
||||
//处理六位的颜色值
|
||||
let sColorChange : number[] = [];
|
||||
sColorChange.push(parseInt(sColor.substring(1, 3), 16));
|
||||
sColorChange.push(parseInt(sColor.substring(3, 5), 16));
|
||||
sColorChange.push(parseInt(sColor.substring(5, 7), 16));
|
||||
if (sColor.length == 9) {
|
||||
sColorChange.push(parseInt(sColor.substring(7, 9), 16) / 255);
|
||||
}
|
||||
return {
|
||||
r: sColorChange[0],
|
||||
g: sColorChange[1],
|
||||
b: sColorChange[2],
|
||||
a: sColorChange.length == 4 ? sColorChange[3] : 1
|
||||
} as RGBA
|
||||
} else if (/^(rgb|RGB|rgba|RGBA)/.test(sColor)) {
|
||||
let arr : string[] = sColor.replace(/(?:\(|\)|rgba|rgb|RGB|RGBA)*/g, "").split(",")
|
||||
let p : number[] = arr.map((val : string) : number => parseInt(val));
|
||||
|
||||
if (p.length < 3) {
|
||||
return {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 1
|
||||
} as RGBA
|
||||
}
|
||||
if (p.length == 3) {
|
||||
p.add(1)
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
r: p[0],
|
||||
g: p[1],
|
||||
b: p[2],
|
||||
a: arr.length==3?p[3]:parseFloat(arr[3])
|
||||
} as RGBA
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { XTIPS_TYPE, XTIPS_TYPE_PRIVATE } from "../interface.uts"
|
||||
export const defaultConfig = {
|
||||
iconColor: 'rgb(5,121,255)',
|
||||
contentBgColor: 'rgba(255,255,255,1)',
|
||||
maskBgColor: 'rgba(0,0,0,0)',
|
||||
iconSize: 20,
|
||||
iconCode: 'F449',
|
||||
title: '',
|
||||
titleSize: 16,
|
||||
titleColor: 'rgb(5,121,255)',
|
||||
duration: 2000,
|
||||
size: 130,
|
||||
close: () => { },
|
||||
|
||||
maskDisableClik: false,
|
||||
position:'top',
|
||||
offset:50
|
||||
|
||||
} as XTIPS_TYPE_PRIVATE
|
||||
|
||||
export const defaultStatusIcon = new Map<string, string>([
|
||||
['warn', 'ECA1'],
|
||||
['error', 'EB97'],
|
||||
['success', 'EB79'],
|
||||
['info', 'F449'],
|
||||
])
|
||||
|
||||
export function configCover(opts : XTIPS_TYPE) : XTIPS_TYPE_PRIVATE {
|
||||
let iconColor = opts.iconColor != null ? (opts.iconColor!) : defaultConfig.iconColor;
|
||||
let contentBgColor = opts.contentBgColor != null ? (opts.contentBgColor!) : defaultConfig.contentBgColor;
|
||||
let maskBgColor = opts.maskBgColor != null ? (opts.maskBgColor!) : defaultConfig.maskBgColor;
|
||||
let iconSize = opts.iconSize != null ? (opts.iconSize!) : defaultConfig.iconSize;
|
||||
let iconCode : string = opts.iconCode != null ? (opts.iconCode!) : defaultConfig.iconCode;
|
||||
if (defaultStatusIcon.has(iconCode)) {
|
||||
iconCode = defaultStatusIcon.get(iconCode)!
|
||||
}
|
||||
let title = opts.title != null ? (opts.title!) : defaultConfig.title;
|
||||
let titleSize = opts.titleSize != null ? (opts.titleSize!) : defaultConfig.titleSize;
|
||||
let titleColor = opts.titleColor != null ? (opts.titleColor!) : defaultConfig.titleColor;
|
||||
let duration = opts.duration != null ? (opts.duration!) : defaultConfig.duration;
|
||||
let close = opts.close != null ? (opts.close!) : defaultConfig.close;
|
||||
let size = opts.size != null ? (opts.size!) : defaultConfig.size;
|
||||
let position = opts.position != null ? (opts.position!) : defaultConfig.position;
|
||||
let offset = opts.offset != null ? (opts.offset!) : defaultConfig.offset;
|
||||
let maskDisableClik = false;
|
||||
|
||||
// #ifdef APP-ANDROID || APP-HARMONY
|
||||
maskDisableClik = opts.maskDisableClik == null ? defaultConfig.maskDisableClik : (opts.maskDisableClik!);
|
||||
// #endif
|
||||
// #ifdef WEB
|
||||
maskDisableClik = opts.maskDisableClik == null ? (defaultConfig.maskDisableClik) : (opts.maskDisableClik);
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-IOS
|
||||
maskDisableClik = opts.maskDisableClik == null ? (!defaultConfig.maskDisableClik) : (!opts.maskDisableClik);
|
||||
// #endif
|
||||
|
||||
return {
|
||||
iconColor,
|
||||
contentBgColor,
|
||||
maskBgColor,
|
||||
iconSize,
|
||||
iconCode, title, titleSize, titleColor, duration, close, size, maskDisableClik,position,offset
|
||||
} as XTIPS_TYPE_PRIVATE
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
export { XTIPS_TYPE, XTIPS_TYPE_PRIVATE } from "../interface.uts"
|
||||
import { defaultConfig, configCover } from "../libs/config.uts"
|
||||
import { LoadFontFace } from "./loadFont.uts"
|
||||
let maskerDom : null | HTMLDivElement = null;
|
||||
let tid:number|null = 0
|
||||
let currentOpts:XTIPS_TYPE | null = null;
|
||||
export const hideTips = () => {
|
||||
if (maskerDom != null) {
|
||||
maskerDom.remove()
|
||||
}
|
||||
if(tid!=null){
|
||||
clearTimeout(tid!)
|
||||
}
|
||||
currentOpts?.close?.()
|
||||
}
|
||||
// @ts-ignore
|
||||
export const showTips = (opts : XTIPS_TYPE | null) => {
|
||||
LoadFontFace()
|
||||
currentOpts = opts;
|
||||
if(tid!=null){
|
||||
clearTimeout(tid!)
|
||||
tid=null;
|
||||
}
|
||||
if (maskerDom != null) {
|
||||
maskerDom.remove()
|
||||
}
|
||||
// @ts-ignore
|
||||
let realopts = opts == null ? ({} as XTIPS_TYPE) : (opts!)
|
||||
let config = configCover(realopts)
|
||||
|
||||
maskerDom = document.createElement("div")
|
||||
if (maskerDom == null) return;
|
||||
maskerDom.style.setProperty("background-color", config.maskBgColor)
|
||||
maskerDom.style.setProperty("position", "fixed")
|
||||
maskerDom.style.setProperty("left", "0px")
|
||||
maskerDom.style.setProperty("top", "0px")
|
||||
maskerDom.style.setProperty("width", "100%")
|
||||
maskerDom.style.setProperty("height", "100%")
|
||||
maskerDom.style.display = "flex"
|
||||
maskerDom.style.flexDirection = "row"
|
||||
maskerDom.style.justifyContent = "center"
|
||||
maskerDom.style.alignItems = config.position=='top'?'flex-start': "flex-end"
|
||||
maskerDom.style.zIndex = "10000"
|
||||
maskerDom.style.pointerEvents = config.maskDisableClik?'auto':"none"
|
||||
|
||||
let contentWrapDiv = document.createElement("div")
|
||||
contentWrapDiv.style.padding = "8px 16px"
|
||||
contentWrapDiv.style.minWidth = config.size+"px"
|
||||
contentWrapDiv.style.maxWidth = "414px"
|
||||
if(config.position=='top'){
|
||||
contentWrapDiv.style.marginTop = config.offset+'px'
|
||||
}else if(config.position=='bottom'){
|
||||
contentWrapDiv.style.marginBottom = config.offset+'px'
|
||||
}
|
||||
|
||||
// contentWrapDiv.style.height = "100px"
|
||||
if((config.iconCode!=''&&config.title!='')||(config.iconCode!=''&&config.title=='')){
|
||||
contentWrapDiv.style.minHeight = (Math.max(config.iconSize,config.titleSize))+"px"
|
||||
}
|
||||
contentWrapDiv.style.backgroundColor = config.contentBgColor
|
||||
contentWrapDiv.style.borderRadius = "8px"
|
||||
contentWrapDiv.style.boxSizing = "border-box"
|
||||
contentWrapDiv.style.display = "flex"
|
||||
contentWrapDiv.style.flexDirection = "row"
|
||||
contentWrapDiv.style.justifyContent = "center"
|
||||
contentWrapDiv.style.alignItems = "center"
|
||||
contentWrapDiv.style.lineHeight = "1"
|
||||
contentWrapDiv.className = 'xShowToasScaleAnimation'
|
||||
let textDiv = document.createElement("span")
|
||||
if(config.iconCode!=''){
|
||||
textDiv.innerText = String.fromCharCode(parseInt(config.iconCode, 16));
|
||||
textDiv.style.fontFamily = "remixicon"
|
||||
textDiv.style.fontSize = config.iconSize + "px"
|
||||
textDiv.style.color = config.iconColor
|
||||
textDiv.className = 'xShowToasAnimation'
|
||||
}
|
||||
|
||||
|
||||
var anistr = `
|
||||
.xShowToasAnimation{
|
||||
animation-name: xUiToastIconAni;
|
||||
animation-duration: 1s;
|
||||
animation-timing-function: cubic-bezier(.42,.38,.15,.93);
|
||||
}
|
||||
.xShowToasScaleAnimation{
|
||||
animation-name: xUiToastIconAniScale;
|
||||
animation-duration: 0.3s;
|
||||
animation-timing-function: cubic-bezier(.42,.38,.15,.93);
|
||||
}
|
||||
@keyframes xUiToastIconAni {
|
||||
0% {
|
||||
transform: scale(0);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
@keyframes xUiToastIconAniScale {
|
||||
0% {
|
||||
transform: scale(0);
|
||||
opacity:0;
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: scale(1);
|
||||
opacity:1;
|
||||
}
|
||||
}
|
||||
`
|
||||
var styleDIv = document.getElementById('xUiToastIcon');
|
||||
if (!styleDIv) {
|
||||
let style = document.createElement("style");
|
||||
style.id = 'xUiLoadWeingIcon'
|
||||
document.head.appendChild(style)
|
||||
styleDIv = style;
|
||||
}
|
||||
let sheet = styleDIv.sheet;
|
||||
if (sheet.cssRules.length == 0) {
|
||||
styleDIv.append(anistr)
|
||||
}
|
||||
|
||||
contentWrapDiv.appendChild(textDiv)
|
||||
|
||||
|
||||
if (config.title != '') {
|
||||
let titleDiv = document.createElement("span")
|
||||
titleDiv.innerText = config.title;
|
||||
titleDiv.style.paddingLeft = '10px'
|
||||
titleDiv.style.fontSize = config.titleSize + "px"
|
||||
titleDiv.style.color = config.titleColor
|
||||
contentWrapDiv.appendChild(titleDiv)
|
||||
titleDiv.style.textAlign = "center"
|
||||
titleDiv.style.wordBreak = "break-all"
|
||||
|
||||
}
|
||||
|
||||
maskerDom!.appendChild(contentWrapDiv)
|
||||
window.document.body.appendChild(maskerDom!)
|
||||
|
||||
if(config.duration==0) return;
|
||||
tid = setTimeout(function() {
|
||||
tid = null;
|
||||
hideTips()
|
||||
}, (config.duration));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
export function LoadFontFace(){
|
||||
// 定义字体
|
||||
// @ts-ignore
|
||||
const font = new FontFace("remixicon", "url(/static/tmui4xLibs/static/remixicon.ttf)", {
|
||||
style: "italic",
|
||||
weight: "800",
|
||||
stretch: "condensed",
|
||||
});
|
||||
|
||||
// 把字体添加到 document.fonts(FontFaceSet)中
|
||||
document.fonts.add(font);
|
||||
font.load();
|
||||
}
|
||||
Reference in New Issue
Block a user