1
This commit is contained in:
@@ -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());
|
||||
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user