Skip to content

Commit

Permalink
feat:新增Swipe
Browse files Browse the repository at this point in the history
  • Loading branch information
yangqi1024 committed May 9, 2022
1 parent 0984a8b commit bd377be
Show file tree
Hide file tree
Showing 6 changed files with 519 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- [StatefulLayout](#StatefulLayout)
- [Stepper](#Stepper)
- [Steps](#Steps)
- [Swipe](#Swipe)
- [TimeSelect](#TimeSelect)
- [VerifyCode](#VerifyCode)

Expand Down Expand Up @@ -172,6 +173,12 @@ Name | 截图
--- | ---
Steps| <img src="https://cdn.jsdelivr.net/gh/yangqi1024/pic-repo/Cui/steps/screenshot.jpg" width="324" height="702">

Swipe
======================
Name | 截图
--- | ---
Swipe| <img src="https://cdn.jsdelivr.net/gh/yangqi1024/pic-repo/Cui/swipe/screenshot.jpg" width="324" height="702">

TimeSelect
======================
Name | 截图
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="cn.idesign.cui.testclient.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity
android:name="cn.idesign.cui.testclient.swipe.SwipeActivity"
android:exported="true"
android:label="Swipe示例"
android:theme="@style/Theme.CUI">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="cn.idesign.cui.testclient.SAMPLE_CODE" />
</intent-filter>
</activity>
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/java/cn/idesign/cui/testclient/swipe/SwipeActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cn.idesign.cui.testclient.swipe

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.ui.Modifier
import cn.idesign.cui.testclient.ui.theme.CUITestTheme

class SwipeActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CUITestTheme {
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
text = "Swipe示例",
color = MaterialTheme.colors.onPrimary
)
},
backgroundColor = MaterialTheme.colors.primary,
)
},
modifier = Modifier.fillMaxSize()
) {
SwipeTest()
}
}
}
}
}
182 changes: 182 additions & 0 deletions app/src/main/java/cn/idesign/cui/testclient/swipe/SwipeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package cn.idesign.cui.testclient.swipe

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Switch
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import cn.idesign.cui.cell.Cell
import cn.idesign.cui.swipe.Swipe
import cn.idesign.cui.swipe.SwipeDirection
import cn.idesign.cui.swipe.rememberSwipeState

@Composable
fun SwipeTest() {
var checked by remember {
mutableStateOf(false)
}
val state = rememberSwipeState()
LazyColumn(
Modifier.padding(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)
) {
item {
Text(
text = "基本用法",
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
color = MaterialTheme.colors.onSurface.copy(ContentAlpha.high),
style = MaterialTheme.typography.subtitle1.copy(fontWeight = FontWeight.Medium)
)
Swipe(background = {
Box(
modifier = Modifier
.width(66.dp)
.fillMaxHeight()
.background(Color.Red),
contentAlignment = Alignment.Center
) {
Text(
text = "删除",
color = Color.White,

)
}
}) {
Cell(text = "左滑删除")
}
}
item {
Text(
text = "右滑删除",
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
color = MaterialTheme.colors.onSurface.copy(ContentAlpha.high),
style = MaterialTheme.typography.subtitle1.copy(fontWeight = FontWeight.Medium)
)
Swipe(
direction = SwipeDirection.LeftToRight,
background = {
Box(
modifier = Modifier
.width(66.dp)
.fillMaxHeight()
.background(MaterialTheme.colors.primary),
contentAlignment = Alignment.Center
) {
Text(
text = "收藏",
color = Color.White,

)
}
}) {
Cell(text = "右滑删除")
}
}
item {
Text(
text = "多个操作",
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
color = MaterialTheme.colors.onSurface.copy(ContentAlpha.high),
style = MaterialTheme.typography.subtitle1.copy(fontWeight = FontWeight.Medium)
)
Swipe(background = {
Row {
Box(
modifier = Modifier
.width(66.dp)
.fillMaxHeight()
.background(Color.Red),
contentAlignment = Alignment.Center
) {
Text(
text = "删除",
color = Color.White,

)
}
Box(
modifier = Modifier
.width(66.dp)
.fillMaxHeight()
.background(MaterialTheme.colors.primary),
contentAlignment = Alignment.Center
) {
Text(
text = "收藏",
color = Color.White,

)
}
}
}) {
Cell(text = "多个操作")
}
}

item {
Text(
text = "异步控制",
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
color = MaterialTheme.colors.onSurface.copy(ContentAlpha.high),
style = MaterialTheme.typography.subtitle1.copy(fontWeight = FontWeight.Medium)
)
Swipe(
state = state,
background = {
Box(
modifier = Modifier
.width(66.dp)
.fillMaxHeight()
.background(Color.Red),
contentAlignment = Alignment.Center
) {
Text(
text = "删除",
color = Color.White,

)
}

}) {
Cell(
text = "多个操作",
rightComponent = {
Switch(checked = checked, onCheckedChange = {
checked = it
if (it) {
state.open()
} else {
state.close()
}
})
},
)
}
}
}
}
Loading

0 comments on commit bd377be

Please sign in to comment.