Merge branch 'feature/dev' into 'master'

Feature/dev



See merge request !31
This commit is contained in:
pengfeizhou 2019-11-28 11:26:51 +08:00
commit 301e521f94
42 changed files with 573 additions and 358 deletions

View File

@ -34,6 +34,7 @@ public class AsyncCall {
try { try {
asyncResult.setResult(callable.call()); asyncResult.setResult(callable.call());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
asyncResult.setError(e); asyncResult.setError(e);
} }
} else { } else {
@ -43,6 +44,7 @@ public class AsyncCall {
try { try {
asyncResult.setResult(callable.call()); asyncResult.setResult(callable.call());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
asyncResult.setError(e); asyncResult.setError(e);
} }
} }

View File

@ -28,7 +28,6 @@ import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.extension.bridge.DoricPromise; import pub.doric.extension.bridge.DoricPromise;
import pub.doric.navbar.IDoricNavBar; import pub.doric.navbar.IDoricNavBar;
import pub.doric.utils.DoricUtils;
import pub.doric.utils.ThreadMode; import pub.doric.utils.ThreadMode;
/** /**
@ -62,7 +61,7 @@ public class NavBarPlugin extends DoricJavaPlugin {
JSObject jsObject = jsDecoder.decode().asObject(); JSObject jsObject = jsDecoder.decode().asObject();
boolean hidden = jsObject.getProperty("hidden").asBoolean().value(); boolean hidden = jsObject.getProperty("hidden").asBoolean().value();
navBar.setHidden(hidden); navBar.setHidden(hidden);
View v = getDoricContext().getRootNode().getDoricLayer(); View v = getDoricContext().getRootNode().getNodeView();
ViewGroup.LayoutParams params = v.getLayoutParams(); ViewGroup.LayoutParams params = v.getLayoutParams();
if (params instanceof ViewGroup.MarginLayoutParams) { if (params instanceof ViewGroup.MarginLayoutParams) {
((ViewGroup.MarginLayoutParams) params).topMargin = ((ViewGroup.MarginLayoutParams) params).topMargin =

View File

@ -85,7 +85,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
mContentNode.setId(viewId); mContentNode.setId(viewId);
mContentNode.init(this); mContentNode.init(this);
mContentNode.blend(props); mContentNode.blend(props);
mView.addView(mContentNode.getDoricLayer()); mView.addView(mContentNode.getNodeView());
} }
} }
} else { } else {
@ -93,7 +93,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
mContentNode.setId(viewId); mContentNode.setId(viewId);
mContentNode.init(this); mContentNode.init(this);
mContentNode.blend(props); mContentNode.blend(props);
mView.addView(mContentNode.getDoricLayer()); mView.addView(mContentNode.getNodeView());
} }
} }
@ -117,7 +117,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
mHeaderNode.setId(viewId); mHeaderNode.setId(viewId);
mHeaderNode.init(this); mHeaderNode.init(this);
mHeaderNode.blend(props); mHeaderNode.blend(props);
mView.getRefreshView().setContent(mHeaderNode.getDoricLayer()); mView.getRefreshView().setContent(mHeaderNode.getNodeView());
} }
} }
} else { } else {
@ -125,7 +125,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
mHeaderNode.setId(viewId); mHeaderNode.setId(viewId);
mHeaderNode.init(this); mHeaderNode.init(this);
mHeaderNode.blend(props); mHeaderNode.blend(props);
mView.getRefreshView().setContent(mHeaderNode.getDoricLayer()); mView.getRefreshView().setContent(mHeaderNode.getNodeView());
} }
} }

View File

@ -75,13 +75,13 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
} else { } else {
//Replace this view //Replace this view
mChildNodes.remove(idx); mChildNodes.remove(idx);
mView.removeView(oldNode.getDoricLayer()); mView.removeView(oldNode.getNodeView());
ViewNode newNode = ViewNode.create(getDoricContext(), type); ViewNode newNode = ViewNode.create(getDoricContext(), type);
newNode.setId(id); newNode.setId(id);
newNode.init(this); newNode.init(this);
newNode.blend(model.getProperty("props").asObject()); newNode.blend(model.getProperty("props").asObject());
mChildNodes.add(idx, newNode); mChildNodes.add(idx, newNode);
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams()); mView.addView(newNode.getNodeView(), idx, newNode.getLayoutParams());
} }
} else { } else {
//Find in remain nodes //Find in remain nodes
@ -101,10 +101,10 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
mChildNodes.set(idx, reused); mChildNodes.set(idx, reused);
mChildNodes.set(position, abandoned); mChildNodes.set(position, abandoned);
//View swap index //View swap index
mView.removeView(reused.getDoricLayer()); mView.removeView(reused.getNodeView());
mView.addView(reused.getDoricLayer(), idx); mView.addView(reused.getNodeView(), idx);
mView.removeView(abandoned.getDoricLayer()); mView.removeView(abandoned.getNodeView());
mView.addView(abandoned.getDoricLayer(), position); mView.addView(abandoned.getNodeView(), position);
} else { } else {
//Not found,insert //Not found,insert
ViewNode newNode = ViewNode.create(getDoricContext(), type); ViewNode newNode = ViewNode.create(getDoricContext(), type);
@ -113,7 +113,7 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
newNode.blend(model.getProperty("props").asObject()); newNode.blend(model.getProperty("props").asObject());
mChildNodes.add(idx, newNode); mChildNodes.add(idx, newNode);
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams()); mView.addView(newNode.getNodeView(), idx, newNode.getLayoutParams());
} }
} }
} }
@ -124,13 +124,13 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
newNode.init(this); newNode.init(this);
newNode.blend(model.getProperty("props").asObject()); newNode.blend(model.getProperty("props").asObject());
mChildNodes.add(newNode); mChildNodes.add(newNode);
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams()); mView.addView(newNode.getNodeView(), idx, newNode.getLayoutParams());
} }
} }
int size = mChildNodes.size(); int size = mChildNodes.size();
for (int idx = mChildViewIds.size(); idx < size; idx++) { for (int idx = mChildViewIds.size(); idx < size; idx++) {
ViewNode viewNode = mChildNodes.remove(mChildViewIds.size()); ViewNode viewNode = mChildNodes.remove(mChildViewIds.size());
mView.removeView(viewNode.getDoricLayer()); mView.removeView(viewNode.getNodeView());
} }
} }

View File

@ -36,7 +36,7 @@ public class RootNode extends StackNode {
} }
@Override @Override
public View getDoricLayer() { public View getNodeView() {
return mView; return mView;
} }

View File

@ -86,7 +86,7 @@ public class ScrollerNode extends SuperNode<HVScrollView> {
mChildNode.setId(viewId); mChildNode.setId(viewId);
mChildNode.init(this); mChildNode.init(this);
mChildNode.blend(props); mChildNode.blend(props);
mView.addView(mChildNode.getDoricLayer()); mView.addView(mChildNode.getNodeView());
} }
} }
} else { } else {
@ -94,7 +94,7 @@ public class ScrollerNode extends SuperNode<HVScrollView> {
mChildNode.setId(viewId); mChildNode.setId(viewId);
mChildNode.init(this); mChildNode.init(this);
mChildNode.blend(props); mChildNode.blend(props);
mView.addView(mChildNode.getDoricLayer()); mView.addView(mChildNode.getNodeView());
} }
} }

View File

@ -21,6 +21,8 @@ import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.DoricRegistry; import pub.doric.DoricRegistry;
import pub.doric.async.AsyncResult; import pub.doric.async.AsyncResult;
@ -60,11 +62,8 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
} }
this.mSuperNode = superNode; this.mSuperNode = superNode;
this.mLayoutParams = superNode.generateDefaultLayoutParams(); this.mLayoutParams = superNode.generateDefaultLayoutParams();
this.doricLayer = new DoricLayer(getContext());
this.doricLayer.setLayoutParams(mLayoutParams);
this.mView = build(); this.mView = build();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mLayoutParams.width, mLayoutParams.height); this.mView.setLayoutParams(mLayoutParams);
doricLayer.addView(mView, params);
} }
public void setId(String id) { public void setId(String id) {
@ -75,8 +74,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
return mType; return mType;
} }
public View getDoricLayer() { public View getNodeView() {
if (doricLayer != null) {
return doricLayer; return doricLayer;
} else {
return mView;
}
} }
public Context getContext() { public Context getContext() {
@ -91,6 +94,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
blend(mView, prop, jsObject.getProperty(prop)); blend(mView, prop, jsObject.getProperty(prop));
} }
} }
if (doricLayer != null) {
ViewGroup.LayoutParams params = mView.getLayoutParams(); ViewGroup.LayoutParams params = mView.getLayoutParams();
if (params != null) { if (params != null) {
params.width = mLayoutParams.width; params.width = mLayoutParams.width;
@ -108,6 +112,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
mView.setLayoutParams(params); mView.setLayoutParams(params);
} }
}
protected void blend(T view, String name, JSValue prop) { protected void blend(T view, String name, JSValue prop) {
switch (name) { switch (name) {
@ -139,34 +144,30 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
setLayoutConfig(prop.asObject()); setLayoutConfig(prop.asObject());
break; break;
case "border": case "border":
if (prop.isObject() && doricLayer != null) { if (prop.isObject()) {
doricLayer.setBorder(DoricUtils.dp2px(prop.asObject().getProperty("width").asNumber().toFloat()), requireDoricLayer().setBorder(DoricUtils.dp2px(prop.asObject().getProperty("width").asNumber().toFloat()),
prop.asObject().getProperty("color").asNumber().toInt()); prop.asObject().getProperty("color").asNumber().toInt());
} }
break; break;
case "corners": case "corners":
if (doricLayer != null) {
if (prop.isNumber()) { if (prop.isNumber()) {
doricLayer.setCornerRadius(DoricUtils.dp2px(prop.asNumber().toFloat())); requireDoricLayer().setCornerRadius(DoricUtils.dp2px(prop.asNumber().toFloat()));
} else if (prop.isObject()) { } else if (prop.isObject()) {
JSValue lt = prop.asObject().getProperty("leftTop"); JSValue lt = prop.asObject().getProperty("leftTop");
JSValue rt = prop.asObject().getProperty("rightTop"); JSValue rt = prop.asObject().getProperty("rightTop");
JSValue rb = prop.asObject().getProperty("rightBottom"); JSValue rb = prop.asObject().getProperty("rightBottom");
JSValue lb = prop.asObject().getProperty("leftBottom"); JSValue lb = prop.asObject().getProperty("leftBottom");
doricLayer.setCornerRadius( requireDoricLayer().setCornerRadius(
DoricUtils.dp2px(lt.isNumber() ? lt.asNumber().toFloat() : 0), DoricUtils.dp2px(lt.isNumber() ? lt.asNumber().toFloat() : 0),
DoricUtils.dp2px(rt.isNumber() ? rt.asNumber().toFloat() : 0), DoricUtils.dp2px(rt.isNumber() ? rt.asNumber().toFloat() : 0),
DoricUtils.dp2px(rb.isNumber() ? rb.asNumber().toFloat() : 0), DoricUtils.dp2px(rb.isNumber() ? rb.asNumber().toFloat() : 0),
DoricUtils.dp2px(lb.isNumber() ? lb.asNumber().toFloat() : 0) DoricUtils.dp2px(lb.isNumber() ? lb.asNumber().toFloat() : 0)
); );
} }
}
break; break;
case "shadow": case "shadow":
if (doricLayer != null) {
if (prop.isObject()) { if (prop.isObject()) {
doricLayer.setShadow( requireDoricLayer().setShadow(
prop.asObject().getProperty("color").asNumber().toInt(), prop.asObject().getProperty("color").asNumber().toInt(),
(int) (prop.asObject().getProperty("opacity").asNumber().toFloat() * 255), (int) (prop.asObject().getProperty("opacity").asNumber().toFloat() * 255),
DoricUtils.dp2px(prop.asObject().getProperty("radius").asNumber().toFloat()), DoricUtils.dp2px(prop.asObject().getProperty("radius").asNumber().toFloat()),
@ -174,13 +175,32 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
DoricUtils.dp2px(prop.asObject().getProperty("offsetY").asNumber().toFloat()) DoricUtils.dp2px(prop.asObject().getProperty("offsetY").asNumber().toFloat())
); );
} }
}
break; break;
default: default:
break; break;
} }
} }
@NonNull
private DoricLayer requireDoricLayer() {
if (doricLayer == null) {
doricLayer = new DoricLayer(getContext());
doricLayer.setLayoutParams(mLayoutParams);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mLayoutParams.width, mLayoutParams.height);
if (mView.getParent() instanceof ViewGroup) {
//Already added in
ViewGroup superview = (ViewGroup) mView.getParent();
int index = superview.indexOfChild(mView);
superview.removeView(mView);
doricLayer.addView(mView, params);
superview.addView(doricLayer, index);
} else {
doricLayer.addView(mView, params);
}
}
return doricLayer;
}
String[] getIdList() { String[] getIdList() {
LinkedList<String> ids = new LinkedList<>(); LinkedList<String> ids = new LinkedList<>();
ViewNode viewNode = this; ViewNode viewNode = this;
@ -250,12 +270,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
@DoricMethod @DoricMethod
public int getWidth() { public int getWidth() {
return mView.getWidth(); return getNodeView().getWidth();
} }
@DoricMethod @DoricMethod
public int getHeight() { public int getHeight() {
return mView.getHeight(); return getNodeView().getHeight();
} }
@DoricMethod @DoricMethod
@ -267,11 +287,11 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
while (rotation < -1) { while (rotation < -1) {
rotation = rotation + 1; rotation = rotation + 1;
} }
doricLayer.setRotation(rotation * 360); getNodeView().setRotation(rotation * 360);
} }
@DoricMethod @DoricMethod
public float getRotation() { public float getRotation() {
return doricLayer.getRotation() / 360; return getNodeView().getRotation() / 360;
} }
} }

View File

@ -54,7 +54,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ListItemNode node = (ListItemNode) ViewNode.create(listNode.getDoricContext(), "ListItem"); ListItemNode node = (ListItemNode) ViewNode.create(listNode.getDoricContext(), "ListItem");
node.init(listNode); node.init(listNode);
return new DoricViewHolder(node, node.getDoricLayer()); return new DoricViewHolder(node, node.getNodeView());
} }
@Override @Override

View File

@ -50,7 +50,7 @@ public class ListItemNode extends StackNode {
@Override @Override
public void blend(JSObject jsObject) { public void blend(JSObject jsObject) {
super.blend(jsObject); super.blend(jsObject);
getDoricLayer().getLayoutParams().width = getLayoutParams().width; getNodeView().getLayoutParams().width = getLayoutParams().width;
getDoricLayer().getLayoutParams().height = getLayoutParams().height; getNodeView().getLayoutParams().height = getLayoutParams().height;
} }
} }

View File

@ -53,7 +53,7 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
SlideItemNode node = (SlideItemNode) ViewNode.create(sliderNode.getDoricContext(), "SlideItem"); SlideItemNode node = (SlideItemNode) ViewNode.create(sliderNode.getDoricContext(), "SlideItem");
node.init(sliderNode); node.init(sliderNode);
return new DoricViewHolder(node, node.getDoricLayer()); return new DoricViewHolder(node, node.getNodeView());
} }
@Override @Override

View File

@ -50,7 +50,7 @@ public class SlideItemNode extends StackNode {
@Override @Override
public void blend(JSObject jsObject) { public void blend(JSObject jsObject) {
super.blend(jsObject); super.blend(jsObject);
getDoricLayer().getLayoutParams().width = getLayoutParams().width; getNodeView().getLayoutParams().width = getLayoutParams().width;
getDoricLayer().getLayoutParams().height = getLayoutParams().height; getNodeView().getLayoutParams().height = getLayoutParams().height;
} }
} }

View File

@ -97,7 +97,7 @@ class RefreshableDemo extends Panel {
}), }),
]).apply({ ]).apply({
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT), layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
gravity: gravity().center(), gravity: gravity().centerX(),
space: 10, space: 10,
} as IVLayout)) } as IVLayout))
}).apply({ }).apply({

View File

@ -38,7 +38,7 @@ export function boxStr(str: string, idx = 0) {
export function title(str: string) { export function title(str: string) {
return text({ return text({
text: "Network Demo", text: str,
layoutConfig: layoutConfig().w(LayoutSpec.AT_MOST), layoutConfig: layoutConfig().w(LayoutSpec.AT_MOST),
textSize: 30, textSize: 30,
textColor: Color.WHITE, textColor: Color.WHITE,

View File

@ -49,8 +49,8 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
- (void)blend:(NSDictionary *)props { - (void)blend:(NSDictionary *)props {
[super blend:props]; [super blend:props];
[self blendHeader];
[self blendContent]; [self blendContent];
[self blendHeader];
} }
- (void)blendContent { - (void)blendContent {

View File

@ -5,6 +5,7 @@
#import "DoricSwipeRefreshLayout.h" #import "DoricSwipeRefreshLayout.h"
#import "UIView+Doric.h" #import "UIView+Doric.h"
#import "DoricLayouts.h" #import "DoricLayouts.h"
#import "Doric.h"
@interface DoricSwipeRefreshLayout () <UIScrollViewDelegate> @interface DoricSwipeRefreshLayout () <UIScrollViewDelegate>
@ -53,9 +54,16 @@ - (BOOL)requestFromSubview:(UIView *)subview {
} }
- (void)layoutSelf:(CGSize)targetSize { - (void)layoutSelf:(CGSize)targetSize {
[super layoutSelf:targetSize]; self.width = targetSize.width;
self.headerView.bottom = 0; self.height = targetSize.height;
self.headerView.centerX = self.centerX; [self.headerView also:^(UIView *it) {
[it layoutSelf:[it measureSize:targetSize]];
it.bottom = 0;
it.centerX = self.centerX;
}];
[self.contentView also:^(UIView *it) {
[it layoutSelf:targetSize];
}];
self.contentSize = self.frame.size; self.contentSize = self.frame.size;
} }

View File

@ -22,6 +22,7 @@
#import "DoricExtensions.h" #import "DoricExtensions.h"
#import "DoricListItemNode.h" #import "DoricListItemNode.h"
#import "DoricLayouts.h" #import "DoricLayouts.h"
#import "DoricRefreshableNode.h"
@interface DoricTableViewCell : UITableViewCell @interface DoricTableViewCell : UITableViewCell
@property(nonatomic, strong) DoricListItemNode *doricListItemNode; @property(nonatomic, strong) DoricListItemNode *doricListItemNode;
@ -73,6 +74,13 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
return self; return self;
} }
- (void)initWithSuperNode:(DoricSuperNode *)superNode {
[super initWithSuperNode:superNode];
if ([superNode isKindOfClass:[DoricRefreshableNode class]]) {
self.view.bounces = NO;
}
}
- (UITableView *)build { - (UITableView *)build {
return [[DoricTableView new] also:^(UITableView *it) { return [[DoricTableView new] also:^(UITableView *it) {
it.dataSource = self; it.dataSource = self;

View File

@ -21,6 +21,7 @@
// //
#import "DoricScrollerNode.h" #import "DoricScrollerNode.h"
#import "DoricExtensions.h" #import "DoricExtensions.h"
#import "DoricRefreshableNode.h"
@implementation DoricScrollView @implementation DoricScrollView
@ -56,6 +57,13 @@ - (DoricScrollView *)build {
return [DoricScrollView new]; return [DoricScrollView new];
} }
- (void)initWithSuperNode:(DoricSuperNode *)superNode {
[super initWithSuperNode:superNode];
if ([superNode isKindOfClass:[DoricRefreshableNode class]]) {
self.view.bounces = NO;
}
}
- (void)blend:(NSDictionary *)props { - (void)blend:(NSDictionary *)props {
[super blend:props]; [super blend:props];
NSDictionary *childModel = [self subModelOf:self.childViewId]; NSDictionary *childModel = [self subModelOf:self.childViewId];

View File

@ -13,20 +13,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
export * from "./src/ui/view"
export * from "./src/ui/layout"
export * from "./src/ui/list"
export * from "./src/ui/slider"
export * from "./src/ui/scroller"
export * from "./src/ui/widgets"
export * from "./src/ui/panel"
export * from "./src/ui/declarative"
export * from "./src/ui/refreshable"
export * from "./src/util/color"
export * from './src/util/log'
export * from './src/util/types'
export * from './src/util/gravity'
export * from './src/util/candies'
export * from './src/vm/mvvm'
export * from './src/runtime/global' export * from './src/runtime/global'
export * from './src/util/nativeModules' export * from './src/ui/index.ui'
export * from "./src/widget/index.widget"
export * from './src/native/index.native'
export * from "./src/util/index.util"
export * from "./src/pattern/index.pattern"

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
export * from './modal'
export * from './navbar'
export * from './navigator'
export * from './network'
export * from './storage'

View File

@ -0,0 +1,62 @@
/*
* 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.
*/
import { BridgeContext } from "../runtime/global"
import { Gravity } from "../util/gravity"
export function modal(context: BridgeContext) {
return {
toast: (msg: string, gravity: Gravity = Gravity.Bottom) => {
context.modal.toast({
msg,
gravity: gravity.toModel(),
})
},
alert: (arg: string | {
title: string,
msg: string,
okLabel?: string,
}) => {
if (typeof arg === 'string') {
return context.modal.alert({ msg: arg })
} else {
return context.modal.alert(arg)
}
},
confirm: (arg: string | {
title: string,
msg: string,
okLabel?: string,
cancelLabel?: string,
}) => {
if (typeof arg === 'string') {
return context.modal.confirm({ msg: arg })
} else {
return context.modal.confirm(arg)
}
},
prompt: (arg: {
title?: string,
msg?: string,
okLabel?: string,
cancelLabel?: string,
text?: string,
defaultText?: string,
}) => {
return context.modal.prompt(arg) as Promise<string>
},
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.
*/
import { BridgeContext } from "../runtime/global"
import { Panel } from "../ui/panel"
import { Color } from "../util/color"
export function navbar(context: BridgeContext) {
const entity = context.entity
let panel: Panel | undefined = undefined
if (entity instanceof Panel) {
panel = entity
}
return {
isHidden: () => {
return context.navbar.isHidden() as Promise<boolean>
},
setHidden: (hidden: boolean) => {
return context.navbar.setHidden({
hidden,
})
},
setTitle: (title: string) => {
return context.navbar.setTitle({
title,
})
},
setBgColor: (color: Color) => {
return context.navbar.setBgColor({
color: color.toModel(),
})
},
}
}

View File

@ -0,0 +1,29 @@
/*
* 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.
*/
import { BridgeContext } from "../runtime/global"
export function navigator(context: BridgeContext) {
return {
push: (scheme: string, alias: string, animated = true) => {
return context.navigator.push({
scheme, alias, animated
})
},
pop: (animated = true) => {
return context.navigator.pop({ animated })
},
}
}

View File

@ -13,54 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { BridgeContext } from "../runtime/global"; import { BridgeContext } from "../runtime/global"
import { Gravity } from "./gravity";
import { Panel } from "../ui/panel";
import { Color } from "./color";
export function modal(context: BridgeContext) {
return {
toast: (msg: string, gravity: Gravity = Gravity.Bottom) => {
context.modal.toast({
msg,
gravity: gravity.toModel(),
})
},
alert: (arg: string | {
title: string,
msg: string,
okLabel?: string,
}) => {
if (typeof arg === 'string') {
return context.modal.alert({ msg: arg })
} else {
return context.modal.alert(arg)
}
},
confirm: (arg: string | {
title: string,
msg: string,
okLabel?: string,
cancelLabel?: string,
}) => {
if (typeof arg === 'string') {
return context.modal.confirm({ msg: arg })
} else {
return context.modal.confirm(arg)
}
},
prompt: (arg: {
title?: string,
msg?: string,
okLabel?: string,
cancelLabel?: string,
text?: string,
defaultText?: string,
}) => {
return context.modal.prompt(arg) as Promise<string>
},
}
}
export interface IRequest { export interface IRequest {
// `url` is the server URL that will be used for the request // `url` is the server URL that will be used for the request
url?: string, url?: string,
@ -103,6 +57,7 @@ function transformRequest(request: IRequest) {
} }
return request return request
} }
export function network(context: BridgeContext) { export function network(context: BridgeContext) {
return { return {
request: (config: IRequest) => { request: (config: IRequest) => {
@ -152,62 +107,3 @@ export function network(context: BridgeContext) {
}, },
} }
} }
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 })
},
}
}
export function navigator(context: BridgeContext) {
return {
push: (scheme: string, alias: string, animated = true) => {
return context.navigator.push({
scheme, alias, animated
})
},
pop: (animated = true) => {
return context.navigator.pop({ animated })
},
}
}
export function navbar(context: BridgeContext) {
const entity = context.entity
let panel: Panel | undefined = undefined
if (entity instanceof Panel) {
panel = entity
}
return {
isHidden: () => {
return context.navbar.isHidden() as Promise<boolean>
},
setHidden: (hidden: boolean) => {
return context.navbar.setHidden({
hidden,
})
},
setTitle: (title: string) => {
return context.navbar.setTitle({
title,
})
},
setBgColor: (color: Color) => {
return context.navbar.setBgColor({
color: color.toModel(),
})
},
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.
*/
import { BridgeContext } from "../runtime/global"
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 })
},
}
}

