Browse Source

@fun: LoginScreen.kt

bai 3 years ago
parent
commit
03a82af388

+ 1 - 0
app/build.gradle.kts

@@ -121,6 +121,7 @@ dependencies {
     implementation("com.google.accompanist:accompanist-insets:0.20.3")
     implementation("com.google.accompanist:accompanist-insets-ui:0.20.3")
     implementation("com.google.accompanist:accompanist-systemuicontroller:0.20.3")
+    implementation("io.coil-kt:coil-compose:1.4.0")
 
     // test
     testImplementation(Deps.Test.Junit)

+ 2 - 0
app/src/main/AndroidManifest.xml

@@ -2,6 +2,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.ys.bdtp.adm">
 
+    <uses-permission android:name="android.permission.INTERNET"/>
     <application
             android:allowBackup="true"
             android:icon="@mipmap/ic_launcher"
@@ -9,6 +10,7 @@
             android:name=".AdmApplication"
             android:roundIcon="@mipmap/ic_launcher_round"
             android:supportsRtl="true"
+            android:usesCleartextTraffic="true"
             android:theme="@style/Theme.Adm">
         <activity
                 android:name=".MainActivity"

+ 7 - 2
app/src/main/java/com/ys/bdtp/adm/App.kt

@@ -21,13 +21,18 @@ fun App() = withDI(di(LocalContext.current)) {
         val systemUiController = rememberSystemUiController()
         val useDarkIcons = MaterialTheme.colors.isLight
 
-        AdmTheme {
+        AdmTheme() {
             ProvideWindowInsets {
                 Surface(color = MaterialTheme.colors.background) {
                     SideEffect {
+                        systemUiController.setNavigationBarColor(
+                            color = Color.Transparent,
+                            darkIcons = useDarkIcons,
+                        )
+
                         systemUiController.setStatusBarColor(
                             color = Color.Transparent,
-                            darkIcons = useDarkIcons
+                            darkIcons = useDarkIcons,
                         )
                     }
                     LoginScreen()

+ 30 - 26
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/login/LoginScreen.kt

@@ -3,7 +3,6 @@ package com.ys.bdtp.adm.mvvm.ui.screen.login
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.Row
 import androidx.compose.foundation.layout.Spacer
@@ -40,8 +39,9 @@ import androidx.compose.ui.text.input.VisualTransformation
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
+import androidx.constraintlayout.compose.ConstraintLayout
 import com.google.accompanist.insets.LocalWindowInsets
-import com.google.accompanist.insets.rememberInsetsPaddingValues
+import com.google.accompanist.insets.statusBarsHeight
 import com.ys.bdtp.adm.R
 
 @Composable
@@ -69,44 +69,48 @@ fun LoginScreen() {
             .fillMaxSize()
             .background(Color.White)
 
-
     ) {
-        Box(
-            modifier = Modifier.weight(3.0f).fillMaxHeight()
-        ) {
-
+        ConstraintLayout(modifier = Modifier.weight(3.0f).fillMaxHeight()) {
+            val (statusBar, logo, background, title) = createRefs()
 
             Image(
                 painter = painterResource(R.drawable.login_background),
                 contentDescription = "",
-                modifier = Modifier.fillMaxSize(),
+                modifier = Modifier.fillMaxSize().constrainAs(background) {
+                    top.linkTo(parent.top)
+                    bottom.linkTo(parent.bottom)
+                    start.linkTo(parent.start)
+                    end.linkTo(parent.end)
+                },
                 contentScale = ContentScale.Crop
             )
 
-            Column(
-                modifier = Modifier.fillMaxSize().padding(
-                    rememberInsetsPaddingValues(
-                        LocalWindowInsets.current.statusBars,
-                        additionalStart = 32.dp,
-                        additionalTop = 12.dp
+            Spacer(Modifier.statusBarsHeight().fillMaxWidth().constrainAs(statusBar) {
+                top.linkTo(parent.top)
+                start.linkTo(parent.start)
+                end.linkTo(parent.end)
+            })
 
-                    )
-                )
-            ) {
-                Icon(
-                    painter = painterResource(R.drawable.logo),
-                    contentDescription = "",
-                    modifier = Modifier.size(112.dp, 48.dp)
-                )
-            }
-
-            Column(modifier = Modifier.align(Alignment.Center)) {
+            Image(
+                painter = painterResource(R.drawable.logo),
+                contentDescription = "",
+                modifier = Modifier.size(112.dp, 48.dp).constrainAs(logo) {
+                    top.linkTo(statusBar.bottom, margin = 12.dp)
+                    start.linkTo(parent.start, margin = 32.dp)
+                }
+            )
+            val guideline = createGuidelineFromBottom(0.1f)
+            Column(modifier = Modifier.constrainAs(title) {
+                top.linkTo(parent.top, margin = 32.dp)
+                start.linkTo(parent.start)
+                end.linkTo(parent.end)
+                bottom.linkTo(guideline)
+            }) {
                 Text(text = "Yushu", fontSize = 36.sp, color = Color(0XFF1F2429))
                 Text("智慧建筑运维平台", fontSize = 48.sp, color = Color(0XFF1F2429))
                 Text("为您提供什么服务,能够用一句话概括出来吧。", fontSize = 16.sp, color = Color(0XFF8D9399))
             }
         }
-
         Column(
             modifier = Modifier.weight(2.0f)
                 .fillMaxHeight()