add scrollview for android
This commit is contained in:
@@ -20,6 +20,7 @@ import android.text.TextUtils;
|
||||
import pub.doric.plugin.ShaderPlugin;
|
||||
import pub.doric.shader.HLayoutNode;
|
||||
import pub.doric.shader.ImageNode;
|
||||
import pub.doric.shader.ScrollerNode;
|
||||
import pub.doric.shader.list.ListItemNode;
|
||||
import pub.doric.shader.list.ListNode;
|
||||
import pub.doric.shader.RootNode;
|
||||
@@ -70,6 +71,7 @@ public class DoricRegistry {
|
||||
this.registerViewNode(HLayoutNode.class);
|
||||
this.registerViewNode(ListNode.class);
|
||||
this.registerViewNode(ListItemNode.class);
|
||||
this.registerViewNode(ScrollerNode.class);
|
||||
initRegistry(this);
|
||||
}
|
||||
|
||||
|
@@ -34,8 +34,6 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
private ArrayList<ViewNode> mChildNodes = new ArrayList<>();
|
||||
private ArrayList<String> mChildViewIds = new ArrayList<>();
|
||||
|
||||
protected boolean mReusable = false;
|
||||
|
||||
public GroupNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
@@ -80,8 +78,8 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
mView.removeView(oldNode.getDoricLayer());
|
||||
ViewNode newNode = ViewNode.create(getDoricContext(), type);
|
||||
newNode.setId(id);
|
||||
if (newNode instanceof GroupNode) {
|
||||
((GroupNode) newNode).mReusable = this.mReusable;
|
||||
if (newNode instanceof SuperNode) {
|
||||
((SuperNode) newNode).mReusable = this.mReusable;
|
||||
}
|
||||
newNode.init(this);
|
||||
newNode.blend(model.getProperty("props").asObject());
|
||||
@@ -126,8 +124,8 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
//Insert
|
||||
ViewNode newNode = ViewNode.create(getDoricContext(), type);
|
||||
newNode.setId(id);
|
||||
if (newNode instanceof GroupNode) {
|
||||
((GroupNode) newNode).mReusable = this.mReusable;
|
||||
if (newNode instanceof SuperNode) {
|
||||
((SuperNode) newNode).mReusable = this.mReusable;
|
||||
}
|
||||
newNode.init(this);
|
||||
newNode.blend(model.getProperty("props").asObject());
|
||||
|
101
Android/doric/src/main/java/pub/doric/shader/ScrollerNode.java
Normal file
101
Android/doric/src/main/java/pub/doric/shader/ScrollerNode.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package pub.doric.shader;
|
||||
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.widget.HVScrollView;
|
||||
|
||||
/**
|
||||
* @Description: pub.doric.shader
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-11-18
|
||||
*/
|
||||
@DoricPlugin(name = "Scroller")
|
||||
public class ScrollerNode extends SuperNode<HVScrollView> {
|
||||
private String mChildViewId;
|
||||
private ViewNode mChildNode;
|
||||
|
||||
public ScrollerNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewNode getSubNodeById(String id) {
|
||||
return id.equals(mChildNode.getId()) ? mChildNode : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blendSubNode(JSObject subProperties) {
|
||||
if (mChildNode != null) {
|
||||
mChildNode.blend(subProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HVScrollView build() {
|
||||
return new HVScrollView(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blend(HVScrollView view, String name, JSValue prop) {
|
||||
if ("content".equals(name)) {
|
||||
mChildViewId = prop.asString().value();
|
||||
} else {
|
||||
super.blend(view, name, prop);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blend(JSObject jsObject) {
|
||||
super.blend(jsObject);
|
||||
JSObject contentModel = getSubModel(mChildViewId);
|
||||
if (contentModel == null) {
|
||||
return;
|
||||
}
|
||||
String viewId = contentModel.getProperty("id").asString().value();
|
||||
String type = contentModel.getProperty("type").asString().value();
|
||||
JSObject props = contentModel.getProperty("props").asObject();
|
||||
if (mChildNode != null) {
|
||||
if (mChildNode.getId().equals(viewId)) {
|
||||
//skip
|
||||
} else {
|
||||
if (mReusable && type.equals(mChildNode.getType())) {
|
||||
mChildNode.setId(viewId);
|
||||
mChildNode.blend(props);
|
||||
} else {
|
||||
mView.removeAllViews();
|
||||
mChildNode = ViewNode.create(getDoricContext(), type);
|
||||
mChildNode.setId(viewId);
|
||||
mChildNode.init(this);
|
||||
mChildNode.blend(props);
|
||||
mView.addView(mChildNode.getDoricLayer());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mChildNode = ViewNode.create(getDoricContext(), type);
|
||||
mChildNode.setId(viewId);
|
||||
mChildNode.init(this);
|
||||
mChildNode.blend(props);
|
||||
mView.addView(mChildNode.getDoricLayer());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -35,6 +35,7 @@ import pub.doric.utils.DoricUtils;
|
||||
*/
|
||||
public abstract class SuperNode<V extends View> extends ViewNode<V> {
|
||||
private Map<String, JSObject> subNodes = new HashMap<>();
|
||||
protected boolean mReusable = false;
|
||||
|
||||
public SuperNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
|
@@ -37,7 +37,9 @@ public class TextNode extends ViewNode<TextView> {
|
||||
|
||||
@Override
|
||||
protected TextView build() {
|
||||
return new TextView(getContext());
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setGravity(Gravity.CENTER);
|
||||
return tv;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
2284
Android/doric/src/main/java/pub/doric/widget/HVScrollView.java
Normal file
2284
Android/doric/src/main/java/pub/doric/widget/HVScrollView.java
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user