Merge branch 'feature/slider' into 'master'
Feature/slider See merge request !24
This commit is contained in:
commit
5189ee320e
@ -19,6 +19,7 @@ import android.text.TextUtils;
|
||||
|
||||
import pub.doric.plugin.NetworkPlugin;
|
||||
import pub.doric.plugin.ShaderPlugin;
|
||||
import pub.doric.plugin.StoragePlugin;
|
||||
import pub.doric.shader.HLayoutNode;
|
||||
import pub.doric.shader.ImageNode;
|
||||
import pub.doric.shader.ScrollerNode;
|
||||
@ -67,6 +68,7 @@ public class DoricRegistry {
|
||||
this.registerNativePlugin(ShaderPlugin.class);
|
||||
this.registerNativePlugin(ModalPlugin.class);
|
||||
this.registerNativePlugin(NetworkPlugin.class);
|
||||
this.registerNativePlugin(StoragePlugin.class);
|
||||
this.registerViewNode(RootNode.class);
|
||||
this.registerViewNode(TextNode.class);
|
||||
this.registerViewNode(ImageNode.class);
|
||||
|
@ -50,7 +50,7 @@ public class ModalPlugin extends DoricJavaPlugin {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@DoricMethod(name = "toast", thread = ThreadMode.UI)
|
||||
@DoricMethod(thread = ThreadMode.UI)
|
||||
public void toast(JSDecoder decoder, DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
@ -72,12 +72,12 @@ public class ModalPlugin extends DoricJavaPlugin {
|
||||
|
||||
}
|
||||
toast.show();
|
||||
} catch (ArchiveException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@DoricMethod(name = "alert", thread = ThreadMode.UI)
|
||||
@DoricMethod(thread = ThreadMode.UI)
|
||||
public void alert(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
@ -101,19 +101,15 @@ public class ModalPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
});
|
||||
builder.setCancelable(false);
|
||||
try {
|
||||
builder.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (ArchiveException e) {
|
||||
builder.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DoricMethod(name = "confirm", thread = ThreadMode.UI)
|
||||
@DoricMethod(thread = ThreadMode.UI)
|
||||
public void confirm(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
@ -148,19 +144,15 @@ public class ModalPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
});
|
||||
builder.setCancelable(false);
|
||||
try {
|
||||
builder.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (ArchiveException e) {
|
||||
builder.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DoricMethod(name = "prompt", thread = ThreadMode.UI)
|
||||
@DoricMethod(thread = ThreadMode.UI)
|
||||
public void prompt(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
@ -187,7 +179,9 @@ public class ModalPlugin extends DoricJavaPlugin {
|
||||
|
||||
View v = LayoutInflater.from(getDoricContext().getContext()).inflate(R.layout.doric_modal_prompt, null);
|
||||
TextView tvMsg = v.findViewById(R.id.tv_msg);
|
||||
tvMsg.setText(msgVal.asString().value());
|
||||
if (msgVal.isString()) {
|
||||
tvMsg.setText(msgVal.asString().value());
|
||||
}
|
||||
final EditText editText = v.findViewById(R.id.edit_input);
|
||||
if (defaultVal.isString()) {
|
||||
editText.setHint(defaultVal.asString().value());
|
||||
@ -211,12 +205,8 @@ public class ModalPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
});
|
||||
builder.setCancelable(false);
|
||||
try {
|
||||
builder.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (ArchiveException e) {
|
||||
builder.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class NetworkPlugin extends DoricJavaPlugin {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@DoricMethod(name = "request")
|
||||
@DoricMethod
|
||||
public void request(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject requestVal = decoder.decode().asObject();
|
||||
|
114
Android/doric/src/main/java/pub/doric/plugin/StoragePlugin.java
Normal file
114
Android/doric/src/main/java/pub/doric/plugin/StoragePlugin.java
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright [2019] [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.content.Context;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricMethod;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.extension.bridge.DoricPromise;
|
||||
|
||||
/**
|
||||
* @Description: pub.doric.plugin
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-11-22
|
||||
*/
|
||||
@DoricPlugin(name = "storage")
|
||||
public class StoragePlugin extends DoricJavaPlugin {
|
||||
private static final String PREF_NAME = "pref_doric";
|
||||
|
||||
public StoragePlugin(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void setItem(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
JSValue zone = jsObject.getProperty("zone");
|
||||
String key = jsObject.getProperty("key").asString().value();
|
||||
String value = jsObject.getProperty("value").asString().value();
|
||||
String prefName = zone.isString() ? PREF_NAME + "_" + zone.asString() : PREF_NAME;
|
||||
getDoricContext().getContext().getSharedPreferences(
|
||||
prefName,
|
||||
Context.MODE_PRIVATE).edit().putString(key, value).apply();
|
||||
promise.resolve();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void getItem(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
JSValue zone = jsObject.getProperty("zone");
|
||||
String key = jsObject.getProperty("key").asString().value();
|
||||
String prefName = zone.isString() ? PREF_NAME + "_" + zone.asString() : PREF_NAME;
|
||||
String ret = getDoricContext().getContext().getSharedPreferences(
|
||||
prefName,
|
||||
Context.MODE_PRIVATE).getString(key, "");
|
||||
promise.resolve(new JavaValue(ret));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void remove(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
JSValue zone = jsObject.getProperty("zone");
|
||||
String key = jsObject.getProperty("key").asString().value();
|
||||
String prefName = zone.isString() ? PREF_NAME + "_" + zone.asString() : PREF_NAME;
|
||||
getDoricContext().getContext().getSharedPreferences(
|
||||
prefName,
|
||||
Context.MODE_PRIVATE).edit().remove(key).apply();
|
||||
promise.resolve();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void clear(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
JSValue zone = jsObject.getProperty("zone");
|
||||
if (zone.isString()) {
|
||||
String prefName = PREF_NAME + "_" + zone.asString();
|
||||
getDoricContext().getContext().getSharedPreferences(
|
||||
prefName,
|
||||
Context.MODE_PRIVATE).edit().clear().apply();
|
||||
promise.resolve();
|
||||
} else {
|
||||
promise.reject(new JavaValue("Zone is empty"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ public class ScrollerNode extends SuperNode<HVScrollView> {
|
||||
@Override
|
||||
protected void blendSubNode(JSObject subProperties) {
|
||||
if (mChildNode != null) {
|
||||
mChildNode.blend(subProperties);
|
||||
mChildNode.blend(subProperties.getProperty("props").asObject());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,4 +9,5 @@ export default [
|
||||
'src/ImageDemo',
|
||||
'src/ModalDemo',
|
||||
'src/NetworkDemo',
|
||||
'src/StorageDemo',
|
||||
]
|
@ -29,6 +29,18 @@ class ImageDemo extends Panel {
|
||||
loadCallback: (ret) => {
|
||||
}
|
||||
}),
|
||||
label('Animated WebP'),
|
||||
image({
|
||||
imageUrl: "https://p.upyun.com/demo/webp/webp/animated-gif-0.webp",
|
||||
loadCallback: (ret) => {
|
||||
}
|
||||
}),
|
||||
label('WebP'),
|
||||
image({
|
||||
imageUrl: "https://p.upyun.com/demo/webp/webp/jpg-0.webp",
|
||||
loadCallback: (ret) => {
|
||||
}
|
||||
}),
|
||||
label('ScaleToFill'),
|
||||
image({
|
||||
imageUrl,
|
||||
|
93
demo/src/StorageDemo.ts
Normal file
93
demo/src/StorageDemo.ts
Normal file
@ -0,0 +1,93 @@
|
||||
import { storage, Panel, scroller, vlayout, text, layoutConfig, LayoutSpec, Color, gravity, IVLayout, Group, IText, modal, Text, log, loge } from "doric";
|
||||
import { colors, label } from "./utils";
|
||||
const storedKey = 'StoredKey'
|
||||
const zone = 'StorageDemo'
|
||||
@Entry
|
||||
class StorageDemo extends Panel {
|
||||
stored!: Text
|
||||
|
||||
update() {
|
||||
storage(context).getItem(storedKey, zone).then(e => {
|
||||
this.stored.text = e || ""
|
||||
log('Called in then')
|
||||
})
|
||||
}
|
||||
|
||||
build(root: Group) {
|
||||
scroller(vlayout([
|
||||
text({
|
||||
text: "Storage Demo",
|
||||
layoutConfig: layoutConfig().w(LayoutSpec.AT_MOST),
|
||||
textSize: 30,
|
||||
textColor: Color.WHITE,
|
||||
bgColor: colors[1],
|
||||
textAlignment: gravity().center(),
|
||||
height: 50,
|
||||
}),
|
||||
label('Stored'),
|
||||
text({
|
||||
layoutConfig: layoutConfig().w(LayoutSpec.AT_MOST),
|
||||
textSize: 20,
|
||||
textColor: Color.WHITE,
|
||||
bgColor: colors[3],
|
||||
textAlignment: gravity().center(),
|
||||
height: 50,
|
||||
}).also(it => this.stored = it),
|
||||
label('store a value').apply({
|
||||
width: 200,
|
||||
height: 50,
|
||||
bgColor: colors[0],
|
||||
textSize: 30,
|
||||
textColor: Color.WHITE,
|
||||
layoutConfig: layoutConfig().exactly(),
|
||||
onClick: () => {
|
||||
storage(context).getItem(storedKey, zone).then(e => {
|
||||
modal(context).prompt({
|
||||
text: e,
|
||||
title: "Please input text to store",
|
||||
defaultText: "Default Value",
|
||||
}).then(text => {
|
||||
storage(context).setItem(storedKey, text, zone).then(() => {
|
||||
this.update()
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
} as IText),
|
||||
label('remove value').apply({
|
||||
width: 200,
|
||||
height: 50,
|
||||
bgColor: colors[0],
|
||||
textSize: 30,
|
||||
textColor: Color.WHITE,
|
||||
layoutConfig: layoutConfig().exactly(),
|
||||
onClick: () => {
|
||||
storage(context).remove(storedKey, zone).then(e => {
|
||||
this.update()
|
||||
})
|
||||
},
|
||||
} as IText),
|
||||
label('clear values').apply({
|
||||
width: 200,
|
||||
height: 50,
|
||||
bgColor: colors[0],
|
||||
textSize: 30,
|
||||
textColor: Color.WHITE,
|
||||
layoutConfig: layoutConfig().exactly(),
|
||||
onClick: () => {
|
||||
storage(context).clear(zone).then(e => {
|
||||
this.update()
|
||||
})
|
||||
},
|
||||
} as IText),
|
||||
]).apply({
|
||||
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
|
||||
gravity: gravity().center(),
|
||||
space: 10,
|
||||
} as IVLayout)).apply({
|
||||
layoutConfig: layoutConfig().atmost(),
|
||||
}).in(root)
|
||||
this.update()
|
||||
}
|
||||
|
||||
}
|
@ -39,7 +39,9 @@ TODO: Add long description of the pod here.
|
||||
s.public_header_files = 'Pod/Classes/**/*.h'
|
||||
# s.frameworks = 'UIKit', 'MapKit'
|
||||
# s.dependency 'AFNetworking', '~> 2.3'
|
||||
s.dependency 'SDWebImage', '~> 5.0'
|
||||
s.dependency 'SDWebImage', '~> 4.4.7'
|
||||
s.dependency 'SDWebImage/WebP'
|
||||
s.dependency 'SocketRocket', '~> 0.5.1'
|
||||
s.dependency 'GCDWebServer', '~> 3.0'
|
||||
s.dependency 'YYCache', '~> 1.0.4'
|
||||
end
|
||||
|
@ -1,15 +1,30 @@
|
||||
PODS:
|
||||
- Doric (0.1.0):
|
||||
- GCDWebServer (~> 3.0)
|
||||
- SDWebImage (~> 5.0)
|
||||
- SDWebImage (~> 4.4.7)
|
||||
- SDWebImage/WebP
|
||||
- SocketRocket (~> 0.5.1)
|
||||
- GCDWebServer (3.5.2):
|
||||
- GCDWebServer/Core (= 3.5.2)
|
||||
- GCDWebServer/Core (3.5.2)
|
||||
- SDWebImage (5.0.6):
|
||||
- SDWebImage/Core (= 5.0.6)
|
||||
- SDWebImage/Core (5.0.6)
|
||||
- YYCache (~> 1.0.4)
|
||||
- GCDWebServer (3.5.3):
|
||||
- GCDWebServer/Core (= 3.5.3)
|
||||
- GCDWebServer/Core (3.5.3)
|
||||
- libwebp (1.0.3):
|
||||
- libwebp/demux (= 1.0.3)
|
||||
- libwebp/mux (= 1.0.3)
|
||||
- libwebp/webp (= 1.0.3)
|
||||
- libwebp/demux (1.0.3):
|
||||
- libwebp/webp
|
||||
- libwebp/mux (1.0.3):
|
||||
- libwebp/demux
|
||||
- libwebp/webp (1.0.3)
|
||||
- SDWebImage (4.4.7):
|
||||
- SDWebImage/Core (= 4.4.7)
|
||||
- SDWebImage/Core (4.4.7)
|
||||
- SDWebImage/WebP (4.4.7):
|
||||
- libwebp (< 2.0, >= 0.5)
|
||||
- SDWebImage/Core
|
||||
- SocketRocket (0.5.1)
|
||||
- YYCache (1.0.4)
|
||||
|
||||
DEPENDENCIES:
|
||||
- Doric (from `../`)
|
||||
@ -17,18 +32,22 @@ DEPENDENCIES:
|
||||
SPEC REPOS:
|
||||
https://github.com/cocoapods/specs.git:
|
||||
- GCDWebServer
|
||||
- libwebp
|
||||
- SDWebImage
|
||||
- SocketRocket
|
||||
- YYCache
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Doric:
|
||||
:path: "../"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Doric: f96b77d435e836e88cf02319e3c9ebc08cab65f6
|
||||
GCDWebServer: ead88cd14596dd4eae4f5830b8877c87c8728990
|
||||
SDWebImage: 920f1a2ff1ca8296ad34f6e0510a1ef1d70ac965
|
||||
Doric: c71287d68afeeb79bfd3c680ed2dd3b90d515c12
|
||||
GCDWebServer: c0ab22c73e1b84f358d1e2f74bf6afd1c60829f2
|
||||
libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e
|
||||
SDWebImage: c10d14a8883ebd89664f02a422006f66a85c0c5d
|
||||
SocketRocket: d57c7159b83c3c6655745cd15302aa24b6bae531
|
||||
YYCache: 8105b6638f5e849296c71f331ff83891a4942952
|
||||
|
||||
PODFILE CHECKSUM: 012563d71439e7e33e976dca3b59664ed56cee39
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#import "DoricScrollerNode.h"
|
||||
#import "DoricSliderNode.h"
|
||||
#import "DoricSlideItemNode.h"
|
||||
#import "DoricStoragePlugin.h"
|
||||
|
||||
@interface DoricRegistry ()
|
||||
|
||||
@ -56,9 +57,10 @@ - (instancetype)init {
|
||||
}
|
||||
|
||||
- (void)innerRegister {
|
||||
[self registerNativePlugin:DoricShaderPlugin.class withName:@"shader"];
|
||||
[self registerNativePlugin:DoricModalPlugin.class withName:@"modal"];
|
||||
[self registerNativePlugin:DoricNetworkPlugin.class withName:@"network"];
|
||||
[self registerNativePlugin:DoricShaderPlugin.class withName:@"shader"];
|
||||
[self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"];
|
||||
|
||||
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
||||
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
|
||||
|
@ -31,6 +31,9 @@
|
||||
@implementation DoricShaderPlugin
|
||||
|
||||
- (void)render:(NSDictionary *)argument {
|
||||
if(!argument) {
|
||||
return;
|
||||
}
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__strong typeof(_self) self = _self;
|
||||
|
24
iOS/Pod/Classes/Plugin/DoricStoragePlugin.h
Normal file
24
iOS/Pod/Classes/Plugin/DoricStoragePlugin.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright [2019] [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 2019/11/22.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricStoragePlugin : DoricNativePlugin
|
||||
@end
|
98
iOS/Pod/Classes/Plugin/DoricStoragePlugin.m
Normal file
98
iOS/Pod/Classes/Plugin/DoricStoragePlugin.m
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright [2019] [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 2019/11/22.
|
||||
//
|
||||
|
||||
#import "DoricStoragePlugin.h"
|
||||
#import "YYDiskCache.h"
|
||||
|
||||
static NSString *doric_prefix = @"pref";
|
||||
|
||||
@interface DoricStoragePlugin ()
|
||||
@property(atomic, strong) NSMutableDictionary <NSString *, YYDiskCache *> *cachedMap;
|
||||
@property(nonatomic, strong) YYDiskCache *defaultCache;
|
||||
@property(nonatomic, copy) NSString *basePath;
|
||||
@end
|
||||
|
||||
@implementation DoricStoragePlugin
|
||||
- (instancetype)initWithContext:(DoricContext *)doricContext {
|
||||
if (self = [super initWithContext:doricContext]) {
|
||||
_basePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
|
||||
stringByAppendingPathComponent:@"doric"];
|
||||
_cachedMap = [NSMutableDictionary new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (YYDiskCache *)defaultCache {
|
||||
if (!_defaultCache) {
|
||||
_defaultCache = [[YYDiskCache alloc] initWithPath:[self.basePath stringByAppendingPathComponent:doric_prefix]];
|
||||
}
|
||||
return _defaultCache;
|
||||
}
|
||||
|
||||
- (YYDiskCache *)getDiskCache:(NSString *)zone {
|
||||
YYDiskCache *diskCache;
|
||||
if (zone) {
|
||||
diskCache = self.cachedMap[zone];
|
||||
if (!diskCache) {
|
||||
diskCache = [[YYDiskCache alloc] initWithPath:[self.basePath
|
||||
stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@", doric_prefix, zone]]];
|
||||
self.cachedMap[zone] = diskCache;
|
||||
}
|
||||
} else {
|
||||
diskCache = self.defaultCache;
|
||||
}
|
||||
return diskCache;
|
||||
}
|
||||
|
||||
- (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
NSString *key = argument[@"key"];
|
||||
NSString *value = argument[@"value"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache setObject:value forKey:key withBlock:^{
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
NSString *key = argument[@"key"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache objectForKey:key withBlock:^(NSString *key, NSString *value) {
|
||||
[promise resolve:value];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
NSString *key = argument[@"key"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache removeObjectForKey:key withBlock:^(NSString *key) {
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)clear:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache removeAllObjectsWithBlock:^{
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
}
|
||||
@end
|
@ -22,7 +22,7 @@
|
||||
|
||||
#import "DoricImageNode.h"
|
||||
#import "Doric.h"
|
||||
#import <SDWebImage/SDWebImage.h>
|
||||
#import <SDWebImage/UIImageView+WebCache.h>
|
||||
|
||||
@interface DoricImageNode ()
|
||||
@property(nonatomic, copy) NSString *loadCallbackId;
|
||||
|
@ -102,6 +102,6 @@ - (void)blendView:(UIScrollView *)view forPropName:(NSString *)name propValue:(i
|
||||
}
|
||||
|
||||
- (void)blendSubNode:(NSDictionary *)subModel {
|
||||
[self.childNode blend:subModel];
|
||||
[self.childNode blend:subModel[@"props"]];
|
||||
}
|
||||
@end
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
import './../runtime/global'
|
||||
import { View, Group } from "./view";
|
||||
import { loge } from '../util/log';
|
||||
import { loge, log } from '../util/log';
|
||||
import { Model } from '../util/types';
|
||||
import { Root } from './layout';
|
||||
|
||||
@ -117,6 +117,8 @@ export abstract class Panel {
|
||||
}
|
||||
|
||||
private hookAfterNativeCall() {
|
||||
//Here insert a native call to ensure the promise is resolved done.
|
||||
log('Check Dirty')
|
||||
if (this.__root__.isDirty()) {
|
||||
const model = this.__root__.toModel()
|
||||
this.nativeRender(model)
|
||||
|
@ -149,4 +149,21 @@ export function network(context: BridgeContext) {
|
||||
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse>
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function storage(context: BridgeContext) {
|
||||
return {
|
||||
setItem: (key: string, value: string, zone?: string) => {
|
||||
return context.storage.setItem({ key, value, zone })
|
||||
},
|
||||
getItem: (key: string, zone?: string) => {
|
||||
return context.storage.getItem({ key, zone }) as Promise<string>
|
||||
},
|
||||
remove: (key: string, zone?: string) => {
|
||||
return context.storage.remove({ key, zone })
|
||||
},
|
||||
clear: (zone: string) => {
|
||||
return context.storage.clear({ zone })
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user