提交 75a27954 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

Merge branch 'dev' of gitcode.net:dcloud/hello-uni-app-x into dev

<template> <template>
<native-view @init="onviewinit" @customClick="ontap"></native-view>
<native-view @init="onviewinit" @customClick="onclick"></native-view> </template>
<script lang="uts">
</template> import { NativeButton } from "@/uni_modules/native-button";
<script lang="uts">
import { NativeButton } from "@/uni_modules/uni-native-button";
export default { export default {
data() { data() {
return { return {
button: null as NativeButton | null, button: null as NativeButton | null,
value : "" value: ""
} }
}, },
props: { props: {
...@@ -27,30 +20,28 @@ ...@@ -27,30 +20,28 @@
"text": { "text": {
handler(newValue : string, oldValue : string) { handler(newValue : string, oldValue : string) {
this.value = newValue this.value = newValue
this.button?.updateText(this.value) this.updateText(newValue)
}, },
immediate: true immediate: true
}, },
}, },
methods: { methods: {
//native-view初始化时触发此方法
onviewinit(e : UniNativeViewInitEvent) { onviewinit(e : UniNativeViewInitEvent) {
//获取UniNativeViewElement 传递给NativeButton插件
this.button = new NativeButton(e.detail.element); this.button = new NativeButton(e.detail.element);
this.button?.updateText(this.value) this.button?.updateText(this.value)
this.$emit("load") },
}, ontap(e: UniNativeViewEvent) {
onclick(e: UniNativeViewEvent) {
this.$emit("buttonTap", e) this.$emit("buttonTap", e)
},
updateText(value: string) {
this.button?.updateText(value)
} }
}, },
unmounted() { unmounted() {
// #ifdef APP-IOS // iOS平台需要主动释放 uts 实例
// iOS平台需要主动释放 uts 实例 this.button?.destroy()
this.button.destroy()
// #endif
} }
} }
</script> </script>
<style>
</style>
...@@ -15,7 +15,7 @@ export class NativeButton { ...@@ -15,7 +15,7 @@ export class NativeButton {
//限制原生Button 文案描述不自动大写 //限制原生Button 文案描述不自动大写
this.button?.setAllCaps(false) this.button?.setAllCaps(false)
//监听原生Button点击事件 //监听原生Button点击事件
this.button?.setOnClickListener(_ => { this.button?.setOnClickListener(_ => {
const detail = {} const detail = {}
//构建自定义UniNativeViewEvent返回对象 //构建自定义UniNativeViewEvent返回对象
const event = new UniNativeViewEvent("customClick", detail) const event = new UniNativeViewEvent("customClick", detail)
...@@ -23,7 +23,7 @@ export class NativeButton { ...@@ -23,7 +23,7 @@ export class NativeButton {
this.$element.dispatchEvent(event) this.$element.dispatchEvent(event)
}) })
//UniNativeViewEvent 绑定 安卓原生view //UniNativeViewEvent 绑定 安卓原生view
this.$element.bindAndroidView(button!); this.$element.bindAndroidView(this.button!);
} }
updateText(text: string) { updateText(text: string) {
...@@ -31,4 +31,7 @@ export class NativeButton { ...@@ -31,4 +31,7 @@ export class NativeButton {
this.button?.setText(text) this.button?.setText(text)
} }
destroy(){
//数据回收
}
} }
<template> <template>
<native-view class="def-picker" @init="onviewinit" @timechanged="ontimechanged"></native-view> <view class="def-picker">
<native-view style="width: 100%; height: 100%;" @init="onviewinit" @timechanged="ontimechanged"></native-view>
</view>
</template> </template>
<script lang="uts"> <script lang="uts">
import { NativeTimePicker } from "@/uni_modules/uni-time-picker"; import { NativeTimePicker } from "@/uni_modules/native-time-picker";
export default { export default {
......
import { TimePicker } from "android.widget" import TimePicker from "android.widget.TimePicker"
export class NativeTimePicker { export class NativeTimePicker {
$element : UniNativeViewElement; $element : UniNativeViewElement;
...@@ -28,5 +28,4 @@ export class NativeTimePicker { ...@@ -28,5 +28,4 @@ export class NativeTimePicker {
setMinute(minute: number) { setMinute(minute: number) {
this.picker?.setMinute(minute.toInt()) this.picker?.setMinute(minute.toInt())
} }
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册