Экран авторизации + скролл при появлении экранной клавиатуры + минорные исправления

This commit is contained in:
Данила Мочалов 2023-10-07 20:36:35 +04:00
parent 6f68f6a63a
commit 8f58d80118
5 changed files with 145 additions and 5 deletions

View File

@ -13,6 +13,7 @@
tools:targetApi="31"> tools:targetApi="31">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true" android:exported="true"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/Theme.Shawarma"> android:theme="@style/Theme.Shawarma">

View File

@ -6,6 +6,7 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Surface import androidx.compose.material.Surface
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import com.example.shawarma.screens.authorization.AuthorizationScreen
import com.example.shawarma.screens.registration.RegistrationScreen import com.example.shawarma.screens.registration.RegistrationScreen
import com.example.shawarma.ui.theme.MyLightYellow import com.example.shawarma.ui.theme.MyLightYellow
import com.example.shawarma.ui.theme.ShawarmaTheme import com.example.shawarma.ui.theme.ShawarmaTheme
@ -13,6 +14,7 @@ import com.example.shawarma.ui.theme.ShawarmaTheme
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
ShawarmaTheme { ShawarmaTheme {
// A surface container using the 'background' color from the theme // A surface container using the 'background' color from the theme
@ -21,7 +23,7 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
) )
{ {
RegistrationScreen() AuthorizationScreen()
} }
} }
} }

View File

@ -0,0 +1,125 @@
package com.example.shawarma.screens.authorization
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex
import com.example.shawarma.ui.theme.JejuFamily
import com.example.shawarma.ui.theme.MyLightRed
import com.example.shawarma.widgets.MyTextField
import com.example.shawarma.widgets.ShawarmaLogo1
@Composable
fun AuthorizationScreen() {
ShawarmaLogo1()
AuthorizationCard()
}
@Composable
fun AuthorizationCard() {
val login = remember { mutableStateOf(TextFieldValue("")) }
val password = remember { mutableStateOf(TextFieldValue("")) }
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.zIndex(2f)
.verticalScroll(rememberScrollState())
.imePadding().padding(10.dp)
.fillMaxHeight()
) {
Card(
shape = RoundedCornerShape(20.dp),
modifier = Modifier.size(275.dp, 290.dp + 72.dp).padding(top = 72.dp)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Авторизация",
fontSize = 20.sp,
modifier = Modifier.padding(
top = 20.dp
),
style = TextStyle(
fontFamily = JejuFamily
)
)
MyTextField(
text = login,
onTextChanged = {login.value = it},
modifier = Modifier
.padding(
top = (20).dp
)
.size(208.dp, (50).dp),
placeholder = "Логин",
singleLine = true
)
MyTextField(
text = password,
onTextChanged = {password.value = it},
modifier = Modifier
.padding(
top = (20).dp
)
.size(208.dp, (50).dp),
placeholder = "Пароль",
singleLine = true
)
Button(
onClick = { /*TODO*/ },
colors = ButtonDefaults.buttonColors(MyLightRed, Color.White),
shape = RoundedCornerShape(20.dp),
modifier = Modifier
.padding(
top = (20).dp
)
.size(208.dp, (50).dp)
) {
Text(
text = "Войти",
style = TextStyle(
fontFamily = JejuFamily,
fontSize = 16.sp
)
)
}
Button(
onClick = { /*TODO*/ },
colors = ButtonDefaults.buttonColors(Color.White),
elevation = ButtonDefaults.elevation(0.dp)
) {
Text(
text = "У меня нет аккаунта!",
textDecoration = TextDecoration.Underline,
style = TextStyle(
fontFamily = JejuFamily,
fontSize = 12.sp
)
)
}
}
}
}
}

View File

@ -1,9 +1,16 @@
package com.example.shawarma.screens.registration package com.example.shawarma.screens.registration
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.FlingBehavior
import androidx.compose.foundation.gestures.ScrollScope
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Card import androidx.compose.material.Card
@ -41,12 +48,14 @@ fun RegistrationCard(){
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier modifier = Modifier
.padding(top = 72.dp)
.zIndex(2f) .zIndex(2f)
.verticalScroll(rememberScrollState())
.imePadding().padding(10.dp)
.fillMaxHeight()
) { ) {
Card( Card(
shape = RoundedCornerShape(20.dp), shape = RoundedCornerShape(20.dp),
modifier = Modifier.size(275.dp, 380.dp) modifier = Modifier.size(275.dp, 380.dp + 72.dp).padding(top = 72.dp)
) { ) {
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally

View File

@ -1,6 +1,7 @@
package com.example.shawarma.widgets package com.example.shawarma.widgets
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.offset
@ -8,6 +9,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
@ -16,8 +18,9 @@ import com.example.shawarma.R
@Composable @Composable
fun ShawarmaLogo1(){ fun ShawarmaLogo1(){
Column(modifier = Modifier Column(modifier = Modifier
.zIndex(1f) .zIndex(-1f)
.fillMaxSize()) { .fillMaxSize()
) {
Image( Image(
painterResource( painterResource(
id = R.drawable.shawarma1 id = R.drawable.shawarma1