complete Android & iOS with same logic

This commit is contained in:
王劲鹏
2020-01-03 18:06:57 +08:00
committed by osborn
parent ece2e0cac2
commit e06b305eb8
6 changed files with 110 additions and 20 deletions

View File

@@ -1,24 +1,38 @@
import { Panel, Group, vlayout, layoutConfig, draggable, Color, Text} from "doric";
import { Panel, Group, vlayout, layoutConfig, draggable, Color, Text, Draggable, modal, Gravity, loge} from "doric";
import { title } from "./utils";
@Entry
class DraggableDemo extends Panel {
build(root: Group) {
let text = (new Text).also(it => {
it.layoutConfig = layoutConfig().most()
it.layoutConfig = layoutConfig().just().configAlignmnet(Gravity.Center)
it.width = 100
it.height = 30
it.textColor = Color.parse('#ff0000')
it.onClick = () => {
modal(context).toast('Clicked')
}
})
let drag: Draggable
let lastX: number = 0
let lastY: number = 0
drag = draggable({
onDrag: (x: number, y: number) => {
lastX += x
lastY += y
drag.translationX = lastX
drag.translationY = lastY
loge(lastX)
text.text = "x: " + lastX.toFixed(0) + " y: " + lastY.toFixed(0)
}
}, [ text ]).apply({
layoutConfig: layoutConfig().just(),
width: 100,
height: 100,
backgroundColor: Color.WHITE
})
vlayout([
title("Draggable Demo"),
draggable({
onDrag: (x: number, y: number) => {
text.text = "x: " + x + " y: " + y
}
}, [ text ]).apply({
layoutConfig: layoutConfig().just(),
width: 100,
height: 100,
backgroundColor: Color.WHITE
})
drag
])
.apply({
layoutConfig: layoutConfig().most(),