Skip to content

Commit

Permalink
style(顶部): 输入框 & 光标
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaoyaning committed Aug 9, 2022
1 parent 4c2e4bd commit dcf7e16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 7 additions & 5 deletions app/src/main/java/com/jyn/composecalculator/ui/BottomBtnView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ package com.jyn.composecalculator.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.jyn.composecalculator.DateViewModel
import com.jyn.composecalculator.R

/**
* 底部按钮
Expand Down Expand Up @@ -72,7 +71,6 @@ fun BottomBtnView() {

@Composable
fun ItemBtn(text: String) {
val modifier = if (text != "=") Modifier.aspectRatio(1f) else Modifier
val viewModel = viewModel<DateViewModel>()

Button(
Expand All @@ -89,6 +87,10 @@ fun ItemBtn(text: String) {
.fillMaxHeight(),
contentAlignment = Alignment.Center
) {
if (text == "D") {
Icon(painter = painterResource(R.drawable.ic_backspace), contentDescription = "")
return@Box
}
Text(
text = text,
fontSize = 30.sp
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/com/jyn/composecalculator/ui/TopResultView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,17 @@ fun InputText(input: String) {
@Preview(showBackground = true)
@Composable
fun CursorView() {
val infiniteTransition = rememberInfiniteTransition()
val float = infiniteTransition.animateFloat(
initialValue = 0f, targetValue = 1f, animationSpec = infiniteRepeatable(
animation = tween(1000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)

Spacer(
modifier = Modifier
.background(Color.Red)
.background(if (float.value > 0.5) Color.Red else Color.Transparent)
.width(2.dp)
.height(50.dp)
)
Expand Down

0 comments on commit dcf7e16

Please sign in to comment.