Add resource system for doric,start with android

This commit is contained in:
pengfei.zhou 2021-10-20 18:57:17 +08:00 committed by osborn
parent 7637a820e5
commit 5501dd38d9
26 changed files with 880 additions and 23 deletions

View File

@ -41,6 +41,11 @@ import pub.doric.plugin.ShaderPlugin;
import pub.doric.plugin.StatusBarPlugin;
import pub.doric.plugin.StoragePlugin;
import pub.doric.refresh.RefreshableNode;
import pub.doric.resource.DoricAssetsLoader;
import pub.doric.resource.DoricAndroidLoader;
import pub.doric.resource.DoricLocalLoader;
import pub.doric.resource.DoricRemoteLoader;
import pub.doric.resource.DoricResourceManager;
import pub.doric.shader.DraggableNode;
import pub.doric.shader.GestureContainerNode;
import pub.doric.shader.HLayoutNode;
@ -77,6 +82,7 @@ public class DoricRegistry {
private Drawable defaultPlaceHolderDrawable = null;
private Drawable defaultErrorDrawable = null;
private final DoricResourceManager doricResourceManager = new DoricResourceManager();
private void initRegistry(DoricRegistry doricRegistry) {
@ -123,6 +129,11 @@ public class DoricRegistry {
this.registerViewNode(SwitchNode.class);
this.registerViewNode(FlexNode.class);
this.registerViewNode(GestureContainerNode.class);
this.getResourceManager().registerLoader(new DoricAndroidLoader("drawable"));
this.getResourceManager().registerLoader(new DoricAndroidLoader("raw"));
this.getResourceManager().registerLoader(new DoricAssetsLoader());
this.getResourceManager().registerLoader(new DoricLocalLoader());
this.getResourceManager().registerLoader(new DoricRemoteLoader());
initRegistry(this);
doricJSEngine.setEnvironmentValue(DoricSingleton.getInstance().envMap);
DoricSingleton.getInstance().registries.add(new WeakReference<>(this));
@ -218,4 +229,8 @@ public class DoricRegistry {
public static void register(DoricLibrary doricLibrary) {
DoricSingleton.getInstance().registerLibrary(doricLibrary);
}
public DoricResourceManager getResourceManager() {
return doricResourceManager;
}
}

View File

@ -0,0 +1,42 @@
/*
* 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;
/**
* @Description: This loads resource from android resource such as R.drawable,R.raw and so on
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricAndroidLoader implements DoricResourceLoader {
private final String defType;
public DoricAndroidLoader(String defType) {
this.defType = defType;
}
@Override
public String resourceType() {
return this.defType;
}
@Override
public DoricResource load(DoricContext doricContext, String identifier) {
return new DoricAndroidResource(this.defType, identifier, doricContext);
}
}

View File

@ -0,0 +1,52 @@
/*
* 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 java.io.InputStream;
import pub.doric.DoricContext;
import pub.doric.async.AsyncResult;
/**
* @Description: This represents an android resource like a drawable from R.drawable
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricAndroidResource extends DoricResource {
private final String defType;
private final String identifier;
public DoricAndroidResource(String defType, String identifier, DoricContext doricContext) {
super(doricContext);
this.defType = defType;
this.identifier = identifier;
}
@Override
public AsyncResult<InputStream> asInputStream() {
AsyncResult<InputStream> result = new AsyncResult<>();
int resId = doricContext.getContext().getResources().getIdentifier(
identifier,
defType,
doricContext.getContext().getPackageName());
if (resId > 0) {
result.setResult(doricContext.getContext().getResources().openRawResource(resId));
} else {
result.setError(new Throwable("Cannot find resource for :" + identifier + ",type = " + defType));
}
return result;
}
}

View File

@ -0,0 +1,35 @@
/*
* 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;
/**
* @Description: This loads resource from android's assets dir
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricAssetsLoader implements DoricResourceLoader {
@Override
public String resourceType() {
return "assets";
}
@Override
public DoricResource load(DoricContext doricContext, String identifier) {
return new DoricAssetsResource(identifier, doricContext);
}
}

View File

@ -0,0 +1,48 @@
/*
* 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 java.io.IOException;
import java.io.InputStream;
import pub.doric.DoricContext;
import pub.doric.async.AsyncResult;
/**
* @Description: This represents a resource from assets
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricAssetsResource extends DoricResource {
private final String path;
public DoricAssetsResource(String path, DoricContext doricContext) {
super(doricContext);
this.path = path;
}
@Override
public AsyncResult<InputStream> asInputStream() {
AsyncResult<InputStream> result = new AsyncResult<>();
try {
InputStream inputStream = doricContext.getContext().getAssets().open(path);
result.setResult(inputStream);
} catch (IOException e) {
result.setError(e);
}
return result;
}
}

View File

@ -0,0 +1,35 @@
/*
* 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;
/**
* @Description: This loads resource from file system
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricLocalLoader implements DoricResourceLoader {
@Override
public String resourceType() {
return "local";
}
@Override
public DoricResource load(DoricContext doricContext, String identifier) {
return new DoricLocalResource(doricContext, identifier);
}
}

View File

@ -0,0 +1,48 @@
/*
* 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 java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import pub.doric.DoricContext;
import pub.doric.async.AsyncResult;
/**
* @Description: This represents a local file
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricLocalResource extends DoricResource {
private final String filePath;
public DoricLocalResource(DoricContext doricContext, String identifier) {
super(doricContext);
this.filePath = identifier;
}
@Override
public AsyncResult<InputStream> asInputStream() {
AsyncResult<InputStream> result = new AsyncResult<>();
try {
result.setResult(new FileInputStream(filePath));
} catch (FileNotFoundException e) {
result.setError(e);
}
return result;
}
}

View File

@ -0,0 +1,37 @@
/*
* 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;
/**
* @Description: This loads resource from network
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricRemoteLoader implements DoricResourceLoader {
@Override
public String resourceType() {
return "remote";
}
@Override
public DoricResource load(DoricContext doricContext, String identifier) {
return new DoricRemoteResource(doricContext, identifier);
}
}

View File

@ -0,0 +1,71 @@
/*
* 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 com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import androidx.annotation.Nullable;
import pub.doric.DoricContext;
import pub.doric.async.AsyncResult;
/**
* @Description: This represents a resource from network
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricRemoteResource extends DoricResource {
private final String url;
public DoricRemoteResource(DoricContext doricContext, String identifier) {
super(doricContext);
this.url = identifier;
}
@Override
public AsyncResult<InputStream> asInputStream() {
final AsyncResult<InputStream> result = new AsyncResult<>();
Glide.with(doricContext.getContext()).download(url)
.listener(new RequestListener<File>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<File> target, boolean isFirstResource) {
result.setError(e);
return false;
}
@Override
public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
try {
result.setResult(new FileInputStream(resource));
} catch (FileNotFoundException e) {
result.setError(e);
}
return false;
}
})
.submit();
return result;
}
}

View File

@ -0,0 +1,37 @@
/*
* 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 java.io.InputStream;
import pub.doric.DoricContext;
import pub.doric.async.AsyncResult;
/**
* @Description: This represents a resource entity
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public abstract class DoricResource {
protected final DoricContext doricContext;
public DoricResource(DoricContext doricContext) {
this.doricContext = doricContext;
}
public abstract AsyncResult<InputStream> asInputStream();
}

View File

@ -0,0 +1,41 @@
/*
* 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;
/**
* @Description: For loading resources
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public interface DoricResourceLoader {
/**
* Determines which type's resource this loader could load
*
* @return type's name of this resource loader
*/
String resourceType();
/**
* Load resource by identifier in your way
*
* @param doricContext which context current running
* @param identifier Identifies the resource
* @return Resource's inputStream
*/
DoricResource load(DoricContext doricContext, String identifier);
}

View File

@ -0,0 +1,49 @@
/*
* 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 java.util.HashMap;
import java.util.Map;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import pub.doric.DoricContext;
/**
* @Description: This manages all resource loaders
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricResourceManager {
private final Map<String, DoricResourceLoader> mResourceLoaders = new HashMap<>();
public void registerLoader(DoricResourceLoader loader) {
mResourceLoaders.put(loader.resourceType(), loader);
}
public void unRegisterLoader(DoricResourceLoader loader) {
mResourceLoaders.remove(loader.resourceType());
}
@Nullable
public DoricResource load(@NonNull DoricContext doricContext, @NonNull String type, @NonNull String identifier) {
DoricResourceLoader loader = mResourceLoaders.get(type);
if (loader != null) {
return loader.load(doricContext, identifier);
}
return null;
}
}

View File

@ -53,11 +53,15 @@ import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue;
import java.io.File;
import java.io.InputStream;
import jp.wasabeef.glide.transformations.BlurTransformation;
import pub.doric.DoricContext;
import pub.doric.DoricSingleton;
import pub.doric.async.AsyncResult;
import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.resource.DoricResource;
import pub.doric.shader.flex.FlexNode;
import pub.doric.utils.DoricLog;
import pub.doric.utils.DoricUtils;
@ -358,6 +362,36 @@ public class ImageNode extends ViewNode<ImageView> {
@Override
protected void blend(ImageView view, String name, JSValue prop) {
switch (name) {
case "image":
if (!prop.isObject()) {
return;
}
JSObject resource = prop.asObject();
final String type = resource.getProperty("type").asString().value();
final String identifier = resource.getProperty("identifier").asString().value();
DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager().load(getDoricContext(), type, identifier);
if (doricResource != null) {
doricResource.asInputStream().setCallback(new AsyncResult.Callback<InputStream>() {
@Override
public void onResult(InputStream result) {
loadIntoTarget(Glide.with(getContext()).load(result));
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
DoricLog.e("Cannot load resource type = %s, identifier = %s, %s", type, identifier, t.getLocalizedMessage());
}
@Override
public void onFinish() {
}
});
} else {
DoricLog.e("Cannot find loader for resource type = %s, identifier = %s", type, identifier);
}
break;
case "imageUrl":
if (!prop.isString()) {
return;

View File

@ -76,7 +76,9 @@ class ListVM extends ViewModel<ListModel, ListVH> {
heightSpec: LayoutSpec.JUST,
},
height: 50,
onClick: () => { modal(context).alert(data.text) }
onClick: function () {
(this as Text).height += 10
}
})
]), {
layoutConfig: {

View File

@ -139,7 +139,7 @@ function logw() {
nativeLog('w', out);
}
var __extends$h = (undefined && undefined.__extends) || (function () {
var __extends$i = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@ -571,7 +571,7 @@ var View = /** @class */ (function () {
return View;
}());
var Superview = /** @class */ (function (_super) {
__extends$h(Superview, _super);
__extends$i(Superview, _super);
function Superview() {
return _super !== null && _super.apply(this, arguments) || this;
}
@ -687,7 +687,7 @@ var Superview = /** @class */ (function (_super) {
return Superview;
}(View));
var Group = /** @class */ (function (_super) {
__extends$h(Group, _super);
__extends$i(Group, _super);
function Group() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.children = [];
@ -905,7 +905,7 @@ function layoutConfig() {
return new LayoutConfigImpl;
}
var __extends$g = (undefined && undefined.__extends) || (function () {
var __extends$h = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@ -941,21 +941,21 @@ var __values$4 = (undefined && undefined.__values) || function(o) {
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var Stack = /** @class */ (function (_super) {
__extends$g(Stack, _super);
__extends$h(Stack, _super);
function Stack() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Stack;
}(Group));
var Root = /** @class */ (function (_super) {
__extends$g(Root, _super);
__extends$h(Root, _super);
function Root() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Root;
}(Stack));
var LinearLayout = /** @class */ (function (_super) {
__extends$g(LinearLayout, _super);
__extends$h(LinearLayout, _super);
function LinearLayout() {
return _super !== null && _super.apply(this, arguments) || this;
}
@ -970,14 +970,14 @@ var LinearLayout = /** @class */ (function (_super) {
return LinearLayout;
}(Group));
var VLayout = /** @class */ (function (_super) {
__extends$g(VLayout, _super);
__extends$h(VLayout, _super);
function VLayout() {
return _super !== null && _super.apply(this, arguments) || this;
}
return VLayout;
}(LinearLayout));
var HLayout = /** @class */ (function (_super) {
__extends$g(HLayout, _super);
__extends$h(HLayout, _super);
function HLayout() {
return _super !== null && _super.apply(this, arguments) || this;
}
@ -1050,7 +1050,7 @@ function vlayout(views, config) {
return ret;
}
var FlexLayout = /** @class */ (function (_super) {
__extends$g(FlexLayout, _super);
__extends$h(FlexLayout, _super);
function FlexLayout() {
return _super !== null && _super.apply(this, arguments) || this;
}
@ -1499,7 +1499,7 @@ exports.GradientOrientation = void 0;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends$f = (undefined && undefined.__extends) || (function () {
var __extends$g = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@ -1615,7 +1615,7 @@ var Animation = /** @class */ (function () {
return Animation;
}());
var ScaleAnimation = /** @class */ (function (_super) {
__extends$f(ScaleAnimation, _super);
__extends$g(ScaleAnimation, _super);
function ScaleAnimation() {
var _this = _super.call(this) || this;
_this.scaleXChangeable = {
@ -1689,7 +1689,7 @@ var ScaleAnimation = /** @class */ (function (_super) {
return ScaleAnimation;
}(Animation));
var TranslationAnimation = /** @class */ (function (_super) {
__extends$f(TranslationAnimation, _super);
__extends$g(TranslationAnimation, _super);
function TranslationAnimation() {
var _this = _super.call(this) || this;
_this.translationXChangeable = {
@ -1766,7 +1766,7 @@ var TranslationAnimation = /** @class */ (function (_super) {
* Rotation range is [0..2]
*/
var RotationAnimation = /** @class */ (function (_super) {
__extends$f(RotationAnimation, _super);
__extends$g(RotationAnimation, _super);
function RotationAnimation() {
var _this = _super.call(this) || this;
_this.rotationChaneable = {
@ -1810,7 +1810,7 @@ var RotationAnimation = /** @class */ (function (_super) {
* Rotation range is [0..2]
*/
var RotationXAnimation = /** @class */ (function (_super) {
__extends$f(RotationXAnimation, _super);
__extends$g(RotationXAnimation, _super);
function RotationXAnimation() {
var _this = _super.call(this) || this;
_this.rotationChaneable = {
@ -1854,7 +1854,7 @@ var RotationXAnimation = /** @class */ (function (_super) {
* Rotation range is [0..2]
*/
var RotationYAnimation = /** @class */ (function (_super) {
__extends$f(RotationYAnimation, _super);
__extends$g(RotationYAnimation, _super);
function RotationYAnimation() {
var _this = _super.call(this) || this;
_this.rotationChaneable = {
@ -1895,7 +1895,7 @@ var RotationYAnimation = /** @class */ (function (_super) {
return RotationYAnimation;
}(Animation));
var BackgroundColorAnimation = /** @class */ (function (_super) {
__extends$f(BackgroundColorAnimation, _super);
__extends$g(BackgroundColorAnimation, _super);
function BackgroundColorAnimation() {
var _this = _super.call(this) || this;
_this.backgroundColorChangeable = {
@ -1939,7 +1939,7 @@ var BackgroundColorAnimation = /** @class */ (function (_super) {
* Alpha range is [0..1]
*/
var AlphaAnimation = /** @class */ (function (_super) {
__extends$f(AlphaAnimation, _super);
__extends$g(AlphaAnimation, _super);
function AlphaAnimation() {
var _this = _super.call(this) || this;
_this.opacityChangeable = {
@ -2011,7 +2011,7 @@ var AnimationSet = /** @class */ (function () {
return AnimationSet;
}());
var __extends$e = (undefined && undefined.__extends) || (function () {
var __extends$f = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@ -2043,7 +2043,7 @@ exports.TruncateAt = void 0;
TruncateAt[TruncateAt["Clip"] = 3] = "Clip";
})(exports.TruncateAt || (exports.TruncateAt = {}));
var Text = /** @class */ (function (_super) {
__extends$e(Text, _super);
__extends$f(Text, _super);
function Text() {
return _super !== null && _super.apply(this, arguments) || this;
}
@ -2119,6 +2119,76 @@ function text(config) {
return ret;
}
var __extends$e = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) { if (Object.prototype.hasOwnProperty.call(b, p)) { d[p] = b[p]; } } };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
{ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); }
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Resource = /** @class */ (function () {
function Resource(type, identifier) {
this.type = type;
this.identifier = identifier;
}
Resource.prototype.toModel = function () {
return {
type: this.type,
identifier: this.identifier,
};
};
return Resource;
}());
/** @class */ ((function (_super) {
__extends$e(FileResource, _super);
function FileResource(path) {
return _super.call(this, "file", path) || this;
}
return FileResource;
})(Resource));
/** @class */ ((function (_super) {
__extends$e(RemoteResource, _super);
function RemoteResource(url) {
return _super.call(this, "remote", url) || this;
}
return RemoteResource;
})(Resource));
/**
* This is for android platform
*/
/** @class */ ((function (_super) {
__extends$e(DrawableResource, _super);
function DrawableResource(url) {
return _super.call(this, "drawable", url) || this;
}
return DrawableResource;
})(Resource));
/** @class */ ((function (_super) {
__extends$e(AssetResource, _super);
function AssetResource(path) {
return _super.call(this, "assets", path) || this;
}
return AssetResource;
})(Resource));
/**
* This is for iOS platform
*/
/** @class */ ((function (_super) {
__extends$e(MainBundleResource, _super);
function MainBundleResource(path) {
return _super.call(this, "mainBundle", path) || this;
}
return MainBundleResource;
})(Resource));
var __extends$d = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
@ -2163,6 +2233,10 @@ var Image = /** @class */ (function (_super) {
Image.prototype.stopAnimating = function (context) {
return this.nativeChannel(context, "stopAnimating")();
};
__decorate$a([
Property,
__metadata$a("design:type", Resource)
], Image.prototype, "image", void 0);
__decorate$a([
Property,
__metadata$a("design:type", String)

View File

@ -1603,6 +1603,19 @@ function text(config) {
return ret;
}
class Resource {
constructor(type, identifier) {
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
type: this.type,
identifier: this.identifier,
};
}
}
var __decorate$a = (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;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@ -1629,6 +1642,10 @@ class Image extends View {
return this.nativeChannel(context, "stopAnimating")();
}
}
__decorate$a([
Property,
__metadata$a("design:type", Resource)
], Image.prototype, "image", void 0);
__decorate$a([
Property,
__metadata$a("design:type", String)

View File

@ -3124,6 +3124,19 @@ function text(config) {
return ret;
}
class Resource {
constructor(type, identifier) {
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
type: this.type,
identifier: this.identifier,
};
}
}
var __decorate$a = (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;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@ -3150,6 +3163,10 @@ class Image extends View {
return this.nativeChannel(context, "stopAnimating")();
}
}
__decorate$a([
Property,
__metadata$a("design:type", Resource)
], Image.prototype, "image", void 0);
__decorate$a([
Property,
__metadata$a("design:type", String)

39
doric-js/index.d.ts vendored
View File

@ -612,12 +612,17 @@ declare module 'doric/lib/src/widget/image' {
import { View } from "doric/lib/src/ui/view";
import { Color } from "doric/lib/src/util/color";
import { BridgeContext } from "doric/lib/src/runtime/global";
import { Resource } from "doric/lib/src/util/resource";
export enum ScaleType {
ScaleToFill = 0,
ScaleAspectFit = 1,
ScaleAspectFill = 2
}
export class Image extends View {
/**
* This could be loaded by customized resource loader
*/
image?: Resource;
imageUrl?: string;
/**
* Read image from local file system.
@ -1761,6 +1766,40 @@ declare module 'doric/lib/src/pattern/modular' {
}
}
declare module 'doric/lib/src/util/resource' {
import { Modeling } from "doric/lib/src/util/types";
export abstract class Resource implements Modeling {
type: string;
identifier: string;
constructor(type: string, identifier: string);
toModel(): {
type: string;
identifier: string;
};
}
export class FileResource extends Resource {
constructor(path: string);
}
export class RemoteResource extends Resource {
constructor(url: string);
}
/**
* This is for android platform
*/
export class DrawableResource extends Resource {
constructor(url: string);
}
export class AssetResource extends Resource {
constructor(path: string);
}
/**
* This is for iOS platform
*/
export class MainBundleResource extends Resource {
constructor(path: string);
}
}
declare module '*.png' {
const value: any;
export default value;

31
doric-js/lib/src/util/resource.d.ts vendored Normal file
View File

@ -0,0 +1,31 @@
import { Modeling } from "./types";
export declare abstract class Resource implements Modeling {
type: string;
identifier: string;
constructor(type: string, identifier: string);
toModel(): {
type: string;
identifier: string;
};
}
export declare class FileResource extends Resource {
constructor(path: string);
}
export declare class RemoteResource extends Resource {
constructor(url: string);
}
/**
* This is for android platform
*/
export declare class DrawableResource extends Resource {
constructor(url: string);
}
export declare class AssetResource extends Resource {
constructor(path: string);
}
/**
* This is for iOS platform
*/
export declare class MainBundleResource extends Resource {
constructor(path: string);
}

View File

@ -0,0 +1,43 @@
export class Resource {
constructor(type, identifier) {
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
type: this.type,
identifier: this.identifier,
};
}
}
export class FileResource extends Resource {
constructor(path) {
super("file", path);
}
}
export class RemoteResource extends Resource {
constructor(url) {
super("remote", url);
}
}
/**
* This is for android platform
*/
export class DrawableResource extends Resource {
constructor(url) {
super("drawable", url);
}
}
export class AssetResource extends Resource {
constructor(path) {
super("assets", path);
}
}
/**
* This is for iOS platform
*/
export class MainBundleResource extends Resource {
constructor(path) {
super("mainBundle", path);
}
}

View File

@ -1,12 +1,17 @@
import { View } from "../ui/view";
import { Color } from "../util/color";
import { BridgeContext } from "../runtime/global";
import { Resource } from "../util/resource";
export declare enum ScaleType {
ScaleToFill = 0,
ScaleAspectFit = 1,
ScaleAspectFill = 2
}
export declare class Image extends View {
/**
* This could be loaded by customized resource loader
*/
image?: Resource;
imageUrl?: string;
/**
* Read image from local file system.

View File

@ -25,6 +25,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
import { View, Property } from "../ui/view";
import { layoutConfig } from "../util/layoutconfig";
import { Color } from "../util/color";
import { Resource } from "../util/resource";
export var ScaleType;
(function (ScaleType) {
ScaleType[ScaleType["ScaleToFill"] = 0] = "ScaleToFill";
@ -42,6 +43,10 @@ export class Image extends View {
return this.nativeChannel(context, "stopAnimating")();
}
}
__decorate([
Property,
__metadata("design:type", Resource)
], Image.prototype, "image", void 0);
__decorate([
Property,
__metadata("design:type", String)

View File

@ -0,0 +1,57 @@
import { Modeling } from "./types";
export abstract class Resource implements Modeling {
type: string;
identifier: string;
constructor(type: string, identifier: string) {
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
type: this.type,
identifier: this.identifier,
}
}
}
export class FileResource extends Resource {
constructor(path: string) {
super("file", path);
}
}
export class RemoteResource extends Resource {
constructor(url: string) {
super("remote", url)
}
}
/**
* This is for android platform
*/
export class DrawableResource extends Resource {
constructor(url: string) {
super("drawable", url)
}
}
export class RawResource extends Resource {
constructor(url: string) {
super("raw", url)
}
}
export class AssetResource extends Resource {
constructor(path: string) {
super("assets", path)
}
}
/**
* This is for iOS platform
*/
export class MainBundleResource extends Resource {
constructor(path: string) {
super("mainBundle", path)
}
}

View File

@ -17,6 +17,7 @@ import { View, Property } from "../ui/view"
import { layoutConfig } from "../util/layoutconfig"
import { Color } from "../util/color"
import { BridgeContext } from "../runtime/global"
import { Resource } from "../util/resource"
export enum ScaleType {
ScaleToFill = 0,
@ -25,9 +26,14 @@ export enum ScaleType {
}
export class Image extends View {
/**
* This could be loaded by customized resource loader
*/
@Property
image?: Resource
@Property
imageUrl?: string
/**
* Read image from local file system.
*/

View File

@ -3178,6 +3178,19 @@ function text(config) {
return ret;
}
class Resource {
constructor(type, identifier) {
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
type: this.type,
identifier: this.identifier,
};
}
}
var __decorate$a = (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;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@ -3204,6 +3217,10 @@ class Image extends View {
return this.nativeChannel(context, "stopAnimating")();
}
}
__decorate$a([
Property,
__metadata$a("design:type", Resource)
], Image.prototype, "image", void 0);
__decorate$a([
Property,
__metadata$a("design:type", String)

File diff suppressed because one or more lines are too long