feat:android support ArrayBuffer Resource
This commit is contained in:
parent
3bedd8034c
commit
e270b9c520
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package pub.doric.plugin;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.extension.bridge.DoricMethod;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.extension.bridge.DoricPromise;
|
||||
import pub.doric.resource.DoricResource;
|
||||
import pub.doric.utils.DoricLog;
|
||||
|
||||
/**
|
||||
* @Description: This is for loading resource into js as ArrayBuffer
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2021/11/18
|
||||
*/
|
||||
@DoricPlugin(name = "imageDecoder")
|
||||
public class ImageDecoderPlugin extends DoricJavaPlugin {
|
||||
|
||||
public ImageDecoderPlugin(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void getImageInfo(final JSObject resource, final DoricPromise promise) {
|
||||
DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager().load(
|
||||
getDoricContext(),
|
||||
resource);
|
||||
if (doricResource != null) {
|
||||
doricResource.fetch().setCallback(new AsyncResult.Callback<byte[]>() {
|
||||
@Override
|
||||
public void onResult(byte[] rawData) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeByteArray(rawData, 0, rawData.length, options);
|
||||
promise.resolve(new JavaValue(new JSONBuilder()
|
||||
.put("width", options.outWidth)
|
||||
.put("height", options.outHeight)
|
||||
.put("mimeType", options.outMimeType)
|
||||
.toJSONObject()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
t.printStackTrace();
|
||||
DoricLog.e("Cannot load resource %s, %s", resource.toString(), t.getLocalizedMessage());
|
||||
promise.reject(new JavaValue("Load error"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
DoricLog.e("Cannot find loader for resource %s", resource);
|
||||
promise.reject(new JavaValue("Load error"));
|
||||
}
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void decodeToPixels(final JSObject resource, final DoricPromise promise) {
|
||||
DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager().load(
|
||||
getDoricContext(),
|
||||
resource);
|
||||
if (doricResource != null) {
|
||||
doricResource.fetch().setCallback(new AsyncResult.Callback<byte[]>() {
|
||||
@Override
|
||||
public void onResult(byte[] rawData) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(rawData, 0, rawData.length);
|
||||
ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
|
||||
bitmap.copyPixelsToBuffer(buffer);
|
||||
promise.resolve(new JavaValue(buffer.array()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
t.printStackTrace();
|
||||
DoricLog.e("Cannot load resource %s, %s", resource.toString(), t.getLocalizedMessage());
|
||||
promise.reject(new JavaValue("Load error"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
DoricLog.e("Cannot find loader for resource %s", resource);
|
||||
promise.reject(new JavaValue("Load error"));
|
||||
}
|
||||
}
|
||||
}
|
@ -43,15 +43,9 @@ public class ResourceLoaderPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void load(JSObject resource, final DoricPromise promise) {
|
||||
final String resId = resource.getProperty("resId").asString().value();
|
||||
final String type = resource.getProperty("type").asString().value();
|
||||
final String identifier = resource.getProperty("identifier").asString().value();
|
||||
public void load(final JSObject resource, final DoricPromise promise) {
|
||||
DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager().load(
|
||||
getDoricContext(),
|
||||
resId,
|
||||
type,
|
||||
identifier);
|
||||
getDoricContext(), resource);
|
||||
if (doricResource != null) {
|
||||
doricResource.fetch().setCallback(new AsyncResult.Callback<byte[]>() {
|
||||
@Override
|
||||
@ -62,7 +56,7 @@ public class ResourceLoaderPlugin extends DoricJavaPlugin {
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
t.printStackTrace();
|
||||
DoricLog.e("Cannot load resource type = %s, identifier = %s, %s", type, identifier, t.getLocalizedMessage());
|
||||
DoricLog.e("Cannot load resource %s, %s", resource.toString(), t.getLocalizedMessage());
|
||||
promise.reject(new JavaValue("Load error"));
|
||||
}
|
||||
|
||||
@ -72,7 +66,7 @@ public class ResourceLoaderPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
DoricLog.e("Cannot find loader for resource type = %s, identifier = %s", type, identifier);
|
||||
DoricLog.e("Cannot find loader for resource %s", resource);
|
||||
promise.reject(new JavaValue("Load error"));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package pub.doric.resource;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.async.AsyncResult;
|
||||
|
||||
/**
|
||||
* @Description: This represents an arrayBuffer resource
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2021/11/18
|
||||
*/
|
||||
public class DoricArrayBufferResource extends DoricResource {
|
||||
private final byte[] data;
|
||||
|
||||
public DoricArrayBufferResource(DoricContext doricContext, byte[] data) {
|
||||
super(doricContext, "");
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncResult<byte[]> fetchRaw() {
|
||||
return new AsyncResult<>(data);
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package pub.doric.resource;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
@ -43,17 +45,18 @@ public class DoricResourceManager {
|
||||
|
||||
@Nullable
|
||||
public synchronized DoricResource load(@NonNull DoricContext doricContext,
|
||||
@NonNull String resId,
|
||||
@NonNull String type,
|
||||
@NonNull String identifier) {
|
||||
DoricResource resource = cachedResources.get(resId);
|
||||
if (resource == null) {
|
||||
@NonNull JSObject resource) {
|
||||
String resId = resource.getProperty("resId").asString().value();
|
||||
String type = resource.getProperty("type").asString().value();
|
||||
String identifier = resource.getProperty("identifier").asString().value();
|
||||
DoricResource doricResource = cachedResources.get(resId);
|
||||
if (doricResource == null) {
|
||||
DoricResourceLoader loader = mResourceLoaders.get(type);
|
||||
if (loader != null) {
|
||||
resource = loader.load(doricContext, identifier);
|
||||
cachedResources.put(resId, resource);
|
||||
doricResource = loader.load(doricContext, identifier);
|
||||
cachedResources.put(resId, doricResource);
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
return doricResource;
|
||||
}
|
||||
}
|
||||
|
@ -396,12 +396,9 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
if (!prop.isObject()) {
|
||||
return;
|
||||
}
|
||||
JSObject resource = prop.asObject();
|
||||
final String resourceId = resource.getProperty("resId").asString().value();
|
||||
final String type = resource.getProperty("type").asString().value();
|
||||
final String identifier = resource.getProperty("identifier").asString().value();
|
||||
final JSObject resource = prop.asObject();
|
||||
DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager()
|
||||
.load(getDoricContext(), resourceId, type, identifier);
|
||||
.load(getDoricContext(), resource);
|
||||
if (doricResource != null) {
|
||||
doricResource.fetch().setCallback(new AsyncResult.Callback<byte[]>() {
|
||||
@Override
|
||||
@ -412,7 +409,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
t.printStackTrace();
|
||||
DoricLog.e("Cannot load resource type = %s, identifier = %s, %s", type, identifier, t.getLocalizedMessage());
|
||||
DoricLog.e("Cannot load resource %s, %s", resource.toString(), t.getLocalizedMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -421,7 +418,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
DoricLog.e("Cannot find loader for resource type = %s, identifier = %s", type, identifier);
|
||||
DoricLog.e("Cannot find loader for resource %s", resource.toString());
|
||||
}
|
||||
break;
|
||||
case "imageUrl":
|
||||
|
@ -14,14 +14,17 @@ import {
|
||||
Text,
|
||||
Gravity,
|
||||
resourceLoader,
|
||||
imageDecoder,
|
||||
createRef,
|
||||
loge,
|
||||
} from "doric";
|
||||
import { colors, label } from "./utils";
|
||||
import { img_base64 } from "./image_base64";
|
||||
import { loge } from "doric/lib/src/util/log";
|
||||
|
||||
@Entry
|
||||
export class ResourceDemo extends Panel {
|
||||
build(root: Group): void {
|
||||
const iv = createRef<Image>();
|
||||
<Scroller parent={root} layoutConfig={layoutConfig().most()}>
|
||||
<VLayout
|
||||
layoutConfig={layoutConfig().mostWidth().fitHeight()}
|
||||
@ -53,12 +56,24 @@ export class ResourceDemo extends Panel {
|
||||
/>
|
||||
<Image
|
||||
image={new Base64Resource(img_base64[0])}
|
||||
ref={iv}
|
||||
onClick={async () => {
|
||||
const resource = new RemoteResource(
|
||||
"https://p.upyun.com/demo/webp/webp/jpg-0.webp"
|
||||
);
|
||||
const rawData = await resourceLoader(context).load(resource);
|
||||
loge(rawData.byteLength);
|
||||
const imageInfo = await imageDecoder(context).getImageInfo(
|
||||
resource
|
||||
);
|
||||
loge(imageInfo);
|
||||
const pixels = await imageDecoder(context).decodeToPixels(resource);
|
||||
const unit8Array = new Uint8Array(pixels);
|
||||
for (let i = 0; i < unit8Array.length; i += 4) {
|
||||
unit8Array[i] -= 20;
|
||||
}
|
||||
loge(pixels.byteLength);
|
||||
iv.current.image = resource;
|
||||
}}
|
||||
/>
|
||||
</VLayout>
|
||||
|
@ -2243,7 +2243,18 @@ var BundleResource = /** @class */ (function (_super) {
|
||||
return _super.call(this, "bundle", bundleName + "://" + fileName) || this;
|
||||
}
|
||||
return BundleResource;
|
||||
<<<<<<< HEAD
|
||||
}(iOSResource));
|
||||
=======
|
||||
}(Resource));
|
||||
var ArrayBufferResource = /** @class */ (function (_super) {
|
||||
__extends$e(ArrayBufferResource, _super);
|
||||
function ArrayBufferResource(data) {
|
||||
return _super.call(this, "arrayBuffer", "") || this;
|
||||
}
|
||||
return ArrayBufferResource;
|
||||
}(Resource));
|
||||
>>>>>>> f476a5b0... feat:android support ArrayBuffer Resource
|
||||
|
||||
var __extends$e = (undefined && undefined.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
@ -3999,7 +4010,7 @@ function repeat(action) {
|
||||
};
|
||||
}
|
||||
|
||||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
@ -4008,7 +4019,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
||||
var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) { throw t[1]; } return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
@ -4055,8 +4066,8 @@ function animate(context) {
|
||||
var entity = context.entity;
|
||||
if (entity instanceof Panel) {
|
||||
var panel_1 = entity;
|
||||
return function (args) { return __awaiter(_this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return function (args) { return __awaiter$1(_this, void 0, void 0, function () {
|
||||
return __generator$1(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, context.callNative('animate', 'submit')];
|
||||
case 1:
|
||||
@ -4213,6 +4224,71 @@ function resourceLoader(context) {
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) { throw t[1]; } return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) { throw new TypeError("Generator is already executing."); }
|
||||
while (_) { try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) { return t; }
|
||||
if (y = 0, t) { op = [op[0] & 2, t.value]; }
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) { _.ops.pop(); }
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } }
|
||||
if (op[0] & 5) { throw op[1]; } return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
function imageDecoder(context) {
|
||||
var _this = this;
|
||||
return {
|
||||
getImageInfo: function (resource) {
|
||||
return context.callNative('imageDecoder', 'getImageInfo', resource);
|
||||
},
|
||||
decodeToPixels: function (resource) { return __awaiter(_this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, context.callNative('imageDecoder', 'decodeToPixels', resource)];
|
||||
});
|
||||
}); },
|
||||
};
|
||||
}
|
||||
|
||||
var __values = (undefined && undefined.__values) || function(o) {
|
||||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||||
if (m) { return m.call(o); }
|
||||
@ -4539,7 +4615,12 @@ exports.AlphaAnimation = AlphaAnimation;
|
||||
exports.AndroidAssetsResource = AndroidAssetsResource;
|
||||
exports.AndroidResource = AndroidResource;
|
||||
exports.AnimationSet = AnimationSet;
|
||||
<<<<<<< HEAD
|
||||
exports.AssetsResource = AssetsResource;
|
||||
=======
|
||||
exports.ArrayBufferResource = ArrayBufferResource;
|
||||
exports.AssetResource = AssetResource;
|
||||
>>>>>>> f476a5b0... feat:android support ArrayBuffer Resource
|
||||
exports.BOTTOM = BOTTOM;
|
||||
exports.BackgroundColorAnimation = BackgroundColorAnimation;
|
||||
exports.Base64Resource = Base64Resource;
|
||||
@ -4618,6 +4699,7 @@ exports.gravity = gravity;
|
||||
exports.hlayout = hlayout;
|
||||
exports.iOSResource = iOSResource;
|
||||
exports.image = image;
|
||||
exports.imageDecoder = imageDecoder;
|
||||
exports.input = input;
|
||||
exports.internalScheme = internalScheme;
|
||||
exports.keyboard = keyboard;
|
||||
|
@ -1680,6 +1680,11 @@ class BundleResource extends iOSResource {
|
||||
super("bundle", `${bundleName}://${fileName}`);
|
||||
}
|
||||
}
|
||||
class ArrayBufferResource extends Resource {
|
||||
constructor(data) {
|
||||
super("arrayBuffer", "");
|
||||
}
|
||||
}
|
||||
|
||||
var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
@ -3084,7 +3089,7 @@ function repeat(action) {
|
||||
};
|
||||
}
|
||||
|
||||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
@ -3101,7 +3106,7 @@ function animate(context) {
|
||||
const entity = context.entity;
|
||||
if (entity instanceof Panel) {
|
||||
let panel = entity;
|
||||
return (args) => __awaiter(this, void 0, void 0, function* () {
|
||||
return (args) => __awaiter$1(this, void 0, void 0, function* () {
|
||||
yield context.callNative('animate', 'submit');
|
||||
args.animations();
|
||||
return takeLet(panel.getRootView())(root => {
|
||||
@ -3232,6 +3237,41 @@ function resourceLoader(context) {
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
function imageDecoder(context) {
|
||||
return {
|
||||
getImageInfo: (resource) => {
|
||||
return context.callNative('imageDecoder', 'getImageInfo', resource);
|
||||
},
|
||||
decodeToPixels: (resource) => __awaiter(this, void 0, void 0, function* () {
|
||||
return context.callNative('imageDecoder', 'decodeToPixels', resource);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
class Observable {
|
||||
constructor(provider, clz) {
|
||||
this.observers = new Set;
|
||||
@ -3470,7 +3510,12 @@ exports.AlphaAnimation = AlphaAnimation;
|
||||
exports.AndroidAssetsResource = AndroidAssetsResource;
|
||||
exports.AndroidResource = AndroidResource;
|
||||
exports.AnimationSet = AnimationSet;
|
||||
<<<<<<< HEAD
|
||||
exports.AssetsResource = AssetsResource;
|
||||
=======
|
||||
exports.ArrayBufferResource = ArrayBufferResource;
|
||||
exports.AssetResource = AssetResource;
|
||||
>>>>>>> f476a5b0... feat:android support ArrayBuffer Resource
|
||||
exports.BOTTOM = BOTTOM;
|
||||
exports.BackgroundColorAnimation = BackgroundColorAnimation;
|
||||
exports.Base64Resource = Base64Resource;
|
||||
@ -3549,6 +3594,7 @@ exports.gravity = gravity;
|
||||
exports.hlayout = hlayout;
|
||||
exports.iOSResource = iOSResource;
|
||||
exports.image = image;
|
||||
exports.imageDecoder = imageDecoder;
|
||||
exports.input = input;
|
||||
exports.internalScheme = internalScheme;
|
||||
exports.keyboard = keyboard;
|
||||
|
@ -3208,6 +3208,11 @@ class BundleResource extends iOSResource {
|
||||
super("bundle", `${bundleName}://${fileName}`);
|
||||
}
|
||||
}
|
||||
class ArrayBufferResource extends Resource {
|
||||
constructor(data) {
|
||||
super("arrayBuffer", "");
|
||||
}
|
||||
}
|
||||
|
||||
var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
@ -4612,7 +4617,7 @@ function repeat(action) {
|
||||
};
|
||||
}
|
||||
|
||||
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
@ -4629,7 +4634,7 @@ function animate(context) {
|
||||
const entity = context.entity;
|
||||
if (entity instanceof Panel) {
|
||||
let panel = entity;
|
||||
return (args) => __awaiter$1(this, void 0, void 0, function* () {
|
||||
return (args) => __awaiter$2(this, void 0, void 0, function* () {
|
||||
yield context.callNative('animate', 'submit');
|
||||
args.animations();
|
||||
return takeLet(panel.getRootView())(root => {
|
||||
@ -4760,6 +4765,41 @@ function resourceLoader(context) {
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
function imageDecoder(context) {
|
||||
return {
|
||||
getImageInfo: (resource) => {
|
||||
return context.callNative('imageDecoder', 'getImageInfo', resource);
|
||||
},
|
||||
decodeToPixels: (resource) => __awaiter$1(this, void 0, void 0, function* () {
|
||||
return context.callNative('imageDecoder', 'decodeToPixels', resource);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
class Observable {
|
||||
constructor(provider, clz) {
|
||||
this.observers = new Set;
|
||||
@ -5239,7 +5279,12 @@ exports.AlphaAnimation = AlphaAnimation;
|
||||
exports.AndroidAssetsResource = AndroidAssetsResource;
|
||||
exports.AndroidResource = AndroidResource;
|
||||
exports.AnimationSet = AnimationSet;
|
||||
<<<<<<< HEAD
|
||||
exports.AssetsResource = AssetsResource;
|
||||
=======
|
||||
exports.ArrayBufferResource = ArrayBufferResource;
|
||||
exports.AssetResource = AssetResource;
|
||||
>>>>>>> f476a5b0... feat:android support ArrayBuffer Resource
|
||||
exports.BOTTOM = BOTTOM;
|
||||
exports.BackgroundColorAnimation = BackgroundColorAnimation;
|
||||
exports.Base64Resource = Base64Resource;
|
||||
@ -5318,6 +5363,7 @@ exports.gravity = gravity;
|
||||
exports.hlayout = hlayout;
|
||||
exports.iOSResource = iOSResource;
|
||||
exports.image = image;
|
||||
exports.imageDecoder = imageDecoder;
|
||||
exports.input = input;
|
||||
exports.internalScheme = internalScheme;
|
||||
exports.keyboard = keyboard;
|
||||
|
17
doric-js/index.d.ts
vendored
17
doric-js/index.d.ts
vendored
@ -113,6 +113,7 @@ declare module 'doric/lib/src/native/index.native' {
|
||||
export * from 'doric/lib/src/native/notch';
|
||||
export * from 'doric/lib/src/native/keyboard';
|
||||
export * from 'doric/lib/src/native/resourceLoader';
|
||||
export * from 'doric/lib/src/native/imageDecoder';
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/util/index.util' {
|
||||
@ -1353,6 +1354,19 @@ declare module 'doric/lib/src/native/resourceLoader' {
|
||||
};
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/native/imageDecoder' {
|
||||
import { Resource } from "doric/lib/src/util/resource";
|
||||
import { BridgeContext } from "doric/lib/src/runtime/global";
|
||||
export function imageDecoder(context: BridgeContext): {
|
||||
getImageInfo: (resource: Resource) => Promise<{
|
||||
width: number;
|
||||
height: number;
|
||||
mimeType: string;
|
||||
}>;
|
||||
decodeToPixels: (resource: Resource) => Promise<ArrayBuffer>;
|
||||
};
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/util/color' {
|
||||
import { Modeling } from "doric/lib/src/util/types";
|
||||
/**
|
||||
@ -1736,6 +1750,9 @@ declare module 'doric/lib/src/util/resource' {
|
||||
export class BundleResource extends iOSResource {
|
||||
constructor(bundleName: string, fileName: string);
|
||||
}
|
||||
export class ArrayBufferResource extends Resource {
|
||||
constructor(data: ArrayBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/pattern/candies' {
|
||||
|
5
doric-js/lib/src/native/imageDecoder.d.ts
vendored
5
doric-js/lib/src/native/imageDecoder.d.ts
vendored
@ -1,9 +1,10 @@
|
||||
import { Resource } from "../util/resource";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
export declare function imageDecoder(context: BridgeContext): {
|
||||
decode: (resource: Resource) => Promise<{
|
||||
getImageInfo: (resource: Resource) => Promise<{
|
||||
width: number;
|
||||
height: number;
|
||||
format: string;
|
||||
mimeType: string;
|
||||
}>;
|
||||
decodeToPixels: (resource: Resource) => Promise<ArrayBuffer>;
|
||||
};
|
||||
|
@ -24,12 +24,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
};
|
||||
export function imageDecoder(context) {
|
||||
return {
|
||||
decode: (resource) => __awaiter(this, void 0, void 0, function* () {
|
||||
yield context.callNative('imageDecoder', 'loadResource', resource);
|
||||
const imageInfo = yield context.callNative('imageDecoder', 'getImageInfo', resource.resId);
|
||||
const pixels = yield context.callNative('imageDecoder', 'decodeToPixels', resource.resId);
|
||||
yield context.callNative('imageDecoder', 'releaseResource', resource.resId);
|
||||
return Object.assign(Object.assign({}, imageInfo), { pixels });
|
||||
getImageInfo: (resource) => {
|
||||
return context.callNative('imageDecoder', 'getImageInfo', resource);
|
||||
},
|
||||
decodeToPixels: (resource) => __awaiter(this, void 0, void 0, function* () {
|
||||
return context.callNative('imageDecoder', 'decodeToPixels', resource);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
1
doric-js/lib/src/native/index.native.d.ts
vendored
1
doric-js/lib/src/native/index.native.d.ts
vendored
@ -11,3 +11,4 @@ export * from './coordinator';
|
||||
export * from './notch';
|
||||
export * from './keyboard';
|
||||
export * from './resourceLoader';
|
||||
export * from './imageDecoder';
|
||||
|
@ -26,3 +26,4 @@ export * from './coordinator';
|
||||
export * from './notch';
|
||||
export * from './keyboard';
|
||||
export * from './resourceLoader';
|
||||
export * from './imageDecoder';
|
||||
|
3
doric-js/lib/src/util/resource.d.ts
vendored
3
doric-js/lib/src/util/resource.d.ts
vendored
@ -50,3 +50,6 @@ export declare class MainBundleResource extends iOSResource {
|
||||
export declare class BundleResource extends iOSResource {
|
||||
constructor(bundleName: string, fileName: string);
|
||||
}
|
||||
export declare class ArrayBufferResource extends Resource {
|
||||
constructor(data: ArrayBuffer);
|
||||
}
|
||||
|
@ -71,3 +71,8 @@ export class BundleResource extends iOSResource {
|
||||
super("bundle", `${bundleName}://${fileName}`);
|
||||
}
|
||||
}
|
||||
export class ArrayBufferResource extends Resource {
|
||||
constructor(data) {
|
||||
super("arrayBuffer", "");
|
||||
}
|
||||
}
|
||||
|
@ -19,26 +19,19 @@ import { BridgeContext } from "../runtime/global"
|
||||
|
||||
export function imageDecoder(context: BridgeContext) {
|
||||
return {
|
||||
decode: async (resource: Resource) => {
|
||||
await context.callNative('imageDecoder', 'loadResource', resource);
|
||||
const imageInfo = await context.callNative(
|
||||
getImageInfo: (resource: Resource) => {
|
||||
return context.callNative(
|
||||
'imageDecoder',
|
||||
'getImageInfo',
|
||||
resource.resId) as Promise<
|
||||
resource) as Promise<
|
||||
{
|
||||
width: number,
|
||||
height: number,
|
||||
format: string,
|
||||
mimeType: string,
|
||||
}>;
|
||||
const pixels = await context.callNative(
|
||||
'imageDecoder',
|
||||
'decodeToPixels',
|
||||
resource.resId) as Promise<ArrayBuffer>;
|
||||
await context.callNative('imageDecoder', 'releaseResource', resource.resId);
|
||||
return {
|
||||
...imageInfo,
|
||||
pixels,
|
||||
};
|
||||
},
|
||||
decodeToPixels: async (resource: Resource) => {
|
||||
return context.callNative('imageDecoder', 'decodeToPixels', resource) as Promise<ArrayBuffer>;
|
||||
},
|
||||
}
|
||||
}
|
@ -26,3 +26,4 @@ export * from './coordinator'
|
||||
export * from './notch'
|
||||
export * from './keyboard'
|
||||
export * from './resourceLoader'
|
||||
export * from './imageDecoder'
|
@ -83,3 +83,10 @@ export class BundleResource extends iOSResource {
|
||||
super("bundle", `${bundleName}://${fileName}`)
|
||||
}
|
||||
}
|
||||
|
||||
export class ArrayBufferResource extends Resource {
|
||||
constructor(data: ArrayBuffer) {
|
||||
super("arrayBuffer", "")
|
||||
}
|
||||
|
||||
}
|
50
doric-web/dist/index.js
vendored
50
doric-web/dist/index.js
vendored
@ -3282,6 +3282,11 @@ class BundleResource extends iOSResource {
|
||||
super("bundle", `${bundleName}://${fileName}`);
|
||||
}
|
||||
}
|
||||
class ArrayBufferResource extends Resource {
|
||||
constructor(data) {
|
||||
super("arrayBuffer", "");
|
||||
}
|
||||
}
|
||||
|
||||
var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
@ -4686,7 +4691,7 @@ function repeat(action) {
|
||||
};
|
||||
}
|
||||
|
||||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
@ -4703,7 +4708,7 @@ function animate(context) {
|
||||
const entity = context.entity;
|
||||
if (entity instanceof Panel) {
|
||||
let panel = entity;
|
||||
return (args) => __awaiter(this, void 0, void 0, function* () {
|
||||
return (args) => __awaiter$1(this, void 0, void 0, function* () {
|
||||
yield context.callNative('animate', 'submit');
|
||||
args.animations();
|
||||
return takeLet(panel.getRootView())(root => {
|
||||
@ -4834,6 +4839,41 @@ function resourceLoader(context) {
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
function imageDecoder(context) {
|
||||
return {
|
||||
getImageInfo: (resource) => {
|
||||
return context.callNative('imageDecoder', 'getImageInfo', resource);
|
||||
},
|
||||
decodeToPixels: (resource) => __awaiter(this, void 0, void 0, function* () {
|
||||
return context.callNative('imageDecoder', 'decodeToPixels', resource);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
class Observable {
|
||||
constructor(provider, clz) {
|
||||
this.observers = new Set;
|
||||
@ -5072,7 +5112,12 @@ exports.AlphaAnimation = AlphaAnimation;
|
||||
exports.AndroidAssetsResource = AndroidAssetsResource;
|
||||
exports.AndroidResource = AndroidResource;
|
||||
exports.AnimationSet = AnimationSet;
|
||||
<<<<<<< HEAD
|
||||
exports.AssetsResource = AssetsResource;
|
||||
=======
|
||||
exports.ArrayBufferResource = ArrayBufferResource;
|
||||
exports.AssetResource = AssetResource;
|
||||
>>>>>>> f476a5b0... feat:android support ArrayBuffer Resource
|
||||
exports.BOTTOM = BOTTOM;
|
||||
exports.BackgroundColorAnimation = BackgroundColorAnimation;
|
||||
exports.Base64Resource = Base64Resource;
|
||||
@ -5151,6 +5196,7 @@ exports.gravity = gravity;
|
||||
exports.hlayout = hlayout;
|
||||
exports.iOSResource = iOSResource;
|
||||
exports.image = image;
|
||||
exports.imageDecoder = imageDecoder;
|
||||
exports.input = input;
|
||||
exports.internalScheme = internalScheme;
|
||||
exports.keyboard = keyboard;
|
||||
|
9
doric-web/dist/index.js.map
vendored
9
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user