Skip to content

refactor: split SearchBar into stateless and stateful components (#86)#87

Merged
komodgn merged 1 commit intodevelopfrom
refactor/#86
Jan 19, 2026
Merged

refactor: split SearchBar into stateless and stateful components (#86)#87
komodgn merged 1 commit intodevelopfrom
refactor/#86

Conversation

@komodgn
Copy link
Owner

@komodgn komodgn commented Jan 19, 2026

  • Create MetaSearchSearchBar as a reusable stateless component
  • Implement state hoisting for NLSearchTextField to improve encapsulation
  • Optimize rendering performance by isolating recomposition scope

Summary by CodeRabbit

New Features

  • Introduced a new reusable search bar component featuring a text input field with customizable placeholder text, search icon button, and rounded styling. Supports keyboard search actions for direct submission.

Refactor

  • Consolidated search input field updates and search action triggering into a single unified interaction model, streamlining the search workflow.

✏️ Tip: You can customize this high-level summary in your review settings.

Verification

Before (Full Recomposition) After (Isolated Recomposition)

- Create MetaSearchSearchBar as a reusable stateless component
- Implement state hoisting for NLSearchTextField to improve encapsulation
- Optimize rendering performance by isolating recomposition scope
@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new reusable MetaSearchSearchBar Compose component and refactors the NLSearchTextField to use it. The event handling flow is consolidated from separate input-change and search callbacks into a single search action that emits both events sequentially.

Changes

Cohort / File(s) Summary
New Search Bar Component
core/ui/src/main/java/com/metasearch/android/core/ui/component/MetaSearchSearchBar.kt
New public top-level Compose function providing a reusable full-width search bar with bordered rounded container, BasicTextField with placeholder, and clickable search icon. Triggers onSearchClick on both keyboard search action and icon click.
Search TextField Integration
feature/search/src/main/java/com/metasearch/android/feature/search/nls/component/NLSearchTextField.kt
Replaced custom-composed text field UI with MetaSearchSearchBar component. API signature changed: removed onInputChange parameter, changed onSearchClick from () -> Unit to (String) -> Unit. Added local input state management via remember and mutableStateOf.
Search Event Handling
feature/search/src/main/java/com/metasearch/android/feature/search/nls/NLSearchUi.kt
Consolidated input-update and search-trigger flow: single onSearchClick callback now accepts lastInput parameter and emits two sequential events (OnInputChange followed by OnNLSearchClick). Removed separate onInputChange handler.
Presenter Event Processing
feature/search/src/main/java/com/metasearch/android/feature/search/nls/NLSearchPresenter.kt
Updated NLSearchUiEvent.OnNLSearchClick handling to assign inputString from the event before validation, ensuring the blank check and search logic operate on the provided value.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A search bar born, reusable and bright,
Events consolidated with all their might,
One click, two flows—so coordinated,
The UI refactored, greatly liberated!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of splitting a search bar component into stateless and stateful parts, which is demonstrated across the changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@core/ui/src/main/java/com/metasearch/android/core/ui/component/MetaSearchSearchBar.kt`:
- Around line 75-89: The Icon in MetaSearchSearchBar.kt uses a hardcoded
contentDescription ("Search Icon"); extract this to a string resource and
reference it via stringResource in the composable. Add a string entry (e.g.
name="search_icon_content_description" value="Search") to your module's
strings.xml and replace the hardcoded contentDescription in the Icon call with
stringResource(R.string.search_icon_content_description) (keep the Icon,
onSearchClick, and Modifier usage unchanged).

Comment on lines +75 to +89
Icon(
painter = painterResource(R.drawable.ic_search_line),
contentDescription = "Search Icon",
modifier = Modifier
.size(
MetaSearchTheme.spacing.spacing6,
)
.clickable(
indication = null,
interactionSource = remember { MutableInteractionSource() },
) {
onSearchClick()
},
tint = Neutral500,
)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Hardcoded content description should be a string resource.

The contentDescription = "Search Icon" on line 77 should be extracted to a string resource for proper internationalization support.

Suggested fix
         Icon(
             painter = painterResource(R.drawable.ic_search_line),
-            contentDescription = "Search Icon",
+            contentDescription = stringResource(R.string.search_icon_content_description),
             modifier = Modifier

Add the corresponding string resource in core/ui/src/main/res/values/strings.xml:

<string name="search_icon_content_description">Search</string>
🤖 Prompt for AI Agents
In
`@core/ui/src/main/java/com/metasearch/android/core/ui/component/MetaSearchSearchBar.kt`
around lines 75 - 89, The Icon in MetaSearchSearchBar.kt uses a hardcoded
contentDescription ("Search Icon"); extract this to a string resource and
reference it via stringResource in the composable. Add a string entry (e.g.
name="search_icon_content_description" value="Search") to your module's
strings.xml and replace the hardcoded contentDescription in the Icon call with
stringResource(R.string.search_icon_content_description) (keep the Icon,
onSearchClick, and Modifier usage unchanged).

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🤖 Android CI Summary

Step Results:

  • Unit Test: ✅ Success (3m 6s)
  • Debug Build: ✅ Success (1m 14s)
  • Code Style Check: ✅ Success (4m 25s)

Total Time: 8m 45s

🎉 All steps completed successfully!

@komodgn komodgn merged commit d437bf5 into develop Jan 19, 2026
2 checks passed
@komodgn komodgn deleted the refactor/#86 branch January 19, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments