Git Product home page Git Product logo

weex-module's Introduction

weex封装组件

weex官方文档

weex源码地址

使用如下:

1. 初始化


public class BaseApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        **
        * 初始化
        *
        * @param context    application的对象
        * @param flag           是否开启weex调试
        */
        ShuWeiWeexSdk.init(this,true);
    }
}


2. 添加weex页面


    //跳转到weex--activity
    WeexPagerActivity.start(this,"home/home.js");

    //添加weex--fragment
    WeexPagerFragment.newInstance("home/home.js");

3. 添加module例如下

public class ProgressHud extends BaseWXModule {

    //运行在主线程
    @JSMethod(uiThread = true)
    public void show(JSCallback jsCallback) {

        //检测jscallback是否为null,为null直接回复fail
        if (!checkContext(jsCallback)) {
            return;
        }

        if (mLoadingDialog == null) {
            mLoadingDialog = new LoadingDialog(mWXSDKInstance.getContext(), 2);
            mLoadingDialog.setDissmissByOutside(false);
            mLoadingDialog.setDissmissByBack(true);
        }
        mLoadingDialog.show();

        //传递成功的消息,只包含result一个字段
        jsCallBack(jsCallback, MSG_SUCCESS);

        //如果需要传递多个字段建议如下:
        // jsCallBack(jsCallback,new TreeMap<String, String>());

    }
}

4. 添加Component

更多建议参考weex文档:android使用weex扩展组件


public class RichText extends WXComponent<TextView> {

    public RichText(WXSDKInstance instance, WXDomObject dom, WXVContainer parent) {
        super(instance, dom, parent);
    }

    @Override
    protected TextView initComponentHostView(@NonNull Context context) {
        TextView textView = new TextView(context);
        textView.setTextSize(20);
        textView.setTextColor(Color.BLACK);
        return textView;
    }

    @WXComponentProp(name = "tel")
    public void setTel(String telNumber) {
        getHostView().setText("tel: " + telNumber);
    }
}

5. 目前扩展的组件有:

Module:

  • _hud 加载动画
  • _photoBrowser 图片浏览器

Component

  • web 使用tencent x5 内核的webView

weex-module's People

Contributors

alguojian avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.