Github user cxfeng1 commented on a diff in the pull request:

    https://github.com/apache/incubator-weex-site/pull/15#discussion_r162041034
  
    --- Diff: source/guide/extend-android.md ---
    @@ -5,70 +5,63 @@ group: Extend
     order: 6.3
     version: 2.1
     ---
    +# Android extend
    +  Weex provides an easy way to extend, as module-extend、component-extend 
and adapter-extend.
     
     ## Module extend
     
    -weex sdk support Module extend, Weex SDK provides only rendering 
capabilities, rather than have other capabilities, such as network, picture, 
and URL redirection. If you want the these features, you need to implement it.
    -
    -For example: If you want to implement an address jumping function, you can 
achieve a Module Follow the steps below.
    -
    -### Step to customize a module
    -
    -- Customize module must extend WXModule
    -- @WXModuleAnno annotation must be added, as it is the only the way to 
recognized by Weex
    -- The access levels of mehtod must be **public**
    -- The module class also can not be an inner class
    -- Customize can not be obfuscated by tools like ProGuard
    -- Module methods will be invoked in UI thread, do not put time consuming 
operation there
    -- Weex params can be int, double, float, String, Map, List
    +1. Customize module class must extends WXModule. 
    +2. Extended method must add `@JSMethod (uiThread = false or true)` 
annotation, and you can set the method whether it is running on UI thread or 
not.
    +3. The access levels of mehtod must be `public`.
    +4. Do not be obfuscated by tools like ProGuard.
    +5. Extended method suppport the data type of int, double, float, String, 
Map, List as its param.
    +7. Register the module: `WXSDKEngine.registerModule("myModule", 
MyModule.class);`or else may report an error: `ReportException :undefined:9: 
TypeError: Object #<Object> has no method 'xxx'` .
     
     Refer to the following example:
     
     ```java
    -public class WXEventModule extends WXModule{
    -
    -  private static final String 
WEEX_CATEGORY="com.taobao.android.intent.category.WEEX";
    +public class MyModule extends WXModule{
     
    -  @WXModuleAnno
    -    public void openURL(String url){
    -      //implement your module logic here
    -    }
    -}
    -```
    -
    -#### Support synchronous/asynchronous callback
    -
    -You can add  `@JSMethod (uiThread = false or true)` annotation to choose 
the callback mode of moudle. See the follow example.
    -
    -```java
    -  // as sync-callback mode
    -@JSMethod (uiThread = false)
    -public void testSyncCall(){
    -    WXLogUtils.d("WXComponentSyncTest : Thread.currentThread().getName());
    -}
    +  //run ui thread 
    +  @JSMethod (uiThread = true)
    +  public void printLog(String msg) {
    +    
Toast.makeText(mWXSDKInstance.getContext(),msg,Toast.LENGTH_SHORT).show();
    +  }
     
    -// as async-callback mode
    -@JSMethod (uiThread = true)
    -public void testAsyncCall(){
    -    WXLogUtils.e("WXComponentASynTest : Thread.currentThread().getName() );
    +  //run JS thread 
    +  @JSMethod (uiThread = false)
    +  public void fireEventSyncCall(){
    +   //implement your module logic here
    +  }
     }
     ```
    -
    -### Register the moulde
    +Register the module
     
     ```java
    -WXSDKEngine.registerModule("event", WXEventModule.class);
    +WXSDKEngine.registerModule("MyModule", WXEventModule.class);
     ```
    -
    -### Use this module in weex DSL
    +Use this module in weex DSL
     Now `event` moudle is avaiable in weex, use the module like this:
     
    -```javascript
    -var event = weex.requireModule('event');
    -event.openURL("http://www.github.com";);
    +```html
    +<template>
    +  <div>
    +    <text onclick="click">testMyModule</text>
    +  </div>
    +</template>
    +
    +<script>
    +  module.exports = {
    +    methods: {
    +      click: function() {
    +        weex.requireModule('myModule').printLog("I am a weex Module!");
    --- End diff --
    
    Maybe it's convenient to add a "uiThread = false" example.


---

Reply via email to