feat: add DoricAssets resource

This commit is contained in:
pengfei.zhou 2021-12-07 18:38:05 +08:00 committed by osborn
parent 233f31b90b
commit 1ba4336857
17 changed files with 279 additions and 62 deletions

View File

@ -41,8 +41,9 @@ 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.DoricAndroidAssetsLoader;
import pub.doric.resource.DoricAndroidLoader;
import pub.doric.resource.DoricAssetsLoader;
import pub.doric.resource.DoricBase64Loader;
import pub.doric.resource.DoricLocalLoader;
import pub.doric.resource.DoricRemoteLoader;
@ -136,6 +137,7 @@ public class DoricRegistry {
this.registerViewNode(AeroEffectViewNode.class);
this.getResourceManager().registerLoader(new DoricAndroidLoader("drawable"));
this.getResourceManager().registerLoader(new DoricAndroidLoader("raw"));
this.getResourceManager().registerLoader(new DoricAndroidAssetsLoader());
this.getResourceManager().registerLoader(new DoricAssetsLoader());
this.getResourceManager().registerLoader(new DoricLocalLoader());
this.getResourceManager().registerLoader(new DoricRemoteLoader());

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 DoricAndroidAssetsLoader implements DoricResourceLoader {
@Override
public String resourceType() {
return "android_assets";
}
@Override
public DoricResource load(DoricContext doricContext, String identifier) {
return new DoricAssetsResource(doricContext, identifier);
}
}

View File

@ -18,18 +18,18 @@ package pub.doric.resource;
import pub.doric.DoricContext;
/**
* @Description: This loads resource from android's assets dir
* @Description: This loads resource from doric project's assets/ file
* @Author: pengfei.zhou
* @CreateDate: 2021/10/20
*/
public class DoricAssetsLoader implements DoricResourceLoader {
@Override
public String resourceType() {
return "assets";
return "doric_assets";
}
@Override
public DoricResource load(DoricContext doricContext, String identifier) {
return new DoricAssetsResource(doricContext, identifier);
return new DoricAssetsResource(doricContext, "assets/" + identifier);
}
}

View File

@ -1,4 +1,4 @@
import { Base64Resource, Group, Panel, coordinator, text, gravity, Color, LayoutSpec, log, vlayout, scroller, layoutConfig, image, ScaleType, Image, modal, RemoteResource, MainBundleResource, AssetResource } from "doric";
import { Base64Resource, Group, Panel, coordinator, text, gravity, Color, LayoutSpec, log, vlayout, scroller, layoutConfig, image, ScaleType, Image, modal, RemoteResource, MainBundleResource, AndroidAssetsResource, DoricAssetsResource } from "doric";
import { colors, label } from "./utils";
import { img_base64 } from "./image_base64";
@ -28,9 +28,12 @@ class ImageDemo extends Panel {
label('Button'),
image({
image: Environment.platform === 'Android'
? new AssetResource("assets/The_Parthenon_in_Athens.jpeg")
? new AndroidAssetsResource("assets/The_Parthenon_in_Athens.jpeg")
: new MainBundleResource("assets/The_Parthenon_in_Athens.jpeg"),
}),
image({
image: new DoricAssetsResource("The_Parthenon_in_Athens.jpeg"),
}),
image({
image: new RemoteResource("https://p.upyun.com/demo/webp/webp/jpg-0.webp"),
}),

View File

@ -63,6 +63,7 @@
#import "DoricCommonBundleResourceLoader.h"
#import "DoricBlurEffectViewNode.h"
#import "DoricAeroEffectViewNode.h"
#import "DoricAssetsResourceLoader.h"
@interface DoricRegistry ()
@ -145,6 +146,7 @@ - (void)innerRegister {
[self.loaderManager registerLoader:[DoricRemoteResourceLoader new]];
[self.loaderManager registerLoader:[DoricBase64ResourceLoader new]];
[self.loaderManager registerLoader:[DoricCommonBundleResourceLoader new]];
[self.loaderManager registerLoader:[DoricAssetsResourceLoader new]];
}
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {

View File

@ -0,0 +1,24 @@
/*
* 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.
*/
//
// Created by pengfei.zhou on 2021/12/7.
//
#import <Foundation/Foundation.h>
#import "DoricResourceLoader.h"
@interface DoricAssetsResourceLoader : NSObject<DoricResourceLoader>
@end

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.
*/
//
// Created by pengfei.zhou on 2021/12/7.
//
#import "DoricAssetsResourceLoader.h"
#import "DoricBundleResource.h"
@implementation DoricAssetsResourceLoader
- (NSString *)resourceType {
return @"doric_assets";
}
- (__kindof DoricResource *)load:(NSString *)identifier withContext:(DoricContext *)context {
DoricBundleResource *resource = [[DoricBundleResource alloc] initWithContext:context
identifier:[NSString stringWithFormat:@"assets/%@", identifier]];
resource.bundle = NSBundle.mainBundle;
return resource;
}
@end

View File

@ -17,7 +17,7 @@
// Created by pengfei.zhou on 2021/10/25.
//
#import <DoricExtensions.h>
#import "DoricExtensions.h"
#import "DoricBundleResourceLoader.h"
#import "DoricBundleResource.h"

View File

@ -2177,6 +2177,30 @@ var Base64Resource = /** @class */ (function (_super) {
}
return Base64Resource;
}(Resource));
/**
* Resources belong to assets dir.
*/
var DoricAssetsResource = /** @class */ (function (_super) {
__extends$f(DoricAssetsResource, _super);
function DoricAssetsResource(content) {
return _super.call(this, "doric_assets", content) || this;
}
return DoricAssetsResource;
}(Resource));
var AndroidResource = /** @class */ (function (_super) {
__extends$f(AndroidResource, _super);
function AndroidResource() {
return _super !== null && _super.apply(this, arguments) || this;
}
return AndroidResource;
}(Resource));
var iOSResource = /** @class */ (function (_super) {
__extends$f(iOSResource, _super);
function iOSResource() {
return _super !== null && _super.apply(this, arguments) || this;
}
return iOSResource;
}(Resource));
/**
* This is for android platform
*/
@ -2186,21 +2210,21 @@ var DrawableResource = /** @class */ (function (_super) {
return _super.call(this, "drawable", name) || this;
}
return DrawableResource;
}(Resource));
}(AndroidResource));
var RawResource = /** @class */ (function (_super) {
__extends$f(RawResource, _super);
function RawResource(name) {
return _super.call(this, "raw", name) || this;
}
return RawResource;
}(Resource));
var AssetResource = /** @class */ (function (_super) {
__extends$f(AssetResource, _super);
function AssetResource(path) {
return _super.call(this, "assets", path) || this;
}(AndroidResource));
var AndroidAssetsResource = /** @class */ (function (_super) {
__extends$f(AndroidAssetsResource, _super);
function AndroidAssetsResource(path) {
return _super.call(this, "android_assets", path) || this;
}
return AssetResource;
}(Resource));
return AndroidAssetsResource;
}(AndroidResource));
/**
* This is for iOS platform
*/
@ -2210,14 +2234,14 @@ var MainBundleResource = /** @class */ (function (_super) {
return _super.call(this, "mainBundle", fileName) || this;
}
return MainBundleResource;
}(Resource));
}(iOSResource));
var BundleResource = /** @class */ (function (_super) {
__extends$f(BundleResource, _super);
function BundleResource(bundleName, fileName) {
return _super.call(this, "bundle", bundleName + "://" + fileName) || this;
}
return BundleResource;
}(Resource));
}(iOSResource));
var __extends$e = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
@ -4498,8 +4522,9 @@ var ModularPanel = /** @class */ (function (_super) {
exports.AeroEffect = AeroEffect;
exports.AlphaAnimation = AlphaAnimation;
exports.AndroidAssetsResource = AndroidAssetsResource;
exports.AndroidResource = AndroidResource;
exports.AnimationSet = AnimationSet;
exports.AssetResource = AssetResource;
exports.BOTTOM = BOTTOM;
exports.BackgroundColorAnimation = BackgroundColorAnimation;
exports.Base64Resource = Base64Resource;
@ -4509,6 +4534,7 @@ exports.CENTER = CENTER;
exports.CENTER_X = CENTER_X;
exports.CENTER_Y = CENTER_Y;
exports.Color = Color;
exports.DoricAssetsResource = DoricAssetsResource;
exports.Draggable = Draggable;
exports.DrawableResource = DrawableResource;
exports.FlexLayout = FlexLayout;
@ -4576,6 +4602,7 @@ exports.flowlayout = flowlayout;
exports.gestureContainer = gestureContainer;
exports.gravity = gravity;
exports.hlayout = hlayout;
exports.iOSResource = iOSResource;
exports.image = image;
exports.input = input;
exports.internalScheme = internalScheme;

View File

@ -1635,33 +1635,45 @@ class Base64Resource extends Resource {
super("base64", content);
}
}
/**
* Resources belong to assets dir.
*/
class DoricAssetsResource extends Resource {
constructor(content) {
super("doric_assets", content);
}
}
class AndroidResource extends Resource {
}
class iOSResource extends Resource {
}
/**
* This is for android platform
*/
class DrawableResource extends Resource {
class DrawableResource extends AndroidResource {
constructor(name) {
super("drawable", name);
}
}
class RawResource extends Resource {
class RawResource extends AndroidResource {
constructor(name) {
super("raw", name);
}
}
class AssetResource extends Resource {
class AndroidAssetsResource extends AndroidResource {
constructor(path) {
super("assets", path);
super("android_assets", path);
}
}
/**
* This is for iOS platform
*/
class MainBundleResource extends Resource {
class MainBundleResource extends iOSResource {
constructor(fileName) {
super("mainBundle", fileName);
}
}
class BundleResource extends Resource {
class BundleResource extends iOSResource {
constructor(bundleName, fileName) {
super("bundle", `${bundleName}://${fileName}`);
}
@ -3441,8 +3453,9 @@ class ModularPanel extends Module {
exports.AeroEffect = AeroEffect;
exports.AlphaAnimation = AlphaAnimation;
exports.AndroidAssetsResource = AndroidAssetsResource;
exports.AndroidResource = AndroidResource;
exports.AnimationSet = AnimationSet;
exports.AssetResource = AssetResource;
exports.BOTTOM = BOTTOM;
exports.BackgroundColorAnimation = BackgroundColorAnimation;
exports.Base64Resource = Base64Resource;
@ -3452,6 +3465,7 @@ exports.CENTER = CENTER;
exports.CENTER_X = CENTER_X;
exports.CENTER_Y = CENTER_Y;
exports.Color = Color;
exports.DoricAssetsResource = DoricAssetsResource;
exports.Draggable = Draggable;
exports.DrawableResource = DrawableResource;
exports.FlexLayout = FlexLayout;
@ -3519,6 +3533,7 @@ exports.flowlayout = flowlayout;
exports.gestureContainer = gestureContainer;
exports.gravity = gravity;
exports.hlayout = hlayout;
exports.iOSResource = iOSResource;
exports.image = image;
exports.input = input;
exports.internalScheme = internalScheme;

View File

@ -3163,33 +3163,45 @@ class Base64Resource extends Resource {
super("base64", content);
}
}
/**
* Resources belong to assets dir.
*/
class DoricAssetsResource extends Resource {
constructor(content) {
super("doric_assets", content);
}
}
class AndroidResource extends Resource {
}
class iOSResource extends Resource {
}
/**
* This is for android platform
*/
class DrawableResource extends Resource {
class DrawableResource extends AndroidResource {
constructor(name) {
super("drawable", name);
}
}
class RawResource extends Resource {
class RawResource extends AndroidResource {
constructor(name) {
super("raw", name);
}
}
class AssetResource extends Resource {
class AndroidAssetsResource extends AndroidResource {
constructor(path) {
super("assets", path);
super("android_assets", path);
}
}
/**
* This is for iOS platform
*/
class MainBundleResource extends Resource {
class MainBundleResource extends iOSResource {
constructor(fileName) {
super("mainBundle", fileName);
}
}
class BundleResource extends Resource {
class BundleResource extends iOSResource {
constructor(bundleName, fileName) {
super("bundle", `${bundleName}://${fileName}`);
}
@ -5210,8 +5222,9 @@ global$1.nativeEmpty = () => {
exports.AeroEffect = AeroEffect;
exports.AlphaAnimation = AlphaAnimation;
exports.AndroidAssetsResource = AndroidAssetsResource;
exports.AndroidResource = AndroidResource;
exports.AnimationSet = AnimationSet;
exports.AssetResource = AssetResource;
exports.BOTTOM = BOTTOM;
exports.BackgroundColorAnimation = BackgroundColorAnimation;
exports.Base64Resource = Base64Resource;
@ -5221,6 +5234,7 @@ exports.CENTER = CENTER;
exports.CENTER_X = CENTER_X;
exports.CENTER_Y = CENTER_Y;
exports.Color = Color;
exports.DoricAssetsResource = DoricAssetsResource;
exports.Draggable = Draggable;
exports.DrawableResource = DrawableResource;
exports.FlexLayout = FlexLayout;
@ -5288,6 +5302,7 @@ exports.flowlayout = flowlayout;
exports.gestureContainer = gestureContainer;
exports.gravity = gravity;
exports.hlayout = hlayout;
exports.iOSResource = iOSResource;
exports.image = image;
exports.input = input;
exports.internalScheme = internalScheme;

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

@ -1690,25 +1690,35 @@ declare module 'doric/lib/src/util/resource' {
export class Base64Resource extends Resource {
constructor(content: string);
}
/**
* Resources belong to assets dir.
*/
export class DoricAssetsResource extends Resource {
constructor(content: string);
}
export class AndroidResource extends Resource {
}
export class iOSResource extends Resource {
}
/**
* This is for android platform
*/
export class DrawableResource extends Resource {
export class DrawableResource extends AndroidResource {
constructor(name: string);
}
export class RawResource extends Resource {
export class RawResource extends AndroidResource {
constructor(name: string);
}
export class AssetResource extends Resource {
export class AndroidAssetsResource extends AndroidResource {
constructor(path: string);
}
/**
* This is for iOS platform
*/
export class MainBundleResource extends Resource {
export class MainBundleResource extends iOSResource {
constructor(fileName: string);
}
export class BundleResource extends Resource {
export class BundleResource extends iOSResource {
constructor(bundleName: string, fileName: string);
}
}

View File

@ -17,24 +17,34 @@ export declare class RemoteResource extends Resource {
export declare class Base64Resource extends Resource {
constructor(content: string);
}
/**
* Resources belong to assets dir.
*/
export declare class DoricAssetsResource extends Resource {
constructor(content: string);
}
export declare class AndroidResource extends Resource {
}
export declare class iOSResource extends Resource {
}
/**
* This is for android platform
*/
export declare class DrawableResource extends Resource {
export declare class DrawableResource extends AndroidResource {
constructor(name: string);
}
export declare class RawResource extends Resource {
export declare class RawResource extends AndroidResource {
constructor(name: string);
}
export declare class AssetResource extends Resource {
export declare class AndroidAssetsResource extends AndroidResource {
constructor(path: string);
}
/**
* This is for iOS platform
*/
export declare class MainBundleResource extends Resource {
export declare class MainBundleResource extends iOSResource {
constructor(fileName: string);
}
export declare class BundleResource extends Resource {
export declare class BundleResource extends iOSResource {
constructor(bundleName: string, fileName: string);
}

View File

@ -25,33 +25,45 @@ export class Base64Resource extends Resource {
super("base64", content);
}
}
/**
* Resources belong to assets dir.
*/
export class DoricAssetsResource extends Resource {
constructor(content) {
super("doric_assets", content);
}
}
export class AndroidResource extends Resource {
}
export class iOSResource extends Resource {
}
/**
* This is for android platform
*/
export class DrawableResource extends Resource {
export class DrawableResource extends AndroidResource {
constructor(name) {
super("drawable", name);
}
}
export class RawResource extends Resource {
export class RawResource extends AndroidResource {
constructor(name) {
super("raw", name);
}
}
export class AssetResource extends Resource {
export class AndroidAssetsResource extends AndroidResource {
constructor(path) {
super("assets", path);
super("android_assets", path);
}
}
/**
* This is for iOS platform
*/
export class MainBundleResource extends Resource {
export class MainBundleResource extends iOSResource {
constructor(fileName) {
super("mainBundle", fileName);
}
}
export class BundleResource extends Resource {
export class BundleResource extends iOSResource {
constructor(bundleName, fileName) {
super("bundle", `${bundleName}://${fileName}`);
}

View File

@ -32,38 +32,50 @@ export class Base64Resource extends Resource {
super("base64", content)
}
}
/**
* Resources belong to assets dir.
*/
export class DoricAssetsResource extends Resource {
constructor(content: string) {
super("doric_assets", content)
}
}
export class AndroidResource extends Resource {
}
export class iOSResource extends Resource {
}
/**
* This is for android platform
*/
export class DrawableResource extends Resource {
export class DrawableResource extends AndroidResource {
constructor(name: string) {
super("drawable", name)
}
}
export class RawResource extends Resource {
export class RawResource extends AndroidResource {
constructor(name: string) {
super("raw", name)
}
}
export class AssetResource extends Resource {
export class AndroidAssetsResource extends AndroidResource {
constructor(path: string) {
super("assets", path)
super("android_assets", path)
}
}
/**
* This is for iOS platform
*/
export class MainBundleResource extends Resource {
export class MainBundleResource extends iOSResource {
constructor(fileName: string) {
super("mainBundle", fileName)
}
}
export class BundleResource extends Resource {
export class BundleResource extends iOSResource {
constructor(bundleName: string, fileName: string) {
super("bundle", `${bundleName}://${fileName}`)
}

View File

@ -3237,33 +3237,45 @@ class Base64Resource extends Resource {
super("base64", content);
}
}
/**
* Resources belong to assets dir.
*/
class DoricAssetsResource extends Resource {
constructor(content) {
super("doric_assets", content);
}
}
class AndroidResource extends Resource {
}
class iOSResource extends Resource {
}
/**
* This is for android platform
*/
class DrawableResource extends Resource {
class DrawableResource extends AndroidResource {
constructor(name) {
super("drawable", name);
}
}
class RawResource extends Resource {
class RawResource extends AndroidResource {
constructor(name) {
super("raw", name);
}
}
class AssetResource extends Resource {
class AndroidAssetsResource extends AndroidResource {
constructor(path) {
super("assets", path);
super("android_assets", path);
}
}
/**
* This is for iOS platform
*/
class MainBundleResource extends Resource {
class MainBundleResource extends iOSResource {
constructor(fileName) {
super("mainBundle", fileName);
}
}
class BundleResource extends Resource {
class BundleResource extends iOSResource {
constructor(bundleName, fileName) {
super("bundle", `${bundleName}://${fileName}`);
}
@ -5043,8 +5055,9 @@ class ModularPanel extends Module {
exports.AeroEffect = AeroEffect;
exports.AlphaAnimation = AlphaAnimation;
exports.AndroidAssetsResource = AndroidAssetsResource;
exports.AndroidResource = AndroidResource;
exports.AnimationSet = AnimationSet;
exports.AssetResource = AssetResource;
exports.BOTTOM = BOTTOM;
exports.BackgroundColorAnimation = BackgroundColorAnimation;
exports.Base64Resource = Base64Resource;
@ -5054,6 +5067,7 @@ exports.CENTER = CENTER;
exports.CENTER_X = CENTER_X;
exports.CENTER_Y = CENTER_Y;
exports.Color = Color;
exports.DoricAssetsResource = DoricAssetsResource;
exports.Draggable = Draggable;
exports.DrawableResource = DrawableResource;
exports.FlexLayout = FlexLayout;
@ -5121,6 +5135,7 @@ exports.flowlayout = flowlayout;
exports.gestureContainer = gestureContainer;
exports.gravity = gravity;
exports.hlayout = hlayout;
exports.iOSResource = iOSResource;
exports.image = image;
exports.input = input;
exports.internalScheme = internalScheme;

File diff suppressed because one or more lines are too long