Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[Android] Android SDK custom WXComponent, there are multiple properties defined using @WXComponentProp, how do I know when all properties are passed from JS to native? #2833

Closed
luohb92 opened this issue Aug 16, 2019 · 1 comment
Labels

Comments

@luohb92
Copy link

luohb92 commented Aug 16, 2019

Weex Android SDK custom WXComponent, with multiple properties using @WXComponentProp

Definition, how do I know when all properties are passed from JS to native? My second property needs to depend on the first property.
Custom WXComponent code is as follows

public class WeexLottieAnimationView extends WXComponent<LottieAnimationView> {
public Context mContext;
private LottieTask<LottieComposition> mLottieResult;
private boolean mLoop; public WeexLottieAnimationView(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) { super(instance, parent, basicComponentData); mContext = instance.getContext(); }

@Override
protected LottieAnimationView initComponentHostView(@NonNull Context context) {
    LottieAnimationView animationView = new LottieAnimationView(context);
    return animationView;
}

@WXComponentProp(name = "url")
public void getUrl(String url) {
    mLottieResult = LottieCompositionFactory.fromUrl(mContext, url);
    mLottieResult.addListener(new LottieListener<LottieComposition>() {
        @Override
        public void onResult(LottieComposition result) {
            getHostView().setComposition(result);
            if (mLoop) {
                getHostView().setRepeatCount(-1);
            }
            getHostView().playAnimation();

        }
    });
}

@WXComponentProp(name = "loop")
public void setLoop(final boolean loop) {
    mLoop = loop;
    if (loop) {
        getHostView().setRepeatCount(-1);
    }
}

Weex code is as follows:
<template>
<lottie class="lottie" :url="url" :loop=true></lottie>
</template>

<script>
export default {
data () {
return {
url: "https://kano.guahao.cn/aEr123600560",
}
}
}
</script>

<style scoped>
.lottie {
width: 750px;
height: 458px;
}
</style>

My url property callback method relies on the loop property. I want the url property callback method to be executed after the loop property callback method。

@luohb92 luohb92 added the Bug label Aug 16, 2019
@luohb92 luohb92 changed the title [Android] Android SDK 自定义WXComponent, 有多个属性使用@WXComponentProp 定义,我要怎么知道什么时候所有属性都从JS传到native这边呢? [Android] Android SDK custom WXComponent, there are multiple properties defined using @WXComponentProp, how do I know when all properties are passed from JS to native? Aug 16, 2019
@YorkShen
Copy link
Contributor

You can combine multiple properties into one.

@WXComponentProp(name = "lottie")
public void setLoop(final com.alibaba.fastjson.JSONObjcet map) {

}
<template>
<lottie class="lottie" :lottie="url"></lottie>
</template>

<script>
export default {
    data () {
        return {
            lottie: {
                    key_A: value_A,
                    key_B: value_B
             }
         }
     }
}
</script>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants