SMR工作室
SMR工作室
  • 发布:2022-10-28 16:01
  • 更新:2022-11-02 11:56
  • 阅读:419

【报Bug】安卓基座调用 ownerInstance.callMethod 无效,H5正常。

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: Windows 11 专业版 22621.675

HBuilderX类型: 正式

HBuilderX版本号: 3.6.4

手机系统: Android

手机系统版本号: Android 9.0

手机厂商: 模拟器

手机机型: SM-G988N

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
<template>  
    <view class="app-box">  
        <view id="test" :style="{left:x+'rpx',top:y+'rpx'}" class="box" @click="test.onclick">  
            <text>{{'y : ' + y}}</text>  
        </view>  
        <view :style="{left:xx+'rpx',top:yy+'rpx',backgroundColor: 'red'}" class="box" @click="onclick1">  
            <text>{{'y : '+ yy}}</text>  
        </view>  
    </view>  
</template>  

<script setup lang="ts">  
    import {  
        ref  
    } from "vue"  

    const x = ref(0)  
    const y = ref(0)  

    const onclickEx = (cy: number) => {  
        console.log('@@@', cy);  
        y.value = cy  
    }  

    const xx = ref(300)  
    const yy = ref(0)  

    let hh = 0  
    const ss = 4  
    let pp = ss  

    const onclick1 = () => {  
        if (hh !== 0) {  
            clearInterval(hh)  
            hh = 0  
        } else {  
            hh = setInterval(() => {  
                if (yy.value >= 1000) {  
                    pp = ss * 0 - ss  
                } else if (yy.value <= 0) {  
                    pp = ss  
                }  
                yy.value = yy.value + pp  
            }, 1000 / 60)  
        }  
    }  
</script>  

<script module="test" lang="renderjs">  
    export default {  
        mounted() {  

        },  

        data() {  
            return {  
                x: 0,  
                y: 0,  
                s: 4,  
                p: this.s  
            }  
        },  

        methods: {  
            onclick(e, o) {  
                this.updateView(() => {  
                    console.log(this.y);  

                    if (this.y >= 1000) {  
                        this.p = this.s * 0 - this.s  
                    } else if (this.y <= 0) {  
                        this.p = this.s  
                    }  
                    this.y = this.y + this.p  

                    o.callMethod('onclickEx', this.y)  

                    return false  
                })  
            },  

            updateView(fn) {  
                let lastFrameTime = 0  

                const animationFrame = (nowFrameTime) => {  

                    let stopAnimation = false  

                    if (lastFrameTime != 0) {  
                        const oneFrameTime = Math.min(nowFrameTime - lastFrameTime, 100) / 1000  
                        stopAnimation = fn(oneFrameTime) === false  
                    }  

                    lastFrameTime = nowFrameTime  

                    if (!stopAnimation) {  
                        requestAnimationFrame(animationFrame);  
                    }  

                }  
                requestAnimationFrame(animationFrame);  
            }  
        }  
    }  
</script>  

<style lang="scss" scoped>  
    .app-box {  
        width: 100vw;  
        height: 100vh;  
        display: flex;  
        flex-direction: column;  
        justify-content: center;  
        align-items: center;  
        position: relative;  

        .box {  
            width: 200rpx;  
            height: 200rpx;  
            background-color: #666;  
            position: absolute;  
        }  
    }  
</style>  

操作步骤:

如代码示例

预期结果:

视图层成功调用逻辑层函数

实际结果:

视图层成功未调用逻辑层函数,没反映

bug描述:

安卓基座调用 ownerInstance.callMethod 无效,H5正常。

2022-10-28 16:01 负责人:无 分享
已邀请:
BoredApe

BoredApe - 有问题就会有答案。

请看您另一个问答中的回复。更新HBuilderX到最新版本测试。我这边测试是正常可以响应到事件的

该问题目前已经被锁定, 无法添加新回复