View File

@ -0,0 +1,18 @@
/*
* 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.
*/
export * from './candies'
export * from './provider'
export * from './mvvm'

View File

@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { Group } from "../ui/view"; import { Group } from "../ui/view"
import { Panel } from "../ui/panel"; import { Panel } from "../ui/panel"
export abstract class ViewHolder<M>{ export abstract class ViewHolder<M>{
abstract build(root: Group): void abstract build(root: Group): void

View File

@ -36,7 +36,7 @@ import "reflect-metadata"
* Reflect.apply(function(__module){ * Reflect.apply(function(__module){
* (function(module,exports,require){ * (function(module,exports,require){
* //module content * //module content
* })(__module,__module.exports,hego.__require__); * })(__module,__module.exports,doric.__require__);
* return __module.exports * return __module.exports
* },this,[{exports:{}}]) * },this,[{exports:{}}])
* ]) * ])

View File

@ -0,0 +1,17 @@
/*
* 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.
*/
export * from './view'
export * from './panel'

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import './../runtime/global' import '../runtime/global'
import { View, Group } from "./view"; import { View, Group } from "./view"
import { loge, log } from '../util/log'; import { loge } from '../util/log'
import { Model } from '../util/types'; import { Model } from '../util/types'
import { Root } from './layout'; import { Root } from '../widget/layouts'
export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor) { export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor) {
@ -50,6 +50,14 @@ export abstract class Panel {
this.headviews.set(v.viewId, v) this.headviews.set(v.viewId, v)
} }
removeHeadView(v: View | string) {
if (v instanceof View) {
this.headviews.delete(v.viewId)
} else {
this.headviews.delete(v)
}
}
getRootView() { getRootView() {
return this.__root__ return this.__root__
} }

