android: slider add property slideStyle

This commit is contained in:
pengfei.zhou 2022-07-15 17:19:11 +08:00 committed by osborn
parent b4eca3be2b
commit fd5994e270
2 changed files with 28 additions and 5 deletions

View File

@ -134,12 +134,12 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
}else { }else {
tv.setText(data[position - 2]); tv.setText(data[position - 3]);
tv.setOnClickListener(new View.OnClickListener() { tv.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(tv.getContext(), DoricDebugTimingActivity.class); Intent intent = new Intent(tv.getContext(), DoricDebugTimingActivity.class);
intent.putExtra("source", "assets://src/" + data[position - 2]); intent.putExtra("source", "assets://src/" + data[position - 3]);
//intent.putExtra("alias", data[position - 1].replace(".js", "")); //intent.putExtra("alias", data[position - 1].replace(".js", ""));
intent.putExtra("alias", "__dev__"); intent.putExtra("alias", "__dev__");
tv.getContext().startActivity(intent); tv.getContext().startActivity(intent);

View File

@ -40,7 +40,6 @@ import pub.doric.shader.ViewNode;
* @Description: pub.doric.shader.slider * @Description: pub.doric.shader.slider
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-11-19 * @CreateDate: 2019-11-19
* @UpdateDate: 2020-04-09
*/ */
@DoricPlugin(name = "Slider") @DoricPlugin(name = "Slider")
public class SliderNode extends SuperNode<RecyclerView> { public class SliderNode extends SuperNode<RecyclerView> {
@ -51,6 +50,9 @@ public class SliderNode extends SuperNode<RecyclerView> {
private boolean loop = false; private boolean loop = false;
private String renderPageFuncId; private String renderPageFuncId;
private boolean scrollable = true; private boolean scrollable = true;
private String slideStyle = null;
private static final float MIN_SCALE = 0.5f;
private static final float MAX_SCALE = 1;
public SliderNode(DoricContext doricContext) { public SliderNode(DoricContext doricContext) {
super(doricContext); super(doricContext);
@ -123,13 +125,29 @@ public class SliderNode extends SuperNode<RecyclerView> {
@Override @Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy); super.onScrolled(recyclerView, dx, dy);
if ("zoomOut".equals(slideStyle)) {
final int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
if (child.getWidth() == 0) {
return;
}
float centerX = (child.getLeft() + child.getRight()) / 2.f;
float percent = 1 - Math.abs(recyclerView.getWidth() / 2f - centerX) / recyclerView.getWidth() / 2f;
float scaleFactor = MIN_SCALE + Math.abs(percent) * (MAX_SCALE - MIN_SCALE);
child.setLayoutParams(lp);
child.setScaleY(scaleFactor);
child.setScaleX(scaleFactor);
}
}
} }
}); });
return recyclerView; return recyclerView;
} }
@Override @Override
public ViewNode getSubNodeById(String id) { public ViewNode<?> getSubNodeById(String id) {
RecyclerView.LayoutManager manager = mView.getLayoutManager(); RecyclerView.LayoutManager manager = mView.getLayoutManager();
if (manager == null) { if (manager == null) {
return null; return null;
@ -150,7 +168,7 @@ public class SliderNode extends SuperNode<RecyclerView> {
@Override @Override
protected void blendSubNode(JSObject subProperties) { protected void blendSubNode(JSObject subProperties) {
String viewId = subProperties.getProperty("id").asString().value(); String viewId = subProperties.getProperty("id").asString().value();
ViewNode node = getSubNodeById(viewId); ViewNode<?> node = getSubNodeById(viewId);
if (node != null) { if (node != null) {
node.blend(subProperties.getProperty("props").asObject()); node.blend(subProperties.getProperty("props").asObject());
} else { } else {
@ -225,6 +243,11 @@ public class SliderNode extends SuperNode<RecyclerView> {
case "loop": case "loop":
this.loop = prop.asBoolean().value(); this.loop = prop.asBoolean().value();
break; break;
case "slideStyle":
if (prop.isString()) {
this.slideStyle = prop.asString().value();
}
break;
default: default:
super.blend(view, name, prop); super.blend(view, name, prop);
break; break;