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

fix: fixed issue not activating search on long click in search bar [WPB-2231] #2353

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ package com.wire.android.ui.common.topappbar.search
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalTextStyle
Expand All @@ -39,6 +41,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -49,6 +54,7 @@ import com.wire.android.R
import com.wire.android.ui.common.SearchBarInput
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireDimensions

@OptIn(ExperimentalAnimationApi::class)
@Composable
Expand All @@ -72,51 +78,59 @@ fun SearchTopBar(
}

val focusManager = LocalFocusManager.current
val focusRequester = remember { FocusRequester() }

LaunchedEffect(isSearchActive) {
if (!isSearchActive) {
focusManager.clearFocus()
onSearchQueryChanged(TextFieldValue(""))
} else {
focusRequester.requestFocus()
}
}

SearchBarInput(
placeholderText = searchBarHint,
text = searchQuery,
onTextTyped = onSearchQueryChanged,
leadingIcon = {
AnimatedContent(!isSearchActive) { isVisible ->
IconButton(onClick = {
if (!isVisible) {
onCloseSearchClicked()
Box {
SearchBarInput(
placeholderText = searchBarHint,
text = searchQuery,
onTextTyped = onSearchQueryChanged,
leadingIcon = {
AnimatedContent(!isSearchActive, label = "") { isVisible ->
IconButton(onClick = {
if (!isVisible) {
onCloseSearchClicked()
}
}) {
Icon(
painter = painterResource(
id = if (isVisible) R.drawable.ic_search
else R.drawable.ic_arrow_left
),
contentDescription = stringResource(R.string.content_description_conversation_search_icon),
tint = MaterialTheme.wireColorScheme.onBackground
)
}
}) {
Icon(
painter = painterResource(
id = if (isVisible) R.drawable.ic_search
else R.drawable.ic_arrow_left
),
contentDescription = stringResource(R.string.content_description_conversation_search_icon),
tint = MaterialTheme.wireColorScheme.onBackground
)
}
}
},
placeholderTextStyle = textStyleAlignment(isTopBarVisible = !isSearchActive),
textStyle = textStyleAlignment(isTopBarVisible = !isSearchActive),
interactionSource = interactionSource,
modifier = Modifier.padding(dimensions().spacing8x)
)

if (interactionSource.collectIsPressedAsState().value) {
// we want to propagate the click on the input of the search
// only the first time the user clicks on the input
// that is when the search is not active
},
placeholderTextStyle = textStyleAlignment(isTopBarVisible = !isSearchActive),
textStyle = textStyleAlignment(isTopBarVisible = !isSearchActive),
interactionSource = interactionSource,
modifier = Modifier
.padding(dimensions().spacing8x)
.focusRequester(focusRequester)
)
// We added an invisible clickable box only present when the search is not active.
// That way we can still make the whole top bar clickable and intercept and discard the long press gestures.
if (!isSearchActive) {
onInputClicked()
Box(
modifier = Modifier
.matchParentSize()
.padding(dimensions().spacing8x)
.clip(RoundedCornerShape(MaterialTheme.wireDimensions.textFieldCornerSize))
.clickable(onClick = onInputClicked)
)
}
}

bottomContent()
}
}
Expand Down
Loading