-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add placeholder and label customization #28
Add placeholder and label customization #28
Conversation
…fields to support them
… with the new data classes
|
@Composable | ||
fun inlinePaymentCardInputLayout(): @Composable() (PaymentCardInputScope.(Modifier) -> Unit) = | ||
{ inline(modifier = it) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to the top as it is the entry point (did not make it internal as it was exposed before)
{ inline(modifier = it) } | ||
|
||
@Composable | ||
fun inlinePaymentCardInputLayout(placeholderTexts: PlaceholderTexts): @Composable() (PaymentCardInputScope.(Modifier) -> Unit) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a new method for providing placeholderTexts
functionality to existing API users
@@ -206,221 +185,3 @@ fun PaymentCardInput( | |||
) | |||
} | |||
|
|||
interface PaymentCardInputScope { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved outside
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.TextStyle | ||
|
||
interface PaymentCardInputScope { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved out from PaymentCardInput
and added new composable methods commented below
fun CardNumberField(modifier: Modifier, options: TextFieldOptions, placeholder: String) | ||
|
||
@Composable | ||
fun CardNumberField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New input that accepts Composables
fun ExpiryField(modifier: Modifier, options: TextFieldOptions, placeholder: String) | ||
|
||
@Composable | ||
fun ExpiryField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New input that accepts Composables
fun CVCField(modifier: Modifier, options: TextFieldOptions, placeholder: String) | ||
|
||
@Composable | ||
fun CVCField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New input that accepts Composables
import com.evervault.sdk.input.model.placeholder.PlaceholderTextsDefaults | ||
import com.evervault.sdk.input.ui.component.CustomTextField | ||
|
||
internal class PaymentCardInputScopeImpl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved out from PaymentCardInput
and added new composable implementation methods commented below
} | ||
|
||
@Composable | ||
override fun CardNumberField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New input that accepts Composables
} | ||
|
||
@Composable | ||
override fun ExpiryField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New input that accepts Composables
} | ||
|
||
@Composable | ||
override fun CVCField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New input that accepts Composables
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
private fun CustomTextField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing new, just extracted from PaymentCardInput
import com.evervault.sdk.input.model.placeholder.PlaceholderTexts | ||
|
||
@Composable | ||
fun rowsPaymentCardInputLayout(): @Composable() (PaymentCardInputScope.(Modifier) -> Unit) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to the top as it is the entry point (did not make it internal as it was exposed before)
{ rows(modifier = it) } | ||
|
||
@Composable | ||
fun rowsPaymentCardInputLayout(placeholderTexts: PlaceholderTexts): @Composable() (PaymentCardInputScope.(Modifier) -> Unit) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a new method for providing placeholderTexts
functionality to existing API users
*/ | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
internal fun CustomTextField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new input field that works with Composables
@@ -0,0 +1,231 @@ | |||
package com.evervault.sdk.input.ui.sample |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed the PaymentCardInputComponentSamples
, modified and added new samples (can be seen inside AS)
*/ | ||
|
||
@Composable | ||
internal fun PaymentCardInputScope.PaymentCardCustomLayoutWithNewComponents(modifier: Modifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to create this one not to pollute the NavigationGraph
. Temporarily until we create a shared module where we can share components between the libs and the sample app
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
internal fun InfoBlock(label: String, value: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just extracted from CreditCardInputView
import com.evervault.sdk.input.model.placeholder.PlaceholderDefaults | ||
|
||
@Composable | ||
internal fun CustomTheme(content: @Composable () -> Unit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted from CreditCardInputView
to make it reusable
} | ||
|
||
@Composable | ||
internal fun customPlaceholderTexts() = PlaceholderDefaults.texts( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just to provide different placeholder texts than defaults to see that the user can customize them
import androidx.compose.ui.text.font.FontStyle | ||
|
||
@Composable | ||
internal fun SupportingText(text: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple component to wrap the supporting text (below the title in the ListItem
) to make the NavigationGraph
easier to read and maintain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
Why
In this PR we have added customization options for the placeholders, labels and the input text field (look and feel).
The PR is pretty big, but the improvements are significant for future ease of maintenance.
Some parts of the changes are just extracting code into separate files/classes so that takes a significant part of the total LOC.
For easier review, I have commented on the code that was just extracted and does not need any additional review.
How
Many improvements have been made, so here is a bullet list:
Created 2 new constructors (
InlinePaymentCard
andRowsPaymentCard
) to separate layouts and make it easier for the users to use default and row implementations (these return the newPaymentCardData
introduced in the previous PR). These new constructors do not accept the layout and the implementation is hidden from the users as the component already provides the expected layout. This also makes the specific default inline and row implementations scalable. In the future they can expand independently without bloating the API with unnecessary parameters that are not needed for both layouts. It also follows the Compose guidelines of creating specific constructors for different implementations of the underlying specific components.The previously created
PaymentCardComponent
has been renamed to simplePaymentCard
as it should be the default constructor for the custom layouts for the users. If you feel that this needs to be changed I am open to suggestions.Added new classes and builders to provide defaults for placeholders and labels
User custom placeholder texts can now be provided to all component implementations (we provide the defaults that can be overridden)
Added new input components to the interface and implementation that accept label and placeholder Composables so the users have the ability to add any kind of Composables and customize them as much as they need
Added
TextFieldColors
parameter and support to the new input components so the user can customize the input look and feel as they wantCreated a new
CustomTextField
that works together with the above-mentioned inputs with Composables.Added many samples of the components and their usage, both inside the lib module (as Previews) and in the sample app
We also took the opportunity to clean up a little bit the code:
Final notes:
Samples