Merge branch 'feature/dev' into 'master'
Feature/dev See merge request !31
This commit is contained in:
commit
301e521f94
@ -34,6 +34,7 @@ public class AsyncCall {
|
||||
try {
|
||||
asyncResult.setResult(callable.call());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
asyncResult.setError(e);
|
||||
}
|
||||
} else {
|
||||
@ -43,6 +44,7 @@ public class AsyncCall {
|
||||
try {
|
||||
asyncResult.setResult(callable.call());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
asyncResult.setError(e);
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import pub.doric.extension.bridge.DoricMethod;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.extension.bridge.DoricPromise;
|
||||
import pub.doric.navbar.IDoricNavBar;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
import pub.doric.utils.ThreadMode;
|
||||
|
||||
/**
|
||||
@ -62,7 +61,7 @@ public class NavBarPlugin extends DoricJavaPlugin {
|
||||
JSObject jsObject = jsDecoder.decode().asObject();
|
||||
boolean hidden = jsObject.getProperty("hidden").asBoolean().value();
|
||||
navBar.setHidden(hidden);
|
||||
View v = getDoricContext().getRootNode().getDoricLayer();
|
||||
View v = getDoricContext().getRootNode().getNodeView();
|
||||
ViewGroup.LayoutParams params = v.getLayoutParams();
|
||||
if (params instanceof ViewGroup.MarginLayoutParams) {
|
||||
((ViewGroup.MarginLayoutParams) params).topMargin =
|
||||
|
@ -85,7 +85,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
|
||||
mContentNode.setId(viewId);
|
||||
mContentNode.init(this);
|
||||
mContentNode.blend(props);
|
||||
mView.addView(mContentNode.getDoricLayer());
|
||||
mView.addView(mContentNode.getNodeView());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -93,7 +93,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
|
||||
mContentNode.setId(viewId);
|
||||
mContentNode.init(this);
|
||||
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.init(this);
|
||||
mHeaderNode.blend(props);
|
||||
mView.getRefreshView().setContent(mHeaderNode.getDoricLayer());
|
||||
mView.getRefreshView().setContent(mHeaderNode.getNodeView());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -125,7 +125,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
|
||||
mHeaderNode.setId(viewId);
|
||||
mHeaderNode.init(this);
|
||||
mHeaderNode.blend(props);
|
||||
mView.getRefreshView().setContent(mHeaderNode.getDoricLayer());
|
||||
mView.getRefreshView().setContent(mHeaderNode.getNodeView());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,13 +75,13 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
} else {
|
||||
//Replace this view
|
||||
mChildNodes.remove(idx);
|
||||
mView.removeView(oldNode.getDoricLayer());
|
||||
mView.removeView(oldNode.getNodeView());
|
||||
ViewNode newNode = ViewNode.create(getDoricContext(), type);
|
||||
newNode.setId(id);
|
||||
newNode.init(this);
|
||||
newNode.blend(model.getProperty("props").asObject());
|
||||
mChildNodes.add(idx, newNode);
|
||||
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams());
|
||||
mView.addView(newNode.getNodeView(), idx, newNode.getLayoutParams());
|
||||
}
|
||||
} else {
|
||||
//Find in remain nodes
|
||||
@ -101,10 +101,10 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
mChildNodes.set(idx, reused);
|
||||
mChildNodes.set(position, abandoned);
|
||||
//View swap index
|
||||
mView.removeView(reused.getDoricLayer());
|
||||
mView.addView(reused.getDoricLayer(), idx);
|
||||
mView.removeView(abandoned.getDoricLayer());
|
||||
mView.addView(abandoned.getDoricLayer(), position);
|
||||
mView.removeView(reused.getNodeView());
|
||||
mView.addView(reused.getNodeView(), idx);
|
||||
mView.removeView(abandoned.getNodeView());
|
||||
mView.addView(abandoned.getNodeView(), position);
|
||||
} else {
|
||||
//Not found,insert
|
||||
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());
|
||||
|
||||
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.blend(model.getProperty("props").asObject());
|
||||
mChildNodes.add(newNode);
|
||||
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams());
|
||||
mView.addView(newNode.getNodeView(), idx, newNode.getLayoutParams());
|
||||
}
|
||||
}
|
||||
int size = mChildNodes.size();
|
||||
for (int idx = mChildViewIds.size(); idx < size; idx++) {
|
||||
ViewNode viewNode = mChildNodes.remove(mChildViewIds.size());
|
||||
mView.removeView(viewNode.getDoricLayer());
|
||||
mView.removeView(viewNode.getNodeView());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class RootNode extends StackNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDoricLayer() {
|
||||
public View getNodeView() {
|
||||
return mView;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class ScrollerNode extends SuperNode<HVScrollView> {
|
||||
mChildNode.setId(viewId);
|
||||
mChildNode.init(this);
|
||||
mChildNode.blend(props);
|
||||
mView.addView(mChildNode.getDoricLayer());
|
||||
mView.addView(mChildNode.getNodeView());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -94,7 +94,7 @@ public class ScrollerNode extends SuperNode<HVScrollView> {
|
||||
mChildNode.setId(viewId);
|
||||
mChildNode.init(this);
|
||||
mChildNode.blend(props);
|
||||
mView.addView(mChildNode.getDoricLayer());
|
||||
mView.addView(mChildNode.getNodeView());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricRegistry;
|
||||
import pub.doric.async.AsyncResult;
|
||||
@ -60,11 +62,8 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
this.mSuperNode = superNode;
|
||||
this.mLayoutParams = superNode.generateDefaultLayoutParams();
|
||||
this.doricLayer = new DoricLayer(getContext());
|
||||
this.doricLayer.setLayoutParams(mLayoutParams);
|
||||
this.mView = build();
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mLayoutParams.width, mLayoutParams.height);
|
||||
doricLayer.addView(mView, params);
|
||||
this.mView.setLayoutParams(mLayoutParams);
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
@ -75,8 +74,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
return mType;
|
||||
}
|
||||
|
||||
public View getDoricLayer() {
|
||||
return doricLayer;
|
||||
public View getNodeView() {
|
||||
if (doricLayer != null) {
|
||||
return doricLayer;
|
||||
} else {
|
||||
return mView;
|
||||
}
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
@ -91,22 +94,24 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
blend(mView, prop, jsObject.getProperty(prop));
|
||||
}
|
||||
}
|
||||
ViewGroup.LayoutParams params = mView.getLayoutParams();
|
||||
if (params != null) {
|
||||
params.width = mLayoutParams.width;
|
||||
params.height = mLayoutParams.height;
|
||||
} else {
|
||||
params = mLayoutParams;
|
||||
}
|
||||
if (mLayoutParams instanceof LinearLayout.LayoutParams && ((LinearLayout.LayoutParams) mLayoutParams).weight > 0) {
|
||||
if (mSuperNode instanceof VLayoutNode) {
|
||||
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
} else if (mSuperNode instanceof HLayoutNode) {
|
||||
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
if (doricLayer != null) {
|
||||
ViewGroup.LayoutParams params = mView.getLayoutParams();
|
||||
if (params != null) {
|
||||
params.width = mLayoutParams.width;
|
||||
params.height = mLayoutParams.height;
|
||||
} else {
|
||||
params = mLayoutParams;
|
||||
}
|
||||
if (mLayoutParams instanceof LinearLayout.LayoutParams && ((LinearLayout.LayoutParams) mLayoutParams).weight > 0) {
|
||||
if (mSuperNode instanceof VLayoutNode) {
|
||||
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
} else if (mSuperNode instanceof HLayoutNode) {
|
||||
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mView.setLayoutParams(params);
|
||||
mView.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
protected void blend(T view, String name, JSValue prop) {
|
||||
@ -139,41 +144,36 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
setLayoutConfig(prop.asObject());
|
||||
break;
|
||||
case "border":
|
||||
if (prop.isObject() && doricLayer != null) {
|
||||
doricLayer.setBorder(DoricUtils.dp2px(prop.asObject().getProperty("width").asNumber().toFloat()),
|
||||
if (prop.isObject()) {
|
||||
requireDoricLayer().setBorder(DoricUtils.dp2px(prop.asObject().getProperty("width").asNumber().toFloat()),
|
||||
prop.asObject().getProperty("color").asNumber().toInt());
|
||||
}
|
||||
break;
|
||||
case "corners":
|
||||
if (doricLayer != null) {
|
||||
if (prop.isNumber()) {
|
||||
doricLayer.setCornerRadius(DoricUtils.dp2px(prop.asNumber().toFloat()));
|
||||
} else if (prop.isObject()) {
|
||||
JSValue lt = prop.asObject().getProperty("leftTop");
|
||||
JSValue rt = prop.asObject().getProperty("rightTop");
|
||||
JSValue rb = prop.asObject().getProperty("rightBottom");
|
||||
JSValue lb = prop.asObject().getProperty("leftBottom");
|
||||
doricLayer.setCornerRadius(
|
||||
DoricUtils.dp2px(lt.isNumber() ? lt.asNumber().toFloat() : 0),
|
||||
DoricUtils.dp2px(rt.isNumber() ? rt.asNumber().toFloat() : 0),
|
||||
DoricUtils.dp2px(rb.isNumber() ? rb.asNumber().toFloat() : 0),
|
||||
DoricUtils.dp2px(lb.isNumber() ? lb.asNumber().toFloat() : 0)
|
||||
);
|
||||
}
|
||||
if (prop.isNumber()) {
|
||||
requireDoricLayer().setCornerRadius(DoricUtils.dp2px(prop.asNumber().toFloat()));
|
||||
} else if (prop.isObject()) {
|
||||
JSValue lt = prop.asObject().getProperty("leftTop");
|
||||
JSValue rt = prop.asObject().getProperty("rightTop");
|
||||
JSValue rb = prop.asObject().getProperty("rightBottom");
|
||||
JSValue lb = prop.asObject().getProperty("leftBottom");
|
||||
requireDoricLayer().setCornerRadius(
|
||||
DoricUtils.dp2px(lt.isNumber() ? lt.asNumber().toFloat() : 0),
|
||||
DoricUtils.dp2px(rt.isNumber() ? rt.asNumber().toFloat() : 0),
|
||||
DoricUtils.dp2px(rb.isNumber() ? rb.asNumber().toFloat() : 0),
|
||||
DoricUtils.dp2px(lb.isNumber() ? lb.asNumber().toFloat() : 0)
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
case "shadow":
|
||||
if (doricLayer != null) {
|
||||
if (prop.isObject()) {
|
||||
doricLayer.setShadow(
|
||||
prop.asObject().getProperty("color").asNumber().toInt(),
|
||||
(int) (prop.asObject().getProperty("opacity").asNumber().toFloat() * 255),
|
||||
DoricUtils.dp2px(prop.asObject().getProperty("radius").asNumber().toFloat()),
|
||||
DoricUtils.dp2px(prop.asObject().getProperty("offsetX").asNumber().toFloat()),
|
||||
DoricUtils.dp2px(prop.asObject().getProperty("offsetY").asNumber().toFloat())
|
||||
);
|
||||
}
|
||||
if (prop.isObject()) {
|
||||
requireDoricLayer().setShadow(
|
||||
prop.asObject().getProperty("color").asNumber().toInt(),
|
||||
(int) (prop.asObject().getProperty("opacity").asNumber().toFloat() * 255),
|
||||
DoricUtils.dp2px(prop.asObject().getProperty("radius").asNumber().toFloat()),
|
||||
DoricUtils.dp2px(prop.asObject().getProperty("offsetX").asNumber().toFloat()),
|
||||
DoricUtils.dp2px(prop.asObject().getProperty("offsetY").asNumber().toFloat())
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -181,6 +181,26 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
}
|
||||
|
||||
@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() {
|
||||
LinkedList<String> ids = new LinkedList<>();
|
||||
ViewNode viewNode = this;
|
||||
@ -250,12 +270,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
|
||||
@DoricMethod
|
||||
public int getWidth() {
|
||||
return mView.getWidth();
|
||||
return getNodeView().getWidth();
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public int getHeight() {
|
||||
return mView.getHeight();
|
||||
return getNodeView().getHeight();
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
@ -267,11 +287,11 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
while (rotation < -1) {
|
||||
rotation = rotation + 1;
|
||||
}
|
||||
doricLayer.setRotation(rotation * 360);
|
||||
getNodeView().setRotation(rotation * 360);
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public float getRotation() {
|
||||
return doricLayer.getRotation() / 360;
|
||||
return getNodeView().getRotation() / 360;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
|
||||
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ListItemNode node = (ListItemNode) ViewNode.create(listNode.getDoricContext(), "ListItem");
|
||||
node.init(listNode);
|
||||
return new DoricViewHolder(node, node.getDoricLayer());
|
||||
return new DoricViewHolder(node, node.getNodeView());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ public class ListItemNode extends StackNode {
|
||||
@Override
|
||||
public void blend(JSObject jsObject) {
|
||||
super.blend(jsObject);
|
||||
getDoricLayer().getLayoutParams().width = getLayoutParams().width;
|
||||
getDoricLayer().getLayoutParams().height = getLayoutParams().height;
|
||||
getNodeView().getLayoutParams().width = getLayoutParams().width;
|
||||
getNodeView().getLayoutParams().height = getLayoutParams().height;
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
|
||||
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
SlideItemNode node = (SlideItemNode) ViewNode.create(sliderNode.getDoricContext(), "SlideItem");
|
||||
node.init(sliderNode);
|
||||
return new DoricViewHolder(node, node.getDoricLayer());
|
||||
return new DoricViewHolder(node, node.getNodeView());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ public class SlideItemNode extends StackNode {
|
||||
@Override
|
||||
public void blend(JSObject jsObject) {
|
||||
super.blend(jsObject);
|
||||
getDoricLayer().getLayoutParams().width = getLayoutParams().width;
|
||||
getDoricLayer().getLayoutParams().height = getLayoutParams().height;
|
||||
getNodeView().getLayoutParams().width = getLayoutParams().width;
|
||||
getNodeView().getLayoutParams().height = getLayoutParams().height;
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ class RefreshableDemo extends Panel {
|
||||
}),
|
||||
]).apply({
|
||||
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
|
||||
gravity: gravity().center(),
|
||||
gravity: gravity().centerX(),
|
||||
space: 10,
|
||||
} as IVLayout))
|
||||
}).apply({
|
||||
|
@ -38,7 +38,7 @@ export function boxStr(str: string, idx = 0) {
|
||||
|
||||
export function title(str: string) {
|
||||
return text({
|
||||
text: "Network Demo",
|
||||
text: str,
|
||||
layoutConfig: layoutConfig().w(LayoutSpec.AT_MOST),
|
||||
textSize: 30,
|
||||
textColor: Color.WHITE,
|
||||
|
@ -49,8 +49,8 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
||||
|
||||
- (void)blend:(NSDictionary *)props {
|
||||
[super blend:props];
|
||||
[self blendHeader];
|
||||
[self blendContent];
|
||||
[self blendHeader];
|
||||
}
|
||||
|
||||
- (void)blendContent {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#import "DoricSwipeRefreshLayout.h"
|
||||
#import "UIView+Doric.h"
|
||||
#import "DoricLayouts.h"
|
||||
#import "Doric.h"
|
||||
|
||||
@interface DoricSwipeRefreshLayout () <UIScrollViewDelegate>
|
||||
|
||||
@ -53,9 +54,16 @@ - (BOOL)requestFromSubview:(UIView *)subview {
|
||||
}
|
||||
|
||||
- (void)layoutSelf:(CGSize)targetSize {
|
||||
[super layoutSelf:targetSize];
|
||||
self.headerView.bottom = 0;
|
||||
self.headerView.centerX = self.centerX;
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
[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;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#import "DoricExtensions.h"
|
||||
#import "DoricListItemNode.h"
|
||||
#import "DoricLayouts.h"
|
||||
#import "DoricRefreshableNode.h"
|
||||
|
||||
@interface DoricTableViewCell : UITableViewCell
|
||||
@property(nonatomic, strong) DoricListItemNode *doricListItemNode;
|
||||
@ -73,6 +74,13 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initWithSuperNode:(DoricSuperNode *)superNode {
|
||||
[super initWithSuperNode:superNode];
|
||||
if ([superNode isKindOfClass:[DoricRefreshableNode class]]) {
|
||||
self.view.bounces = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (UITableView *)build {
|
||||
return [[DoricTableView new] also:^(UITableView *it) {
|
||||
it.dataSource = self;
|
||||
|
@ -21,6 +21,7 @@
|
||||
//
|
||||
#import "DoricScrollerNode.h"
|
||||
#import "DoricExtensions.h"
|
||||
#import "DoricRefreshableNode.h"
|
||||
|
||||
@implementation DoricScrollView
|
||||
|
||||
@ -56,6 +57,13 @@ - (DoricScrollView *)build {
|
||||
return [DoricScrollView new];
|
||||
}
|
||||
|
||||
- (void)initWithSuperNode:(DoricSuperNode *)superNode {
|
||||
[super initWithSuperNode:superNode];
|
||||
if ([superNode isKindOfClass:[DoricRefreshableNode class]]) {
|
||||
self.view.bounces = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)blend:(NSDictionary *)props {
|
||||
[super blend:props];
|
||||
NSDictionary *childModel = [self subModelOf:self.childViewId];
|
||||
|
@ -13,20 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* 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/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"
|
||||
|
20
js-framework/src/native/index.native.ts
Normal file
20
js-framework/src/native/index.native.ts
Normal 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'
|
62
js-framework/src/native/modal.ts
Normal file
62
js-framework/src/native/modal.ts
Normal 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>
|
||||
},
|
||||
}
|
||||
}
|
47
js-framework/src/native/navbar.ts
Normal file
47
js-framework/src/native/navbar.ts
Normal 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(),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
29
js-framework/src/native/navigator.ts
Normal file
29
js-framework/src/native/navigator.ts
Normal 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 })
|
||||
},
|
||||
}
|
||||
}
|
@ -13,54 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { Gravity } from "./gravity";
|
||||
import { Panel } from "../ui/panel";
|
||||
import { Color } from "./color";
|
||||
import { BridgeContext } from "../runtime/global"
|
||||
|
||||
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 {
|
||||
// `url` is the server URL that will be used for the request
|
||||
url?: string,
|
||||
@ -103,6 +57,7 @@ function transformRequest(request: IRequest) {
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
export function network(context: BridgeContext) {
|
||||
return {
|
||||
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(),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
33
js-framework/src/native/storage.ts
Normal file
33
js-framework/src/native/storage.ts
Normal 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 })
|
||||
},
|
||||
}
|
||||
}
|
18
js-framework/src/pattern/index.pattern.ts
Normal file
18
js-framework/src/pattern/index.pattern.ts
Normal 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'
|
@ -13,8 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Group } from "../ui/view";
|
||||
import { Panel } from "../ui/panel";
|
||||
import { Group } from "../ui/view"
|
||||
import { Panel } from "../ui/panel"
|
||||
|
||||
export abstract class ViewHolder<M>{
|
||||
abstract build(root: Group): void
|
@ -36,7 +36,7 @@ import "reflect-metadata"
|
||||
* Reflect.apply(function(__module){
|
||||
* (function(module,exports,require){
|
||||
* //module content
|
||||
* })(__module,__module.exports,hego.__require__);
|
||||
* })(__module,__module.exports,doric.__require__);
|
||||
* return __module.exports
|
||||
* },this,[{exports:{}}])
|
||||
* ])
|
||||
|
17
js-framework/src/ui/index.ui.ts
Normal file
17
js-framework/src/ui/index.ui.ts
Normal 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'
|
@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import './../runtime/global'
|
||||
import { View, Group } from "./view";
|
||||
import { loge, log } from '../util/log';
|
||||
import { Model } from '../util/types';
|
||||
import { Root } from './layout';
|
||||
import '../runtime/global'
|
||||
import { View, Group } from "./view"
|
||||
import { loge } from '../util/log'
|
||||
import { Model } from '../util/types'
|
||||
import { Root } from '../widget/layouts'
|
||||
|
||||
|
||||
export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
@ -50,6 +50,14 @@ export abstract class Panel {
|
||||
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() {
|
||||
return this.__root__
|
||||
}
|
||||
|
@ -16,29 +16,9 @@
|
||||
import { Color, GradientColor } from "../util/color"
|
||||
import { Modeling, Model, obj2Model } from "../util/types";
|
||||
import { uniqueId } from "../util/uniqueId";
|
||||
import { Gravity } from "../util/gravity";
|
||||
import { loge } from "../util/log";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
|
||||
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
|
||||
}
|
||||
import { LayoutConfig } from '../util/layoutconfig'
|
||||
|
||||
export function Property(target: Object, propKey: string) {
|
||||
Reflect.defineMetadata(propKey, true, target)
|
||||
|
21
js-framework/src/util/index.util.ts
Normal file
21
js-framework/src/util/index.util.ts
Normal 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'
|
@ -13,73 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { View, LayoutSpec, LayoutConfig } from './view'
|
||||
import { Stack, HLayout, VLayout } from './layout'
|
||||
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'
|
||||
import { Gravity } from "./gravity";
|
||||
import { Modeling } from "./types";
|
||||
|
||||
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
|
||||
export enum LayoutSpec {
|
||||
EXACTLY = 0,
|
||||
WRAP_CONTENT = 1,
|
||||
AT_MOST = 2,
|
||||
}
|
||||
|
||||
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)
|
||||
export interface LayoutConfig {
|
||||
widthSpec?: LayoutSpec
|
||||
heightSpec?: LayoutSpec
|
||||
margin?: {
|
||||
left?: number,
|
||||
right?: number,
|
||||
top?: number,
|
||||
bottom?: number,
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
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
|
||||
alignment?: Gravity
|
||||
//Only affective in VLayout or HLayout
|
||||
weight?: number
|
||||
}
|
||||
|
||||
export class LayoutConfigImpl implements LayoutConfig, Modeling {
|
@ -13,34 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { IView, View, Property } from "./view"
|
||||
import { Color } from "../util/color"
|
||||
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
|
||||
}
|
||||
import { IView, View, Property } from "../ui/view"
|
||||
import { layoutConfig } from "../util/layoutconfig"
|
||||
|
||||
export enum ScaleType {
|
||||
ScaleToFill = 0,
|
||||
@ -66,3 +40,12 @@ export class Image extends View implements IImage {
|
||||
@Property
|
||||
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
|
||||
}
|
22
js-framework/src/widget/index.widget.ts
Normal file
22
js-framework/src/widget/index.widget.ts
Normal 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'
|
@ -13,8 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Group, Property, IView } from "./view";
|
||||
import { Group, Property, IView, View } from "../ui/view";
|
||||
import { Gravity } from "../util/gravity";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
|
||||
export interface IStack extends IView {
|
||||
}
|
||||
@ -49,3 +50,30 @@ export interface IHLayout extends IView {
|
||||
|
||||
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
|
||||
}
|
@ -14,18 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { View, Property, LayoutSpec, Superview, IView } from "./view";
|
||||
import { Stack } from "./layout";
|
||||
|
||||
export function listItem(item: View) {
|
||||
return (new ListItem).also((it) => {
|
||||
it.layoutConfig = {
|
||||
widthSpec: LayoutSpec.WRAP_CONTENT,
|
||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||
}
|
||||
it.addChild(item)
|
||||
})
|
||||
}
|
||||
import { View, Property, Superview, IView } from "../ui/view";
|
||||
import { Stack } from "./layouts";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import { View, Property, Superview, IView } from "./view";
|
||||
import { View, Property, Superview, IView } from "../ui/view";
|
||||
import { List } from "./list";
|
||||
import { Scroller } from "./scroller";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { layoutConfig } from "./declarative";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
|
||||
export interface IRefreshable extends IView {
|
||||
content: View
|
@ -13,14 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* 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) {
|
||||
return (new Scroller).also(v => {
|
||||
v.layoutConfig = {
|
||||
widthSpec: LayoutSpec.WRAP_CONTENT,
|
||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||
}
|
||||
v.layoutConfig = layoutConfig().wrap()
|
||||
v.content = content
|
||||
})
|
||||
}
|
@ -1,15 +1,6 @@
|
||||
import { Superview, View, LayoutSpec, Property, IView } from "./view";
|
||||
import { Stack } from "./layout";
|
||||
|
||||
export function slideItem(item: View) {
|
||||
return (new SlideItem).also((it) => {
|
||||
it.layoutConfig = {
|
||||
widthSpec: LayoutSpec.AT_MOST,
|
||||
heightSpec: LayoutSpec.AT_MOST,
|
||||
}
|
||||
it.addChild(item)
|
||||
})
|
||||
}
|
||||
import { Superview, View, Property, IView } from "../ui/view";
|
||||
import { Stack } from "./layouts";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
|
||||
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
|
||||
}
|
53
js-framework/src/widget/text.ts
Normal file
53
js-framework/src/widget/text.ts
Normal 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
|
||||
}
|
Reference in New Issue
Block a user