-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from PatilShreyas/v1.1.0-dev
Improvements for Compose App
- Loading branch information
Showing
33 changed files
with
670 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...mposeapp/src/main/java/dev/shreyaspatil/noty/composeapp/component/text/CommonTextField.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2020 Shreyas Patil | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.shreyaspatil.noty.composeapp.component.text | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.animation.ExperimentalAnimationApi | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.text.BasicTextField | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.OutlinedTextField | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.SolidColor | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.input.VisualTransformation | ||
import androidx.compose.ui.unit.TextUnit | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import dev.shreyaspatil.noty.composeapp.ui.theme.getTextFieldHintColor | ||
|
||
@Composable | ||
fun NotyTextField( | ||
value: String, | ||
label: String, | ||
onValueChange: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
fontSize: TextUnit = 16.sp, | ||
color: Color = MaterialTheme.colors.onPrimary, | ||
leadingIcon: @Composable() (() -> Unit)? = null, | ||
isError: Boolean = false, | ||
visualTransformation: VisualTransformation = VisualTransformation.None | ||
) { | ||
OutlinedTextField( | ||
value = value, | ||
label = { Text(text = label) }, | ||
modifier = modifier, | ||
onValueChange = onValueChange, | ||
leadingIcon = leadingIcon, | ||
textStyle = TextStyle(color, fontSize = fontSize), | ||
isError = isError, | ||
visualTransformation = visualTransformation | ||
) | ||
} | ||
|
||
@ExperimentalAnimationApi | ||
@Composable | ||
fun BasicNotyTextField( | ||
modifier: Modifier = Modifier, | ||
value: String = "", | ||
label: String = "", | ||
textStyle: TextStyle = TextStyle(fontSize = 16.sp, fontWeight = FontWeight.Normal), | ||
onTextChange: (String) -> Unit, | ||
maxLines: Int = Int.MAX_VALUE | ||
) { | ||
|
||
Box(modifier = modifier.padding(4.dp)) { | ||
AnimatedVisibility(visible = value.isBlank()) { | ||
Text( | ||
text = label, | ||
color = getTextFieldHintColor(), | ||
fontSize = textStyle.fontSize, | ||
fontWeight = textStyle.fontWeight | ||
) | ||
} | ||
BasicTextField( | ||
value = value, | ||
onValueChange = onTextChange, | ||
textStyle = textStyle.copy(color = MaterialTheme.colors.onPrimary), | ||
maxLines = maxLines, | ||
cursorBrush = SolidColor(MaterialTheme.colors.primary) | ||
) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...omposeapp/src/main/java/dev/shreyaspatil/noty/composeapp/component/text/NoteTextFields.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2020 Shreyas Patil | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.shreyaspatil.noty.composeapp.component.text | ||
|
||
import androidx.compose.animation.ExperimentalAnimationApi | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.sp | ||
|
||
@ExperimentalAnimationApi | ||
@Composable | ||
fun NoteTitleField( | ||
modifier: Modifier = Modifier, | ||
value: String = "", | ||
onTextChange: (String) -> Unit | ||
) { | ||
BasicNotyTextField( | ||
modifier, | ||
value = value, | ||
label = "Title", | ||
onTextChange = onTextChange, | ||
textStyle = MaterialTheme.typography.h6, | ||
maxLines = 2 | ||
) | ||
} | ||
|
||
@ExperimentalAnimationApi | ||
@Composable | ||
fun NoteField( | ||
modifier: Modifier = Modifier, | ||
value: String = "", | ||
onTextChange: (String) -> Unit | ||
) { | ||
BasicNotyTextField( | ||
modifier, | ||
value = value, | ||
label = "Write here", | ||
onTextChange = onTextChange, | ||
textStyle = TextStyle(fontSize = 18.sp, fontWeight = FontWeight.Light) | ||
) | ||
} |
83 changes: 83 additions & 0 deletions
83
...oseapp/src/main/java/dev/shreyaspatil/noty/composeapp/component/text/PasswordTextField.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2020 Shreyas Patil | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.shreyaspatil.noty.composeapp.component.text | ||
|
||
import androidx.compose.material.Icon | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.Password | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.input.PasswordVisualTransformation | ||
import dev.shreyaspatil.noty.utils.validator.AuthValidator.isPasswordAndConfirmPasswordSame | ||
import dev.shreyaspatil.noty.utils.validator.AuthValidator.isValidPassword | ||
|
||
@Composable | ||
fun PasswordTextField( | ||
modifier: Modifier = Modifier, | ||
value: String = "", | ||
onTextChange: (TextFieldValue<String>) -> Unit, | ||
) { | ||
var startedTyping by remember { mutableStateOf(false) } | ||
var isValid by remember { mutableStateOf(false) } | ||
|
||
NotyTextField( | ||
value = value, | ||
label = "Password", | ||
onValueChange = { | ||
isValid = isValidPassword(it) | ||
onTextChange(if (isValid) TextFieldValue.Valid(it) else TextFieldValue.Invalid(it)) | ||
if (!startedTyping) { | ||
startedTyping = true | ||
} | ||
}, | ||
modifier = modifier, | ||
leadingIcon = { Icon(Icons.Outlined.Password, "Password") }, | ||
visualTransformation = PasswordVisualTransformation(), | ||
isError = !isValid && startedTyping | ||
) | ||
} | ||
|
||
@Composable | ||
fun ConfirmPasswordTextField( | ||
modifier: Modifier = Modifier, | ||
value: String = "", | ||
expectedValue: String = "", | ||
onTextChange: (TextFieldValue<String>) -> Unit, | ||
) { | ||
var startedTyping by remember { mutableStateOf(false) } | ||
var isValid by remember { mutableStateOf(false) } | ||
|
||
NotyTextField( | ||
value = value, | ||
label = "Confirm Password", | ||
onValueChange = { | ||
isValid = isValidPassword(it) && isPasswordAndConfirmPasswordSame(expectedValue, it) | ||
onTextChange(if (isValid) TextFieldValue.Valid(it) else TextFieldValue.Invalid(it)) | ||
if (!startedTyping) { | ||
startedTyping = true | ||
} | ||
}, | ||
modifier = modifier, | ||
leadingIcon = { Icon(Icons.Outlined.Password, "Confirm Password") }, | ||
visualTransformation = PasswordVisualTransformation(), | ||
isError = !isValid && startedTyping | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
...omposeapp/src/main/java/dev/shreyaspatil/noty/composeapp/component/text/TextFieldValue.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2020 Shreyas Patil | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.shreyaspatil.noty.composeapp.component.text | ||
|
||
sealed class TextFieldValue<T>(val data: T) { | ||
class Valid<T>(data: T) : TextFieldValue<T>(data) | ||
class Invalid<T>(data: T) : TextFieldValue<T>(data) | ||
} |
53 changes: 53 additions & 0 deletions
53
...oseapp/src/main/java/dev/shreyaspatil/noty/composeapp/component/text/UsernameTextField.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2020 Shreyas Patil | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.shreyaspatil.noty.composeapp.component.text | ||
|
||
import androidx.compose.material.Icon | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.Person | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import dev.shreyaspatil.noty.utils.validator.AuthValidator | ||
|
||
@Composable | ||
fun UsernameTextField( | ||
modifier: Modifier = Modifier, | ||
value: String = "", | ||
onTextChange: (TextFieldValue<String>) -> Unit, | ||
) { | ||
var startedTyping by remember { mutableStateOf(false) } | ||
var isValid by remember { mutableStateOf(false) } | ||
|
||
NotyTextField( | ||
value = value, | ||
label = "Username", | ||
onValueChange = { | ||
isValid = AuthValidator.isValidUsername(it) | ||
onTextChange(if (isValid) TextFieldValue.Valid(it) else TextFieldValue.Invalid(it)) | ||
if (!startedTyping) { | ||
startedTyping = true | ||
} | ||
}, | ||
modifier = modifier, | ||
leadingIcon = { Icon(Icons.Outlined.Person, "User") }, | ||
isError = !isValid && startedTyping | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.