-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Compose: Add DaxTextField #7247
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
Open
landomen
wants to merge
14
commits into
develop
Choose a base branch
from
feature/domen/compose-text-field
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,613
−18
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
72466a6
WIP: compose text field
landomen 80381b6
Finalize component
landomen 62a6b0f
Finalize component
landomen 6759260
Add previews
landomen 7398c5d
Revert DaxText change
landomen a87aa84
Remove unused color
landomen 942f070
Fix code formatting
landomen bf70752
Fix lint issue
landomen b08866a
Refactor based on feedback
landomen 2e25a24
Remove unused press listener
landomen 95e4b1b
Lift password state
landomen 70786de
Add new lint detector
landomen 1c7d88b
Update implementation
landomen 33aa9f1
Fix rebase issues
landomen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
485 changes: 485 additions & 0 deletions
485
...va/com/duckduckgo/common/ui/internal/ui/component/textinput/ComponentTextInputFragment.kt
Large diffs are not rendered by default.
Oops, something went wrong.
658 changes: 640 additions & 18 deletions
658
...id-design-system/design-system-internal/src/main/res/layout/component_text_input_view.xml
Large diffs are not rendered by default.
Oops, something went wrong.
476 changes: 476 additions & 0 deletions
476
...ign-system/src/main/java/com/duckduckgo/common/ui/compose/textfield/DaxSecureTextField.kt
Large diffs are not rendered by default.
Oops, something went wrong.
542 changes: 542 additions & 0 deletions
542
...em/design-system/src/main/java/com/duckduckgo/common/ui/compose/textfield/DaxTextField.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
133
lint-rules/src/main/java/com/duckduckgo/lint/ui/DaxSecureTextFieldTrailingIconDetector.kt
This file contains hidden or 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,133 @@ | ||
| /* | ||
| * Copyright (c) 2025 DuckDuckGo | ||
| * | ||
| * 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 com.duckduckgo.lint.ui | ||
|
|
||
| import com.android.tools.lint.client.api.UElementHandler | ||
| import com.android.tools.lint.detector.api.Category.Companion.CUSTOM_LINT_CHECKS | ||
| import com.android.tools.lint.detector.api.Detector | ||
| import com.android.tools.lint.detector.api.Implementation | ||
| import com.android.tools.lint.detector.api.Issue | ||
| import com.android.tools.lint.detector.api.JavaContext | ||
| import com.android.tools.lint.detector.api.Scope | ||
| import com.android.tools.lint.detector.api.Severity | ||
| import com.android.tools.lint.detector.api.SourceCodeScanner | ||
| import com.android.tools.lint.detector.api.TextFormat | ||
| import org.jetbrains.uast.UCallExpression | ||
| import org.jetbrains.uast.getParameterForArgument | ||
| import java.util.EnumSet | ||
|
|
||
| @Suppress("UnstableApiUsage") | ||
| class DaxSecureTextFieldTrailingIconDetector : Detector(), SourceCodeScanner { | ||
|
|
||
| override fun getApplicableUastTypes() = listOf(UCallExpression::class.java) | ||
|
|
||
| override fun createUastHandler(context: JavaContext): UElementHandler = DaxSecureTextFieldCallHandler(context) | ||
|
|
||
| internal class DaxSecureTextFieldCallHandler(private val context: JavaContext) : UElementHandler() { | ||
|
|
||
| private val validTrailingIconMembers: List<String> by lazy { | ||
| getTrailingIconScopeMembers() | ||
| } | ||
|
|
||
| override fun visitCallExpression(node: UCallExpression) { | ||
| val methodName = node.methodName | ||
|
|
||
| if (methodName == "DaxSecureTextField") { | ||
| checkTrailingIconParameter(node) | ||
| } | ||
| } | ||
|
|
||
| private fun checkTrailingIconParameter(node: UCallExpression) { | ||
| // Find the 'trailingIcon' parameter | ||
| val trailingIconArgument = node.valueArguments.find { arg -> | ||
| val parameterName = node.getParameterForArgument(arg)?.name | ||
| parameterName == "trailingIcon" | ||
| } ?: return // No 'trailingIcon' parameter provided which is fine | ||
|
|
||
| // Check if the trailingIcon uses an invalid composable | ||
| if (isInvalidComposable(trailingIconArgument)) { | ||
| reportInvalidComposableUsage(trailingIconArgument) | ||
| } | ||
| } | ||
|
|
||
| private fun getTrailingIconScopeMembers(): List<String> { | ||
| val scopeClass = context.evaluator.findClass(TRAILING_ICON_SCOPE_CLASS) | ||
| ?: return emptyList() | ||
|
|
||
| return scopeClass.methods | ||
| .filter { !it.isConstructor } | ||
| .mapNotNull { it.name } | ||
| } | ||
|
|
||
| private fun isInvalidComposable(argument: org.jetbrains.uast.UExpression): Boolean { | ||
| val source = argument.sourcePsi?.text ?: return false | ||
|
|
||
| // Check if the source contains any of the valid trailing icon members | ||
| // If the scope class couldn't be resolved, fall back to allowing the usage | ||
| if (validTrailingIconMembers.isEmpty()) return false | ||
|
|
||
| return validTrailingIconMembers.none { member -> source.contains(member) } | ||
| } | ||
|
|
||
| private fun reportInvalidComposableUsage(arg: org.jetbrains.uast.UExpression) { | ||
| context.report( | ||
| issue = INVALID_DAX_SECURE_TEXT_FIELD_TRAILING_ICON_USAGE, | ||
| location = context.getLocation(arg), | ||
| message = INVALID_DAX_SECURE_TEXT_FIELD_TRAILING_ICON_USAGE.getExplanation(TextFormat.RAW), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val TRAILING_ICON_SCOPE_CLASS = | ||
| "com.duckduckgo.common.ui.compose.textfield.DaxTextFieldTrailingIconScope" | ||
|
|
||
| val INVALID_DAX_SECURE_TEXT_FIELD_TRAILING_ICON_USAGE = Issue | ||
landomen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .create( | ||
| id = "InvalidDaxSecureTextFieldTrailingIconUsage", | ||
| briefDescription = "DaxSecureTextField trailingIcon parameter should only use composables from DaxTextFieldTrailingIconScope", | ||
| explanation = """ | ||
| Use composables from DaxTextFieldTrailingIconScope instead of arbitrary composables | ||
| for the trailingIcon parameter to maintain design system consistency. | ||
|
|
||
| Example: | ||
| DaxSecureTextField( | ||
| state = state, | ||
| isPasswordVisible = isPasswordVisible, | ||
| onShowHidePasswordIconClick = { /* toggle visibility */ }, | ||
| trailingIcon = { | ||
| DaxTextFieldTrailingIcon( | ||
| painter = painterResource(R.drawable.ic_copy_24), | ||
| contentDescription = stringResource(R.string.icon_description) | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| This ensures consistent styling, spacing, and behavior across all text field icons in the app. | ||
| """.trimIndent(), | ||
| moreInfo = "", | ||
| category = CUSTOM_LINT_CHECKS, | ||
| priority = 6, | ||
| severity = Severity.WARNING, | ||
| androidSpecific = true, | ||
| implementation = Implementation( | ||
| DaxSecureTextFieldTrailingIconDetector::class.java, | ||
| EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES), | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
131 changes: 131 additions & 0 deletions
131
lint-rules/src/main/java/com/duckduckgo/lint/ui/DaxTextFieldTrailingIconDetector.kt
This file contains hidden or 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,131 @@ | ||
| /* | ||
| * Copyright (c) 2025 DuckDuckGo | ||
| * | ||
| * 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 com.duckduckgo.lint.ui | ||
|
|
||
| import com.android.tools.lint.client.api.UElementHandler | ||
| import com.android.tools.lint.detector.api.Category.Companion.CUSTOM_LINT_CHECKS | ||
| import com.android.tools.lint.detector.api.Detector | ||
| import com.android.tools.lint.detector.api.Implementation | ||
| import com.android.tools.lint.detector.api.Issue | ||
| import com.android.tools.lint.detector.api.JavaContext | ||
| import com.android.tools.lint.detector.api.Scope | ||
| import com.android.tools.lint.detector.api.Severity | ||
| import com.android.tools.lint.detector.api.SourceCodeScanner | ||
| import com.android.tools.lint.detector.api.TextFormat | ||
| import org.jetbrains.uast.UCallExpression | ||
| import org.jetbrains.uast.getParameterForArgument | ||
| import java.util.EnumSet | ||
|
|
||
| @Suppress("UnstableApiUsage") | ||
| class DaxTextFieldTrailingIconDetector : Detector(), SourceCodeScanner { | ||
landomen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| override fun getApplicableUastTypes() = listOf(UCallExpression::class.java) | ||
|
|
||
| override fun createUastHandler(context: JavaContext): UElementHandler = DaxTextFieldCallHandler(context) | ||
|
|
||
| internal class DaxTextFieldCallHandler(private val context: JavaContext) : UElementHandler() { | ||
|
|
||
| private val validTrailingIconMembers: List<String> by lazy { | ||
| getTrailingIconScopeMembers() | ||
| } | ||
|
|
||
| override fun visitCallExpression(node: UCallExpression) { | ||
| val methodName = node.methodName | ||
|
|
||
| if (methodName == "DaxTextField") { | ||
| checkTrailingIconParameter(node) | ||
| } | ||
landomen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private fun checkTrailingIconParameter(node: UCallExpression) { | ||
| // Find the 'trailingIcon' parameter | ||
| val trailingIconArgument = node.valueArguments.find { arg -> | ||
| val parameterName = node.getParameterForArgument(arg)?.name | ||
| parameterName == "trailingIcon" | ||
| } ?: return // No 'trailingIcon' parameter provided which is fine | ||
|
|
||
| // Check if the trailingIcon uses an invalid composable | ||
| if (isInvalidComposable(trailingIconArgument)) { | ||
| reportInvalidComposableUsage(trailingIconArgument) | ||
| } | ||
| } | ||
|
|
||
| private fun getTrailingIconScopeMembers(): List<String> { | ||
| val scopeClass = context.evaluator.findClass(TRAILING_ICON_SCOPE_CLASS) | ||
| ?: return emptyList() | ||
|
|
||
| return scopeClass.methods | ||
| .filter { !it.isConstructor } | ||
| .mapNotNull { it.name } | ||
| } | ||
|
|
||
| private fun isInvalidComposable(argument: org.jetbrains.uast.UExpression): Boolean { | ||
| val source = argument.sourcePsi?.text ?: return false | ||
|
|
||
| // Check if the source contains any of the valid trailing icon members | ||
| // If the scope class couldn't be resolved, fall back to allowing the usage | ||
| if (validTrailingIconMembers.isEmpty()) return false | ||
|
|
||
| return validTrailingIconMembers.none { member -> source.contains(member) } | ||
| } | ||
|
|
||
| private fun reportInvalidComposableUsage(arg: org.jetbrains.uast.UExpression) { | ||
| context.report( | ||
| issue = INVALID_DAX_TEXT_FIELD_TRAILING_ICON_USAGE, | ||
| location = context.getLocation(arg), | ||
| message = INVALID_DAX_TEXT_FIELD_TRAILING_ICON_USAGE.getExplanation(TextFormat.RAW), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val TRAILING_ICON_SCOPE_CLASS = | ||
| "com.duckduckgo.common.ui.compose.textfield.DaxTextFieldTrailingIconScope" | ||
|
|
||
| val INVALID_DAX_TEXT_FIELD_TRAILING_ICON_USAGE = Issue | ||
| .create( | ||
| id = "InvalidDaxTextFieldTrailingIconUsage", | ||
| briefDescription = "DaxTextField trailingIcon parameter should only use composables from DaxTextFieldTrailingIconScope", | ||
| explanation = """ | ||
| Use composables from DaxTextFieldTrailingIconScope instead of arbitrary composables | ||
| for the trailingIcon parameter to maintain design system consistency. | ||
|
|
||
| Example: | ||
| DaxTextField( | ||
| state = state, | ||
| trailingIcon = { | ||
| DaxTextFieldTrailingIcon( | ||
| painter = painterResource(R.drawable.ic_copy_24), | ||
| contentDescription = stringResource(R.string.icon_description) | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| This ensures consistent styling, spacing, and behavior across all text field icons in the app. | ||
| """.trimIndent(), | ||
| moreInfo = "", | ||
| category = CUSTOM_LINT_CHECKS, | ||
| priority = 6, | ||
| severity = Severity.WARNING, | ||
| androidSpecific = true, | ||
| implementation = Implementation( | ||
| DaxTextFieldTrailingIconDetector::class.java, | ||
| EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES), | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.