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 {
tv.setText(data[position - 2]);
tv.setText(data[position - 3]);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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", "__dev__");
tv.getContext().startActivity(intent);

View File

@ -40,7 +40,6 @@ import pub.doric.shader.ViewNode;
* @Description: pub.doric.shader.slider
* @Author: pengfei.zhou
* @CreateDate: 2019-11-19
* @UpdateDate: 2020-04-09
*/
@DoricPlugin(name = "Slider")
public class SliderNode extends SuperNode<RecyclerView> {
@ -51,6 +50,9 @@ public class SliderNode extends SuperNode<RecyclerView> {
private boolean loop = false;
private String renderPageFuncId;
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) {
super(doricContext);
@ -123,13 +125,29 @@ public class SliderNode extends SuperNode<RecyclerView> {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int 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;
}
@Override
public ViewNode getSubNodeById(String id) {
public ViewNode<?> getSubNodeById(String id) {
RecyclerView.LayoutManager manager = mView.getLayoutManager();
if (manager == null) {
return null;
@ -150,7 +168,7 @@ public class SliderNode extends SuperNode<RecyclerView> {
@Override
protected void blendSubNode(JSObject subProperties) {
String viewId = subProperties.getProperty("id").asString().value();
ViewNode node = getSubNodeById(viewId);
ViewNode<?> node = getSubNodeById(viewId);
if (node != null) {
node.blend(subProperties.getProperty("props").asObject());
} else {
@ -225,6 +243,11 @@ public class SliderNode extends SuperNode<RecyclerView> {
case "loop":
this.loop = prop.asBoolean().value();
break;
case "slideStyle":
if (prop.isString()) {
this.slideStyle = prop.asString().value();
}
break;
default:
super.blend(view, name, prop);
break;