View File

@ -16,29 +16,9 @@
import { Color, GradientColor } from "../util/color" import { Color, GradientColor } from "../util/color"
import { Modeling, Model, obj2Model } from "../util/types"; import { Modeling, Model, obj2Model } from "../util/types";
import { uniqueId } from "../util/uniqueId"; import { uniqueId } from "../util/uniqueId";
import { Gravity } from "../util/gravity";
import { loge } from "../util/log"; import { loge } from "../util/log";
import { BridgeContext } from "../runtime/global"; import { BridgeContext } from "../runtime/global";
import { LayoutConfig } from '../util/layoutconfig'
export enum LayoutSpec {
EXACTLY = 0,
WRAP_CONTENT = 1,
AT_MOST = 2,
}
export interface LayoutConfig {
widthSpec?: LayoutSpec
heightSpec?: LayoutSpec
margin?: {
left?: number,
right?: number,
top?: number,
bottom?: number,
}
alignment?: Gravity
//Only affective in VLayout or HLayout
weight?: number
}
export function Property(target: Object, propKey: string) { export function Property(target: Object, propKey: string) {
Reflect.defineMetadata(propKey, true, target) Reflect.defineMetadata(propKey, true, target)

View File

@ -0,0 +1,21 @@
/*
* 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.
*/
export * from './color'
export * from './gravity'
export * from './layoutconfig'
export * from './log'
export * from './types'
export * from './uniqueId'

View File

@ -13,73 +13,27 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { View, LayoutSpec, LayoutConfig } from './view' import { Gravity } from "./gravity";
import { Stack, HLayout, VLayout } from './layout' import { Modeling } from "./types";
import { IText, IImage, Text, Image } from './widgets'
import { IList, List } from './list'
import { ISlider, Slider } from './slider'
import { Gravity } from '../util/gravity'
import { Modeling } from '../util/types'
export function text(config: IText) { export enum LayoutSpec {
const ret = new Text EXACTLY = 0,
ret.layoutConfig = layoutConfig().wrap() WRAP_CONTENT = 1,
for (let key in config) { AT_MOST = 2,
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
} }
export function image(config: IImage) { export interface LayoutConfig {
const ret = new Image widthSpec?: LayoutSpec
ret.layoutConfig = layoutConfig().wrap() heightSpec?: LayoutSpec
for (let key in config) { margin?: {
Reflect.set(ret, key, Reflect.get(config, key, config), ret) left?: number,
right?: number,
top?: number,
bottom?: number,
} }
return ret alignment?: Gravity
} //Only affective in VLayout or HLayout
weight?: number
export function stack(views: View[]) {
const ret = new Stack
ret.layoutConfig = layoutConfig().wrap()
for (let v of views) {
ret.addChild(v)
}
return ret
}
export function hlayout(views: View[]) {
const ret = new HLayout
ret.layoutConfig = layoutConfig().wrap()
for (let v of views) {
ret.addChild(v)
}
return ret
}
export function vlayout(views: View[]) {
const ret = new VLayout
ret.layoutConfig = layoutConfig().wrap()
for (let v of views) {
ret.addChild(v)
}
return ret
}
export function list(config: IList) {
const ret = new List
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
}
export function slider(config: ISlider) {
const ret = new Slider
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
} }
export class LayoutConfigImpl implements LayoutConfig, Modeling { export class LayoutConfigImpl implements LayoutConfig, Modeling {

View File

@ -13,34 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { IView, View, Property } from "./view" import { IView, View, Property } from "../ui/view"
import { Color } from "../util/color" import { layoutConfig } from "../util/layoutconfig"
import { Gravity } from "../util/gravity"
export interface IText extends IView {
text?: string
textColor?: Color
textSize?: number
maxLines?: number
textAlignment?: Gravity
}
export class Text extends View implements IText {
@Property
text?: string
@Property
textColor?: Color
@Property
textSize?: number
@Property
maxLines?: number
@Property
textAlignment?: Gravity
}
export enum ScaleType { export enum ScaleType {
ScaleToFill = 0, ScaleToFill = 0,
@ -66,3 +40,12 @@ export class Image extends View implements IImage {
@Property @Property
loadCallback?: (image: { width: number; height: number } | undefined) => void loadCallback?: (image: { width: number; height: number } | undefined) => void
} }
export function image(config: IImage) {
const ret = new Image
ret.layoutConfig = layoutConfig().wrap()
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
}

View File

@ -0,0 +1,22 @@
/*
* 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.
*/
export * from './layouts'
export * from './text'
export * from './image'
export * from './list'
export * from './slider'
export * from './scroller'
export * from './refreshable'

View File

@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { Group, Property, IView } from "./view"; import { Group, Property, IView, View } from "../ui/view";
import { Gravity } from "../util/gravity"; import { Gravity } from "../util/gravity";
import { layoutConfig } from "../util/layoutconfig";
export interface IStack extends IView { export interface IStack extends IView {
} }
@ -49,3 +50,30 @@ export interface IHLayout extends IView {
export class HLayout extends LinearLayout implements IHLayout { export class HLayout extends LinearLayout implements IHLayout {
} }
export function stack(views: View[]) {
const ret = new Stack
ret.layoutConfig = layoutConfig().wrap()
for (let v of views) {
ret.addChild(v)
}
return ret
}
export function hlayout(views: View[]) {
const ret = new HLayout
ret.layoutConfig = layoutConfig().wrap()
for (let v of views) {
ret.addChild(v)
}
return ret
}
export function vlayout(views: View[]) {
const ret = new VLayout
ret.layoutConfig = layoutConfig().wrap()
for (let v of views) {
ret.addChild(v)
}
return ret
}

View File

@ -14,18 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { View, Property, LayoutSpec, Superview, IView } from "./view"; import { View, Property, Superview, IView } from "../ui/view";
import { Stack } from "./layout"; import { Stack } from "./layouts";
import { layoutConfig } from "../util/layoutconfig";
export function listItem(item: View) {
return (new ListItem).also((it) => {
it.layoutConfig = {
widthSpec: LayoutSpec.WRAP_CONTENT,
heightSpec: LayoutSpec.WRAP_CONTENT,
}
it.addChild(item)
})
}
export class ListItem extends Stack { export class ListItem extends Stack {
/** /**
@ -88,3 +79,18 @@ export class List extends Superview implements IList {
}) })
} }
} }
export function list(config: IList) {
const ret = new List
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
}
export function listItem(item: View) {
return (new ListItem).also((it) => {
it.layoutConfig = layoutConfig().wrap()
it.addChild(item)
})
}

View File

@ -1,8 +1,8 @@
import { View, Property, Superview, IView } from "./view"; import { View, Property, Superview, IView } from "../ui/view";
import { List } from "./list"; import { List } from "./list";
import { Scroller } from "./scroller"; import { Scroller } from "./scroller";
import { BridgeContext } from "../runtime/global"; import { BridgeContext } from "../runtime/global";
import { layoutConfig } from "./declarative"; import { layoutConfig } from "../util/layoutconfig";
export interface IRefreshable extends IView { export interface IRefreshable extends IView {
content: View content: View

View File

@ -13,14 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { Superview, View, Property, IView, LayoutSpec } from './view' import { Superview, View, IView } from '../ui/view'
import { layoutConfig } from '../util/layoutconfig'
export function scroller(content: View) { export function scroller(content: View) {
return (new Scroller).also(v => { return (new Scroller).also(v => {
v.layoutConfig = { v.layoutConfig = layoutConfig().wrap()
widthSpec: LayoutSpec.WRAP_CONTENT,
heightSpec: LayoutSpec.WRAP_CONTENT,
}
v.content = content v.content = content
}) })
} }

View File

@ -1,15 +1,6 @@
import { Superview, View, LayoutSpec, Property, IView } from "./view"; import { Superview, View, Property, IView } from "../ui/view";
import { Stack } from "./layout"; import { Stack } from "./layouts";
import { layoutConfig } from "../util/layoutconfig";
export function slideItem(item: View) {
return (new SlideItem).also((it) => {
it.layoutConfig = {
widthSpec: LayoutSpec.AT_MOST,
heightSpec: LayoutSpec.AT_MOST,
}
it.addChild(item)
})
}
export class SlideItem extends Stack { export class SlideItem extends Stack {
/** /**
@ -70,3 +61,18 @@ export class Slider extends Superview implements ISlider {
}) })
} }
} }
export function slideItem(item: View) {
return (new SlideItem).also((it) => {
it.layoutConfig = layoutConfig().wrap()
it.addChild(item)
})
}
export function slider(config: ISlider) {
const ret = new Slider
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
}

View File

@ -0,0 +1,53 @@
/*
* 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.
*/
import { IView, View, Property } from "../ui/view"
import { Color } from "../util/color"
import { Gravity } from "../util/gravity"
import { layoutConfig } from "../util/layoutconfig"
export interface IText extends IView {
text?: string
textColor?: Color
textSize?: number
maxLines?: number
textAlignment?: Gravity
}
export class Text extends View implements IText {
@Property
text?: string
@Property
textColor?: Color
@Property
textSize?: number
@Property
maxLines?: number
@Property
textAlignment?: Gravity
}
export function text(config: IText) {
const ret = new Text
ret.layoutConfig = layoutConfig().wrap()
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
}