提交 d6f5b7af 编写于 作者: shutao-dc's avatar shutao-dc

uni-native-button/utssdk/app-android/index.uts

uni-time-picker/utssdk/app-android/index.uts
代码优化
上级 de825a7f
......@@ -5,13 +5,13 @@ export class NativeButton {
constructor(element : UniNativeViewElement) {
this.$element = element;
bindView();
this.bindView();
}
button : Button | null = null;
bindView() {
//通过UniElement.getAndroidActivity()获取android平台activity 用于创建view的上下文
this.button = new Button($element.getAndroidActivity()!); //构建原生view
this.button = new Button(this.$element.getAndroidActivity()!); //构建原生view
//限制原生Button 文案描述不自动大写
this.button?.setAllCaps(false)
//监听原生Button点击事件
......@@ -20,10 +20,10 @@ export class NativeButton {
//构建自定义UniNativeViewEvent返回对象
const event = new UniNativeViewEvent("customClick", detail)
//响应分发原生Button的点击事件
$element.dispatchEvent(event)
this.$element.dispatchEvent(event)
})
//UniNativeViewEvent 绑定 安卓原生view
$element.bindAndroidView(button!);
this.$element.bindAndroidView(button!);
}
updateText(text: string) {
......
import { TimePicker } from "android.widget"
import { View } from "android.view"
export class NativeTimePicker {
$element : UniNativeViewElement;
constructor(element : UniNativeViewElement, hour: number, minute: number) {
this.$element = element;
bindView(hour, minute);
this.bindView(hour, minute);
}
picker : TimePicker | null = null;
bindView(hour: number, minute: number) {
this.picker = new TimePicker($element.getAndroidActivity()!); //构建原生view
$element.bindAndroidView(picker!);
setHour(hour)
setMinute(minute)
this.picker = new TimePicker(this.$element.getAndroidActivity()!); //构建原生view
this.$element.bindAndroidView(this.picker!);
this.setHour(hour)
this.setMinute(minute)
this.picker?.setOnTimeChangedListener((_, hourOfDay, minute) => {
const detail = {"hour": hourOfDay, "minute": minute}
const event = new UniNativeViewEvent("timechanged", detail)
$element.dispatchEvent(event)
this.$element.dispatchEvent(event)
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册