Skip to content
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

Merged
merged 32 commits into from
Oct 27, 2023

Conversation

adnanjelic
Copy link
Contributor

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:

  1. Created 2 new constructors (InlinePaymentCard and RowsPaymentCard) to separate layouts and make it easier for the users to use default and row implementations (these return the new PaymentCardData 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.

  2. The previously created PaymentCardComponent has been renamed to simple PaymentCard 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.

  3. Added new classes and builders to provide defaults for placeholders and labels

  4. User custom placeholder texts can now be provided to all component implementations (we provide the defaults that can be overridden)

  5. 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

  6. Added TextFieldColors parameter and support to the new input components so the user can customize the input look and feel as they want

  7. Created a new CustomTextField that works together with the above-mentioned inputs with Composables.

  8. Added many samples of the components and their usage, both inside the lib module (as Previews) and in the sample app

  9. We also took the opportunity to clean up a little bit the code:

    • Better code/class structuring
    • Got rid of "god" classes that had mixed-up code by extracting parts of the code to other SRP classes/files smaller for better maintainability and reusability

Final notes:

  • The changes are done so the existing API users are not affected.
  • No current API name or signature is changed
  • If we needed to add something to the existing constructors, we overloaded them not to change any method/constructor signature.
  • The users are not forced and can switch to use the new components whenever they feel to (to use the Composables instead of simple configurations for example.)

Samples

Sample app update Samples in the lib Samples in the lib
image image image

@changeset-bot
Copy link

changeset-bot bot commented Oct 27, 2023

⚠️ No Changeset found

Latest commit: ceafaae

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines +18 to +20
@Composable
fun inlinePaymentCardInputLayout(): @Composable() (PaymentCardInputScope.(Modifier) -> Unit) =
{ inline(modifier = it) }
Copy link
Contributor Author

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) =
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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(
Copy link
Contributor Author

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(
Copy link
Contributor Author

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(
Copy link
Contributor Author

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(
Copy link
Contributor Author

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(
Copy link
Contributor Author

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(
Copy link
Contributor Author

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(
Copy link
Contributor Author

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(
Copy link
Contributor Author

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) =
Copy link
Contributor Author

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) =
Copy link
Contributor Author

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(
Copy link
Contributor Author

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
Copy link
Contributor Author

@adnanjelic adnanjelic Oct 27, 2023

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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(
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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

Copy link
Contributor

@boilsquid boilsquid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@adnanjelic adnanjelic merged commit cd86117 into main Oct 27, 2023
4 checks passed
@adnanjelic adnanjelic deleted the adnan/add-placeholder-and-label-customization branch October 27, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants