Skip to content

Commit

Permalink
Change elements visibility on search bar open
Browse files Browse the repository at this point in the history
  • Loading branch information
tboba committed Sep 27, 2023
1 parent a87885b commit e08f528
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions android/src/main/java/com/swmansion/rnscreens/SearchBarView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ class SearchBarView(reactContext: ReactContext?) : ReactViewGroup(reactContext)

private var mAreListenersSet: Boolean = false

private val screenStackFragment: ScreenStackFragment?
private val headerConfig: ScreenStackHeaderConfig?
get() {
val currentParent = parent
if (currentParent is ScreenStackHeaderSubview) {
return currentParent.config?.screenFragment
return currentParent.config
}

return null
}

private val screenStackFragment: ScreenStackFragment?
get() = headerConfig?.screenFragment

fun onUpdate() {
setSearchViewProps()
}
Expand Down Expand Up @@ -110,10 +114,12 @@ class SearchBarView(reactContext: ReactContext?) : ReactViewGroup(reactContext)

private fun handleClose() {
sendEvent(SearchBarCloseEvent(surfaceId, id))
setToolbarElementsVisibility(VISIBLE)
}

private fun handleOpen() {
sendEvent(SearchBarOpenEvent(surfaceId, id))
setToolbarElementsVisibility(GONE)
}

private fun handleTextSubmit(newText: String?) {
Expand Down Expand Up @@ -144,6 +150,14 @@ class SearchBarView(reactContext: ReactContext?) : ReactViewGroup(reactContext)
text?.let { screenStackFragment?.searchView?.setText(it) }
}

private fun setToolbarElementsVisibility(visibility: Int) {
for (i in 0..(headerConfig?.configSubviewsCount?.minus(1) ?: 0)) {
val subview = headerConfig?.getConfigSubview(i)
if (subview?.type != ScreenStackHeaderSubview.Type.SEARCH_BAR)
subview?.visibility = visibility
}
}

private val surfaceId = UIManagerHelper.getSurfaceId(this)

enum class SearchBarAutoCapitalize {
Expand Down

0 comments on commit e08f528

Please sign in to comment.