Skip to content

Commit

Permalink
feat(顶部): 顶部结果布局
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaoyaning committed Aug 7, 2022
1 parent f7e9604 commit ef53028
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ dependencies {
implementation 'androidx.activity:activity-compose:1.4.0'
implementation "androidx.compose.runtime:runtime:1.3.0-alpha01"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1"

implementation "com.apkfuns.logutils:library:1.7.5"
}
9 changes: 2 additions & 7 deletions app/src/main/java/com/jyn/composecalculator/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ package com.jyn.composecalculator
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.apkfuns.logutils.LogUtils
import com.jyn.composecalculator.ui.ContentView
import com.jyn.composecalculator.ui.theme.ComposeCalculatorTheme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
LogUtils.getLogConfig().configShowBorders(false)
setContent {
ComposeCalculatorTheme {
ContentView()
Expand Down
29 changes: 10 additions & 19 deletions app/src/main/java/com/jyn/composecalculator/ui/TopResultView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,38 @@ import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.apkfuns.logutils.LogUtils

/**
* 上层结果
* Created by jiaoyaning on 2022/8/6.
*/
enum class Status {
MIN, MAX
}

@OptIn(ExperimentalMaterialApi::class)
@Preview(showBackground = true)
@Composable
fun TopResultView() {
val configuration = LocalConfiguration.current
val screenHeight = configuration.screenHeightDp.dp
val screenWidth = configuration.screenWidthDp.dp

val topHeight = screenHeight * BOTTOM_FRACTION + 10.dp
val swipeableState = rememberSwipeableState(0)

val sizePx = with(LocalDensity.current) { -topHeight.toPx() }
val anchors = mapOf(0f to 0, sizePx to 1)

Surface(
modifier = Modifier
.padding(bottom = topHeight)
.fillMaxWidth()
.fillMaxHeight(),

// .swipeable(
// state = swipeableState,
// anchors = anchors,
// thresholds = { _, _ -> FractionalThreshold(0.3f) },
// orientation = Orientation.Vertical
// )

shape = RoundedCornerShape(25.dp),
.width(screenWidth)
.height(screenHeight)
.offset(y = -topHeight),
shape = RoundedCornerShape(bottomStart = 25.dp, bottomEnd = 25.dp),
tonalElevation = 3.dp
) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.Bottom
) {
Text("TopResultView")
Text("TopResultView", fontSize = 22.sp)
}
}
}
8 changes: 8 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ pluginManagement {
gradlePluginPortal()
google()
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
}
}
rootProject.name = "ComposeCalculator"
Expand Down

0 comments on commit ef53028

Please sign in to comment.