Skip to content

Commit

Permalink
feat:新增NumberKeyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
yangqi1024 committed May 6, 2022
1 parent 55a044f commit 4c9cd3a
Show file tree
Hide file tree
Showing 6 changed files with 383 additions and 40 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- [GridCard](#GridCard)
- [Indicator](#Indicator)
- [NoticeBar](#NoticeBar)
- [NumberKeyboard](#NumberKeyboard)
- [Preview](#Preview)
- [PrivacyPolicy](#PrivacyPolicy)
- [Progress](#Progress)
Expand Down Expand Up @@ -98,6 +99,12 @@ Name | 截图
--- | ---
NoticeBar| <img src="https://cdn.jsdelivr.net/gh/yangqi1024/pic-repo/Cui/noticebar/screenshot.jpg" width="324" height="702">

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

Preview
======================
Name | 截图
Expand Down Expand Up @@ -177,5 +184,6 @@ Compose UI组件参考和引用的部分开源库如下:
- [BannerViewPager](https://github.com/zhpanvip/BannerViewPager)
- [accompanist](https://github.com/google/accompanist)
- [ant-design](https://github.com/ant-design/ant-design)
- [nutui](https://github.com/jdf2e/nutui)

感谢以上开源库的作者
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,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.numberkeyboard.NumberKeyboardActivity"
android:exported="true"
android:label="NumberKeyboard示例"
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cn.idesign.cui.testclient.numberkeyboard

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.Surface
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.ui.Modifier
import cn.idesign.cui.testclient.ui.theme.CUITestTheme

class NumberKeyboardActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CUITestTheme {
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
text = "NumberKeyboard示例",
color = MaterialTheme.colors.onPrimary
)
},
backgroundColor = MaterialTheme.colors.primary,
)
},
modifier = Modifier.fillMaxSize()
) {
NumberKeyboardTest()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package cn.idesign.cui.testclient.numberkeyboard

import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import cn.idesign.cui.bottomsheet.rememberBottomSheetState
import cn.idesign.cui.cell.Cell
import cn.idesign.cui.numberkeyboard.NumberKeyBoard
import kotlinx.coroutines.launch

@Composable
fun NumberKeyboardTest() {
val commonState = rememberBottomSheetState()
val randomState = rememberBottomSheetState()
val customState = rememberBottomSheetState()
val disableState = rememberBottomSheetState()
val scope = rememberCoroutineScope()
val context = LocalContext.current
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)
)
Cell(text = "默认键盘", onClick = {
scope.launch {
commonState.show()
}
})
}
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)
)
Cell(text = "随机数键盘", onClick = {
scope.launch {
randomState.show()
}
})
}

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)
)
Cell(text = "自定义用法", onClick = {
scope.launch {
customState.show()
}
})
}
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)
)
Cell(text = "禁用确认按钮", onClick = {
scope.launch {
disableState.show()
}
})
}
}

NumberKeyBoard(
state = commonState,
onInput = {
Toast.makeText(context, "点击了:${it}", Toast.LENGTH_SHORT).show()

},
onDelete = {
Toast.makeText(context, "点击了:删除", Toast.LENGTH_SHORT).show()
},
onConfirm = {
Toast.makeText(context, "点击了:确定", Toast.LENGTH_SHORT).show()
}
)
NumberKeyBoard(
state = customState, confirmText = "支付", confirmModifier = Modifier.background(
Color(0xff66bb6a)
)
)
NumberKeyBoard(state = randomState, random = true)
NumberKeyBoard(state = disableState, confirmDisable = true)
}
Loading

0 comments on commit 4c9cd3a

Please sign in to comment.