1
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"minSdkVersion": "21",
|
||||
"dependencies":[
|
||||
"com.caverock:androidsvg:1.4"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import View from "android.view.View";
|
||||
import InputStream from "java.io.InputStream";
|
||||
import Context from "com.alibaba.fastjson.parser.deserializer.ASMDeserializerFactory.Context";
|
||||
import FileInputStream from "java.io.FileInputStream";
|
||||
import File from "java.io.File";
|
||||
import PictureDrawable from "android.graphics.drawable.PictureDrawable";
|
||||
import SVG from "com.caverock.androidsvg.SVG"
|
||||
import ImageView from 'android.widget.ImageView';
|
||||
|
||||
export class xSvgU {
|
||||
$element : UniNativeViewElement;
|
||||
targetView : ImageView | null = null;
|
||||
constructor(element : UniNativeViewElement) {
|
||||
//接收传递过来的UniNativeViewElement
|
||||
this.$element = element;
|
||||
this.bindView();
|
||||
}
|
||||
bindView() {
|
||||
this.targetView = new ImageView(this.$element.getAndroidActivity()!); //构建原生view
|
||||
this.$element.bindAndroidView(this.targetView!);
|
||||
}
|
||||
setImage(newval:string){
|
||||
let furl = UTSAndroid.convert2AbsFullPath(newval)
|
||||
let inputStream:InputStream|null = null;
|
||||
if(furl.indexOf('android_asset')==-1){
|
||||
inputStream = new FileInputStream(new File(furl))
|
||||
}else{
|
||||
inputStream = UTSAndroid.getUniActivity()!.getAssets().open(furl.replace("/android_asset/", ""));
|
||||
}
|
||||
if(inputStream ==null) return
|
||||
let svg = SVG.getFromInputStream(inputStream!);
|
||||
let pictureDrawable = new PictureDrawable(svg.renderToPicture());
|
||||
this.targetView?.setImageDrawable(pictureDrawable);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class xSvgU {}
|
||||
@@ -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,7 @@
|
||||
{
|
||||
"deploymentTarget": "12",
|
||||
"dependencies-pods": [{
|
||||
"name": "SVGKit",
|
||||
"version": "3.0.0"
|
||||
}]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
UIButton,
|
||||
UIControl,
|
||||
UIImageView,
|
||||
UIImage
|
||||
} from "UIKit"
|
||||
import { SVGKImage } from "SVGKit" assert { type: "implementationOnly" };
|
||||
import { UTSComponent } from "DCloudUTSFoundation"
|
||||
import { Data } from 'Assignables';
|
||||
import { CALayer } from 'QuartzCore';
|
||||
import { CGRect, CGSize } from 'CoreFoundation';
|
||||
|
||||
|
||||
|
||||
export class xSvgU {
|
||||
$element : UniNativeViewElement;
|
||||
targetView : UIImageView | null = null;
|
||||
constructor(element : UniNativeViewElement) {
|
||||
this.$element = element;
|
||||
this.targetView = new UIImageView()
|
||||
this.$element.bindIOSView(this.targetView!);
|
||||
}
|
||||
|
||||
setImage(newval : string) {
|
||||
if (newval != '') {
|
||||
let url = UTSiOS.getResourcePath(newval)
|
||||
// let width = (16).toInt();
|
||||
// let height = (16).toInt();
|
||||
// this.targetView!.frame = new CGRect(x = 0, y = 0, width = width, height = height);
|
||||
const size:CGRect = this.targetView!.frame;
|
||||
let svgURL = new URL(fileURLWithPath = url)
|
||||
let svgData = UTSiOS.try(new Data(contentsOf = svgURL),"?")
|
||||
if(svgData==null) return;
|
||||
let svgImage = new SVGKImage(data = svgData!)
|
||||
svgImage!.size = new CGSize(width= size.width, height= size.height)
|
||||
this.targetView!.image = svgImage?.uiImage
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export type xSvgPropsType = {
|
||||
src:string,
|
||||
width:number,
|
||||
height:number,
|
||||
color:string
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class xSvgU {}
|
||||
@@ -0,0 +1 @@
|
||||
export class xSvgU {}
|
||||
Reference in New Issue
Block a user