This commit is contained in:
2026-09-24 16:25:22 +08:00
commit 7428184f01
1198 changed files with 314515 additions and 0 deletions
View File
@@ -0,0 +1,9 @@
<template>
<view>
<x-text>欢迎使用TMUI4X标准组件库</x-text>
</view>
</template>
<script>
</script>
<style>
</style>
@@ -0,0 +1,109 @@
<template>
<view :id="uid" style="min-height: 5px;min-width: 5px;">
<slot v-if="props.into == 'self'" ></slot>
<view v-if="props.into == 'self'" class="xdBlurSelf" :id="uidself" ></view>
<!-- #ifdef APP -->
<native-view @init="onviewinit" v-else :style="`background-color: ${bgColor};width:100%;height:100%;min-height: 5px;min-width: 5px;`"></native-view>
<!-- #endif -->
<!-- #ifdef APP-HARMONY -->
<native-view @init="onviewinit" v-if="props.into == 'self'" style="width:100%;height:100%;min-height: 5px;min-width: 5px;"></native-view>
<!-- #endif -->
</view>
</template>
<script setup lang="uts">
import { xdBlur } from '@/uni_modules/x-design';
let xdblur : xdBlur | null = null
let uid = 'xdblur' + Math.random().toString(16).substring(4, 20)
let uidself = 'xdblurself' + Math.random().toString(16).substring(4, 20)
const props = defineProps({
/**
* 模糊程度0-100
*/
blur: {
type: Number,
default: 100
},
/**
* 背景颜色建议rgba,让a有透明度,这样
* 更适合磨砂效果,推荐blur=90,a=0.9,具体请自行设置
* 如果要适应暗黑,请自行在外部判断isDark来切换暗黑背景.
*/
bgColor: {
type: String,
default: 'rgba(255,255,255,0.8)'
},
/**
* 模糊对象
* parent,模糊它的父级(即背景),self:模糊自己本身内容
*/
into: {
type: String,
default: "parent"
}
})
let tid = 12
const bgColor = computed(():string => props.bgColor)
const setBgBlur = ():Promise<boolean> => {
return new Promise((res)=>{
let ele = uni.getElementById(uid) as UniElement | null;
let ele2 = uni.getElementById(uidself) as UniElement | null;
if (ele != null) {
let blur = props.blur;
if (props.into == 'parent') {
xdblur?.setFilterBg(blur as number, props.bgColor,ele)
} else if (ele2 != null&&props.into != 'parent') {
// #ifdef APP-ANDROID||APP-IOS
xdBlur.setFilterSelfBg(ele, ele2, blur as number, props.bgColor)
// #endif
// #ifdef APP-HARMONY
xdblur?.setFilterSelfBg(ele, ele2, blur as number, props.bgColor)
// #endif
}
}
res(true)
})
}
watch(() : any[] => [props.blur, props.bgColor], () => {
setBgBlur()
})
function onviewinit(e : UniNativeViewInitEvent) {
xdblur = new xdBlur(e.detail.element);
tid = setTimeout(function () {
setBgBlur()
}, 50);
}
onMounted(() => {
// #ifndef APP
xdblur = new xdBlur(null);
setBgBlur()
// #endif
})
// #ifdef APP
onPageScroll((ops : OnPageScrollOptions) => {
clearTimeout(tid)
tid = setTimeout(function () {
setBgBlur()
}, 5);
})
// #endif
</script>
<style>
.xdBlurSelf {
pointer-events: none;
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
</style>
@@ -0,0 +1,53 @@
<template>
<view :id="guid">
<view>
<text>445fdsf枯顶替顶替</text>
</view>
<view v-if="showmodal">
<slot></slot>
</view>
</view>
<x-button @click="show">显示</x-button>
<x-button @click="hide">隐藏</x-button>
</template>
<script setup lang="uts">
import { xModalPage } from '@/uni_modules/x-design';
const guid = "xdModal-"+Math.random().toString(16).substring(2,20)
const modal = new xModalPage()
const showmodal = ref(false)
const createpage = ()=>{
let ele = uni.getElementById(guid) as UniElement|null;
modal.setView(ele)
}
const show = ()=>{
if(!showmodal.value){
showmodal.value = true;
setTimeout(function() {
modal.show()
}, 250);
}
}
const hide = ()=>{
modal.hide()
}
onMounted(()=>{
uni.$once('onReady',()=>{
createpage()
})
setTimeout(function() {
show()
}, 1500);
})
</script>
<style lang="css" scoped>
.xdModalPage{
display: flex;
}
.xdModalPageOff{
display: none;
}
</style>
@@ -0,0 +1,31 @@
<template>
<view style="width:100%;height:100%;min-height: 250px;">
<native-view @init="onviewinit" style="width:100%;height:100%;"></native-view>
</view>
</template>
<script setup lang="uts">
import { xdPickerView } from '@/uni_modules/x-design';
let xdpicker : xdPickerView | null = null
const props = defineProps({
width:{
type:String,
default:"100%"
}
})
function onviewinit(e : UniNativeViewInitEvent) {
xdpicker = new xdPickerView(e.detail.element);
}
onMounted(() => {
})
</script>
<style>
</style>
+83
View File
@@ -0,0 +1,83 @@
{
"id": "x-design",
"displayName": "x-design",
"version": "1.0.0",
"description": "x-design",
"keywords": [
"x-design"
],
"repository": "",
"engines": {
"HBuilderX": "^4.31"
},
"dcloudext": {
"type": "uts-vue-component",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u",
"alipay": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u",
"app-harmony": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
+46
View File
@@ -0,0 +1,46 @@
# x-design
### 开发文档
[TMUI4.0文档](https://xui.tmui.design/)
[TMUI4.0组件库](https://ext.dcloud.net.cn/plugin?id=16369)
这是标准组件库依赖系列
### 兼容性
| Harmony | IOS | Android | WEB | 小程序 |
| --- | --- | --- | --- | --- |
| 支持 | 支持 | 支持 | 支持 | 支持 |
### 使用
与正常的uvue组件一样使用,但不同的是,这些全是原生标准组件,需要打包或者mac系统配置环境使用,不能在普通win环境使用.
如果在win下使用,请先在页面调用 ,再打基座使用.如果是mac配置好环境可以直接使用.
**xd-blur有三个属性**
blur:0-100模糊度
bgColor:模糊的叠加颜色
into:模糊对象,可选值parent:模糊它的父级(即背景),self:模糊自身内容(标签内的所有内容被模糊)
当模糊背景的时候需要设置为fiexd在根节点的直接子直接,这样可以模糊动态背景内容,当模糊自身内容时,请把内容放到标签内.
### 模糊组件xdBlur
模糊背景:
它的背景会被局部模糊到xd-blur自身(俗称的磨砂背景效果),作为背景模糊时,插槽会失效,因此你要把它当作一个背景图定位到你的内容下方。
```vue
<scroll-view style="flex:1;">
<xd-blur style="position:fixed;left: 0;top: 0px;width: 100%;height: 100px;z-index: 10;"></xd-blur>
</scroll-view>
```
模糊自己的内容:
它的内容会被全部模糊化(俗称的图片模糊,内容模糊)
```vue
<xd-blur into="self">
<x-sheet>
<x-button :block="true" class="mb-12">主色</x-button>
<x-button :block="true" class="mb-12" color="error">错误</x-button>
<x-button :block="true" class="mb-12" color="warn">警告</x-button>
<x-button :block="true" class="mb-12" color="danger">危险</x-button>
<x-button :block="true" class="mb-12" color="success">成功</x-button>
<x-button darkColor="#222222" :block="true" :shadow="[0,0]" class="mb-12" color="info">次要</x-button>
</x-sheet>
</xd-blur>
```
@@ -0,0 +1,7 @@
{
"minSdkVersion": "21",
"dependencies":[
"jp.wasabeef:blurry:4.0.1",
"com.github.Dimezis:BlurView:version-2.0.6"
]
}
@@ -0,0 +1,134 @@
// import UniversalBlurHelper from 'uts.sdk.modules.utsXdBlur.UniversalBlurHelper';
import Color from 'android.graphics.Color';
import View from 'android.view.View';
import Blurry from 'jp.wasabeef.blurry.Blurry'
import ViewGroup from "android.view.ViewGroup";
import Bitmap from "android.graphics.Bitmap";
import ImageView from 'android.widget.ImageView';
import Canvas from 'android.graphics.Canvas';
import BitmapDrawable from "android.graphics.drawable.BitmapDrawable";
import { hexToRgb } from '../libs/color.uts'
import { ManiWinFloat } from './mainWinFloa.uts'
export class xModalPage {
contentView : View | null = null;
rootWin : ManiWinFloat = new ManiWinFloat();
constructor() {
}
setView(ele : UniElement | null) {
if (ele == null) return;
let userView = ele.getAndroidView() as View | null
if (userView == null) return;
this.contentView = userView;
this.rootWin.setContent(userView)
}
show() {
this.rootWin.show()
}
hide() {
}
destroy() {
}
}
export class xdBlur {
$element : UniNativeViewElement;
targetView : View | null = null;
// bgView:bgBlurView = new bgBlurView(UTSAndroid.getAppContext()!)
constructor(element : UniNativeViewElement) {
//接收传递过来的UniNativeViewElement
this.$element = element;
this.bindView();
}
bindView() {
//通过UniElement.getAndroidActivity()获取android平台activity 用于创建view的上下文
this.targetView = new View(this.$element.getAndroidActivity()!); //构建原生view
// this.targetView = new bgBlurView(this.$element.getAndroidActivity()!); //构建原生view
// this.targetView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT))
// //限制原生Button 文案描述不自动大写
// this.button?.setAllCaps(false)
// //监听原生Button点击事件
// this.button?.setOnClickListener(_ => {
// const detail = {}
// //构建自定义UniNativeViewEvent返回对象
// const event = new UniNativeViewEvent("customClick", detail)
// //触发原生Button的点击事件
// this.$element.dispatchEvent(event)
// })
//UniNativeViewEvent 绑定 安卓原生view
this.$element.bindAndroidView(this.targetView!);
}
setFilterBg(blur : number, bgcolor : string, ele : UniElement | null = null) {
// let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
// this.targetView?.refreshBG(decorView)
let colorrgba = hexToRgb(bgcolor)
let r = (colorrgba?.r ?? 255).toInt()
let g = (colorrgba?.g ?? 255).toInt()
let b = (colorrgba?.b ?? 255).toInt()
let a = ((colorrgba?.a ?? 1) * 255).toInt()
let br = (blur / 100 * 25).toFloat()
let view = this.targetView!;
view.setBackgroundColor(Color.argb(a, r, g, b))
let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
let context = UTSAndroid.getAppContext()!;
let bitmap : Bitmap = Blurry.with(context)
.radius(br.toInt()) // 模糊度
.sampling(8) // 采样
.color(Color.argb(a, r, g, b))
.capture(decorView) // 捕获背景View
.get()
let location = new IntArray(2);
view.getLocationInWindow(location);
let top = (location[1]).toInt()
let left = location[0]
let okbitm = Bitmap.createBitmap(bitmap, left, top, view.getWidth(), view.getHeight());
view.setBackground(new BitmapDrawable(view.getResources(), okbitm));
}
public static setFilterSelfBg(ele : UniElement, bg : UniElement, blur : number, bgcolor : string) {
let colorrgba = hexToRgb(bgcolor)
let r = (colorrgba?.r ?? 255).toInt()
let g = (colorrgba?.g ?? 255).toInt()
let b = (colorrgba?.b ?? 255).toInt()
let a = ((colorrgba?.a ?? 1) * 255).toInt()
let br = (blur / 100 * 25).toFloat()
let view = ele.getAndroidView()! as View
let viewbg = bg.getAndroidView()! as View
let context = UTSAndroid.getAppContext()!;
let bitmapbg = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
let canvas = new Canvas(bitmapbg)
view.draw(canvas)
let imgview = new ImageView(context)
Blurry.with(context)
.radius(br.toInt())
.sampling(8)
.color(Color.argb(a, r, g, b))
.from(bitmapbg)
.into(imgview)
viewbg.setBackground(imgview.getDrawable());
}
}
@@ -0,0 +1,82 @@
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 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 ViewPropertyAnimator from 'android.view.ViewPropertyAnimator';
import ScrollView from 'android.widget.ScrollView';
import AccelerateDecelerateInterpolator from 'android.view.animation.AccelerateDecelerateInterpolator';
// #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 Visibility from 'android.transition.Visibility';
// #endif
export class ManiWinFloat {
contentView:View|null = null;
parentView:LinearLayout|null = null;
contentWrap:ScrollView|null = null;
constructor(){
this._createRootView();
}
getContext():Context{
const context = UTSAndroid.getAppContext()! as Context
return context;
}
getWinRoot():ViewGroup{
let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
return decorView;
}
setContent(view:View){
this.contentView = view;
this.contentWrap?.addView(view)
console.log(view)
}
show(){
this.parentView?.setVisibility(View.VISIBLE)
}
hide(){}
destroy(){
}
_createRootView(){
// 内容容器
let container = new LinearLayout(this.getContext());
let containerLayrPrams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
container.setLayoutParams(containerLayrPrams)
container.setBackgroundColor(Color.GREEN)
container.setOrientation(LinearLayout.VERTICAL)
// container.setGravity(Gravity.CENTER)
container.setVisibility(View.GONE)
container.setAlpha((0.3).toFloat())
// 滚动容器
let scroll = new ScrollView(this.getContext())
scroll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
this.contentWrap = scroll;
container.addView(scroll)
this.parentView = container;
this.getWinRoot().addView(this.parentView)
}
}
@@ -0,0 +1,14 @@
@Builder
export function buildXdBlurView(params: ESObject) {
Column(){}.width('100%').height('100%')
.backgroundColor('rgba(255,0,0,0.3')
.backdropBlur(params.blur,{grayscale:[50,50]})
}
@Builder
export function buildXdParentBlurView(params: ESObject) {
Column(){}.width('100%').height('100%')
.backgroundColor('rgba(255,0,0,0.3')
.backdropBlur(params.blur,{grayscale:[50,50]})
}
@@ -0,0 +1,38 @@
import { BuilderNode, ComponentContent } from "@kit.ArkUI"
import { image } from '@kit.ImageKit';
import * from '@ohos.multimedia.image';
import {buildXdBlurView,buildXdParentBlurView} from "./builder.ets"
// 定义 buildButton 的参数类型
interface NativeXdblurOptions {
blur:number
}
export class xdBlur {
$element : UniNativeViewElement;
targetView : BuilderNode<[NativeXdblurOptions]> | null = null;
// 初始化 buildButton 默认参数
private params : NativeXdblurOptions = {
blur: 30,
}
constructor(element : UniNativeViewElement) {
// 绑定 wrapBuilder 函数
this.targetView = element.bindHarmonyWrappedBuilder(wrapBuilder<[NativeXdblurOptions]>(buildXdBlurView), this.params)
this.$element = element
// 绑定当前实例为自定义的controller,方便其他地方通过 element 获取使用
this.$element.bindHarmonyController(this)
// this.targetView.
}
setFilterBg(blur : number, bgcolor : string,ele:UniElement|null = null) {
this.params.blur = blur;
this.targetView?.update(this.params)
}
setFilterSelfBg(ele : UniElement,bg:UniElement, blur : number, bgcolor : string) {
// this.params.blur = blur;
// const parent = this.targetView?.getFrameNode()?.getParent();
// const uiContext = UTSHarmony.getCurrentWindow()!.getUIContext();
// let component = new ComponentContent<ESObject>(uiContext, wrapBuilder<[NativeXdblurOptions]>(buildXdParentBlurView), this.params)
// parent?.addComponentContent(component)
// const px = uiContext.getComponentSnapshot().getSyncWithUniqueId(parent?.getUniqueId()!)
// let pos = image.PositionArea
// ele.getDrawableContext()?.fill(px.readPixelsSync())
}
}
@@ -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>
@@ -0,0 +1,117 @@
import UIKit
class XdBlur {
///
/// - Parameters:
/// - view:
/// - style: Light, Dark, ExtraLight
/// - intensity: 0-1
/// - backgroundColor:
static func applyBlur(
to view: UIView,
style: UIBlurEffect.Style = .light,
intensity: CGFloat = 0.8,
backgroundColor: UIColor? = nil
) {
//
view.subviews
.filter { $0 is UIVisualEffectView }
.forEach { $0.removeFromSuperview() }
//
let blurEffect = UIBlurEffect(style: style)
let blurView = UIVisualEffectView(effect: blurEffect)
//
if #available(iOS 13.0, *) {
let vibrancyView = UIVisualEffectView(effect:
UIVibrancyEffect(blurEffect: blurEffect, style: .fill)
)
blurView.contentView.addSubview(vibrancyView)
}
// frame
blurView.frame = view.bounds
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
//
blurView.alpha = intensity
//
if let backgroundColor = backgroundColor {
let colorView = UIView(frame: blurView.bounds)
colorView.backgroundColor = backgroundColor
colorView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
blurView.contentView.addSubview(colorView)
}
//
view.insertSubview(blurView, at: 0)
}
///
/// - Parameter view:
static func removeBlur(from view: UIView) {
view.subviews
.filter { $0 is UIVisualEffectView }
.forEach { $0.removeFromSuperview() }
}
///
/// - Parameters:
/// - view:
/// - radius:
/// - tintColor:
static func applyCustomBlur(
to view: UIView,
radius: CGFloat = 10,
tintColor: UIColor? = nil
) {
//
let blurEffect = UIBlurEffect(style: .light)
let blurView = UIVisualEffectView(effect: blurEffect)
//
let vibrancyView = UIVisualEffectView(effect:
UIVibrancyEffect(blurEffect: blurEffect)
)
blurView.frame = view.bounds
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
//
if let tintColor = tintColor {
let colorView = UIView(frame: blurView.bounds)
colorView.backgroundColor = tintColor
colorView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
blurView.contentView.addSubview(colorView)
}
view.insertSubview(blurView, at: 0)
}
static func applyBlurSelf(ele: UIView ,bg:UIView, blur: CGFloat, backgroundColor: UIColor = .clear) {
// Create snapshot of element
UIGraphicsBeginImageContextWithOptions(ele.bounds.size, false, 0)
ele.layer.render(in: UIGraphicsGetCurrentContext()!)
let snapshot = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
// Create blur effect
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
effectView.frame = bg.bounds
// Create color overlay
let colorView = UIView(frame: bg.bounds)
colorView.backgroundColor = backgroundColor
colorView.alpha = blur
// Add views to background
bg.addSubview(effectView)
bg.addSubview(colorView)
// Set snapshot as background
let imageView = UIImageView(image: snapshot)
imageView.frame = bg.bounds
bg.insertSubview(imageView, at: 0)
}
}
@@ -0,0 +1,3 @@
{
"deploymentTarget": "12"
}
@@ -0,0 +1,103 @@
import { UIViewController, UIView, UIWindow, UIScreen, UIColor, UIBlurEffect } from 'UIKit';
import { CGRect, CGFloat, CGPoint, CGAffineTransform, CGSize } from 'CoreFoundation';
import { CABasicAnimation, CAMediaTimingFillMode, CATransform3DIsIdentity, CATransform3DIdentity, CATransform3DMakeTranslation, CATransform3DRotate, CATransform3DScale } from 'QuartzCore';
import { getRootView } from "./libs/util.uts"
import { Color } from 'SwiftUI';
import { hexToRgb } from '../libs/color.uts'
export class xModalPage {
contentView : UIView | null = null;
rootWin : UIWindow;
constructor() {
let winsize = UIScreen.main.bounds as CGRect;
let mainwidth = new CGRect(x = 0, y = 180, width = 300, height = 200)
// 创建一个新的 UIWindow 实例
let newWindow = new UIWindow(frame = mainwidth)
// newWindow.frame = mainwidth
this.rootWin = newWindow;
}
setView(ele : UniElement | null) {
if (ele == null) return;
let userView = ele!.getIOSView() as UIView | null
if (userView == null) return;
this.contentView = userView!;
class ContentWin extends UIViewController {
userView : UIView | null = null;
setAddView(userViewBox : UIView | null) {
this.userView = userViewBox;
}
override viewDidLoad() {
super.viewDidLoad();
let root = super.view as UIView;
root.backgroundColor = UIColor.black
if (this.userView != null) {
let cview = this.userView! as UIView;
cview.frame = UIScreen.main.bounds
root.addSubview(cview)
}
}
}
if (this.contentView == null) return;
DispatchQueue.main.async(execute = () : void => {
// 创建一个新的 UIViewController 实例作为模态视图控制器
let secondViewController = new ContentWin()
secondViewController.setAddView(this.contentView)
// 将模态视图控制器添加到新窗口中
this.rootWin.rootViewController = secondViewController as UIViewController
})
}
show() {
let pageconroll = this.rootWin.rootViewController;
if (this.contentView == null || pageconroll == null) return;
DispatchQueue.main.async(execute = () : void => {
this.rootWin.makeKeyAndVisible()
let parent = UTSiOS.getCurrentViewController() as UIViewController;
parent.present(pageconroll!, animated = true, completion = nil)
})
}
hide() {
DispatchQueue.main.async(execute = () : void => {
this.rootWin.rootViewController?.dismiss(animated = true, completion = nil)
})
}
destroy() {
}
}
export class xdBlur {
$element : UniNativeViewElement;
targetView : UIView | null = null;
constructor(element : UniNativeViewElement) {
//接收传递过来的UniNativeViewElement
this.$element = element;
this.targetView = new UIView()
this.$element.bindIOSView(this.targetView!);
}
setFilterBg(blur : number, bgcolor : string,ele:UniElement|null = null) {
let colorrgba = hexToRgb(bgcolor)
let br = (blur / 100).toFloat()
let view = this.targetView!
XdBlur.applyBlur(
to = view,
style = UIBlurEffect.Style.light,
intensity = new CGFloat(br),
backgroundColor = UTSiOS.colorWithString(bgcolor)
)
}
public static setFilterSelfBg(ele : UniElement,bg:UniElement, blur : number, bgcolor : string) {
let colorrgba = hexToRgb(bgcolor)
let br = (blur / 100).toFloat()
let view = ele.getIOSView()! as UIView
let viewbg = bg.getIOSView()! as UIView
XdBlur.applyBlurSelf(ele=view,bg = viewbg, blur = new CGFloat(br), backgroundColor = UTSiOS.colorWithString(bgcolor))
}
}
@@ -0,0 +1,10 @@
import { UIViewController, UIView } from 'UIKit';
export function getRootView() : UIView {
let parent = UTSiOS.getCurrentViewController() as UIViewController;
let windUiview = parent.view as UIView
return windUiview;
}
export function getRoot() : UIViewController {
let parent = UTSiOS.getCurrentViewController() as UIViewController;
return parent;
}
@@ -0,0 +1,65 @@
type RGBA = { r : number, g : number, b : number, a : number }
export function hexToRgb(sColors : string) : RGBA | null {
if (sColors == "") {
return { r: 0, g: 0, b: 0, a: 0 } as RGBA
}
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) {
arr.push('1')
}
return {
r: p[0],
g: p[1],
b: p[2],
a: parseFloat(arr[3])
} as RGBA
} else {
return {
r: 0,
g: 0,
b: 0,
a: 1
} as RGBA
}
return null;
}
@@ -0,0 +1,50 @@
import { hexToRgb } from '../libs/color.uts'
export class xModalPage {
contentView : HTMLDivElement | null = null;
rootWin : HTMLDivElement | null = null;
constructor() {
}
setView(ele : HTMLDivElement | null) {
}
show() {
}
hide() {
}
destroy() {
}
}
export class xdBlur {
constructor(element : UniNativeViewElement) {
}
setFilterBg( blur : number, bgcolor : string,ele : HTMLDivElement|null=null) {
let colorrgba = hexToRgb(bgcolor)
let r = (colorrgba?.r??255)
let g = (colorrgba?.g??255)
let b = (colorrgba?.b??255)
let a = (colorrgba?.a??1)
let br = blur
ele?.style.setProperty('background-color',`rgba(${r},${g},${b},${a})`)
ele?.style.setProperty('backdrop-filter',`blur(${Math.min(br,10)}px)`)
}
public static setFilterSelfBg(ele : HTMLDivElement,bg:HTMLDivElement, blur : number, bgcolor : string) {
let colorrgba = hexToRgb(bgcolor)
let r = (colorrgba?.r??255)
let g = (colorrgba?.g??255)
let b = (colorrgba?.b??255)
let a = (colorrgba?.a??1)
let br = blur
bg.style.setProperty('background-color',`rgba(${r},${g},${b},${a})`)
bg.style.setProperty('backdrop-filter',`blur(${Math.min(br,10)}px)`)
}
}
+51
View File
@@ -0,0 +1,51 @@
import { hexToRgb } from '../libs/color.uts'
export class xModalPage {
contentView : HTMLDivElement | null = null;
rootWin : HTMLDivElement | null = null;
constructor() {
}
setView(ele : HTMLDivElement | null) {
}
show() {
}
hide() {
}
destroy() {
}
}
export class xdBlur {
constructor(element : UniNativeViewElement) {
}
setFilterBg( blur : number, bgcolor : string,ele : HTMLDivElement|null=null) {
let colorrgba = hexToRgb(bgcolor)
let r = (colorrgba?.r??255)
let g = (colorrgba?.g??255)
let b = (colorrgba?.b??255)
let a = (colorrgba?.a??1)
let br = blur
ele?.style.setProperty('background-color',`rgba(${r},${g},${b},${a})`)
ele?.style.setProperty('backdrop-filter',`blur(${Math.min(br,10)}px)`)
}
public static setFilterSelfBg(ele : HTMLDivElement,bg:HTMLDivElement, blur : number, bgcolor : string) {
let colorrgba = hexToRgb(bgcolor)
let r = (colorrgba?.r??255)
let g = (colorrgba?.g??255)
let b = (colorrgba?.b??255)
let a = (colorrgba?.a??1)
let br = blur
bg.style.setProperty('background-color',`rgba(${r},${g},${b},${a})`)
bg.style.setProperty('backdrop-filter',`blur(${Math.min(br,10)}px)`)
}
}