1
+ package com.gzq.wanandroid.features.test_click
2
+
3
+ import android.widget.Toast
4
+ import androidx.compose.animation.ExperimentalAnimationApi
5
+ import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.gestures.Orientation
7
+ import androidx.compose.foundation.gestures.draggable
8
+ import androidx.compose.foundation.gestures.rememberDraggableState
9
+ import androidx.compose.foundation.layout.Box
10
+ import androidx.compose.foundation.layout.Column
11
+ import androidx.compose.foundation.layout.Spacer
12
+ import androidx.compose.foundation.layout.fillMaxSize
13
+ import androidx.compose.foundation.layout.fillMaxWidth
14
+ import androidx.compose.foundation.layout.height
15
+ import androidx.compose.foundation.layout.offset
16
+ import androidx.compose.foundation.layout.padding
17
+ import androidx.compose.foundation.rememberScrollState
18
+ import androidx.compose.foundation.verticalScroll
19
+ import androidx.compose.material3.Button
20
+ import androidx.compose.material3.ExperimentalMaterial3Api
21
+ import androidx.compose.material3.Scaffold
22
+ import androidx.compose.material3.Text
23
+ import androidx.compose.runtime.Composable
24
+ import androidx.compose.runtime.getValue
25
+ import androidx.compose.runtime.key
26
+ import androidx.compose.runtime.mutableStateOf
27
+ import androidx.compose.runtime.remember
28
+ import androidx.compose.runtime.setValue
29
+ import androidx.compose.ui.Modifier
30
+ import androidx.compose.ui.graphics.Color
31
+ import androidx.compose.ui.platform.LocalContext
32
+ import androidx.compose.ui.unit.IntOffset
33
+ import androidx.compose.ui.unit.dp
34
+ import androidx.navigation.NavGraphBuilder
35
+ import androidx.navigation.NavHostController
36
+ import com.google.accompanist.navigation.animation.composable
37
+ import com.gzq.wanandroid.router.Router
38
+ import com.gzq.wanandroid.widget.MyTopAppBar
39
+ import kotlin.math.roundToInt
40
+
41
+ @OptIn(ExperimentalAnimationApi ::class )
42
+ fun NavGraphBuilder.testClickPage (
43
+ navController : NavHostController
44
+ ) {
45
+ composable(Router .TestClickPage .route) {
46
+ TestClickPage (){
47
+
48
+ }
49
+ }
50
+ }
51
+
52
+ @OptIn(ExperimentalMaterial3Api ::class )
53
+ @Composable
54
+ fun TestClickPage (clickBack : () -> Unit ) {
55
+ Scaffold (topBar = {
56
+ MyTopAppBar (title = " 测试点击穿透" , clickBack = clickBack)
57
+ }) { paddingValues ->
58
+ val ctx = LocalContext .current
59
+ Box (
60
+ Modifier
61
+ .padding(paddingValues)
62
+ .fillMaxSize()
63
+ ) {
64
+ Button (onClick = {
65
+ Toast .makeText(ctx, " 点击生效" , Toast .LENGTH_SHORT ).show()
66
+ }) {
67
+ Text (text = " 点击我" )
68
+ }
69
+
70
+ Column (
71
+ Modifier
72
+ .fillMaxSize()
73
+ .verticalScroll(rememberScrollState())
74
+ ) {
75
+
76
+ }
77
+ }
78
+ }
79
+ }
80
+
81
+ @Composable
82
+ fun ClickEventTest () {
83
+ val ctx = LocalContext .current
84
+ var offset by remember {
85
+ mutableStateOf(0f )
86
+ }
87
+ Box (Modifier .fillMaxSize()) {
88
+ Button (
89
+ onClick = { Toast .makeText(ctx, " 我是Toast" , Toast .LENGTH_SHORT ).show() },
90
+ ) {
91
+ Text (text = " 点我" )
92
+ }
93
+ Column (
94
+ Modifier
95
+ .fillMaxSize()
96
+ .offset { IntOffset (0 , offset.roundToInt()) }
97
+ .draggable(rememberDraggableState(onDelta = { offset + = it}), Orientation .Vertical )
98
+ ) {
99
+ repeat(20 ){ i->
100
+ key(i) {
101
+ Text (text = " Item $i " , modifier = Modifier .padding(20 .dp))
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
0 commit comments