This commit is contained in:
2026-09-24 16:25:22 +08:00
commit 7428184f01
1198 changed files with 314515 additions and 0 deletions
@@ -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)`)
}
}