Android组件Component如何传值给Weex vue

需求:做一个可以垂直滚动的TextView组件提供给Weex,还要能够点击把值也传给Weex。
android中组件的点击事件只要在组件中实现就可以点击了。

TextVirticls 组件代码

package com.weex.app;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.common.Constants;
import com.taobao.weex.ui.action.BasicComponentData;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.component.WXVContainer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by txb on 2019/9/10.
 * Weex自动上下滚动的TextView
 */
public class TextVirticls extends WXComponent {

  private VerticalScrollTextView mVerticalScrollTextView;
  private List mList;
  private Context mContext;
  Map params = new HashMap<>();
  public static final String INDEX = "index";

  public TextVirticls(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) {
    super(instance, parent, basicComponentData);
    Log.v("txb", "ScrollTextView构造方法调用了");
  }

  @Override
  protected VerticalScrollTextView initComponentHostView(@NonNull Context context) {
    mContext=context;
    mVerticalScrollTextView = new VerticalScrollTextView(context);
    appleStyleAfterCreated();
    Log.v("txb", "VerticalScrollTextView........");
    return mVerticalScrollTextView;
  }

  private void appleStyleAfterCreated() {
//    WXEvent event = getEvents();
    final String ref = getRef();

    mVerticalScrollTextView.setTextStillTime(3000);//设置停留时长间隔
    mVerticalScrollTextView.setAnimTime(300);//设置进入和退出的时间间隔
    mVerticalScrollTextView.startAutoScroll();
    mVerticalScrollTextView.setOnItemClickListener(new VerticalTextview.OnItemClickListener() {
      @Override
      public void onItemClick(int position) {
        //通过fireEvent方法把值发送给weex
        params.put(INDEX, mList.get(position));
        WXSDKManager.getInstance().fireEvent(getInstanceId(), ref,
          Constants.Event.CHANGE, params);
      }
    });
  }

  @JSMethod
  public void setListText(List list) {
    mList=list;
    Log.v("txb", "setListText........");
    mVerticalScrollTextView.setTextList(list);
  }


  //用属性的方式传值
  /*  @WXComponentProp(name = "tel")
  public void setTextList(List list) {
    Log.v("txb", "WXComponentProp........");
    mVerticalScrollTextView.setList(list);
  }*/


}

Vue接收







最后还要记得在WXApplication中注册

WXSDKEngine.registerComponent("textviewv", TextVirticls.class);

你可能感兴趣的:(Android组件Component如何传值给Weex vue)