Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar Desktop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
Briar Desktop
Commits
3fc232c3
Commit
3fc232c3
authored
2 years ago
by
paul
Browse files
Options
Downloads
Patches
Plain Diff
Add trailing clear button, and support for ESC key
parent
bae30e39
No related branches found
Branches containing commit
No related tags found
1 merge request
!209
Update Conversation Search to Material Spec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/ui/SearchTextField.kt
+44
-7
44 additions, 7 deletions
...tlin/org/briarproject/briar/desktop/ui/SearchTextField.kt
with
44 additions
and
7 deletions
briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/ui/SearchTextField.kt
+
44
−
7
View file @
3fc232c3
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
package
org.briarproject.briar.desktop.ui
package
org.briarproject.briar.desktop.ui
import
androidx.compose.animation.Crossfade
import
androidx.compose.animation.Crossfade
import
androidx.compose.animation.core.tween
import
androidx.compose.foundation.layout.Arrangement
import
androidx.compose.foundation.layout.Arrangement
import
androidx.compose.foundation.layout.Box
import
androidx.compose.foundation.layout.Box
import
androidx.compose.foundation.layout.Row
import
androidx.compose.foundation.layout.Row
...
@@ -37,20 +38,35 @@ import androidx.compose.material.TextField
...
@@ -37,20 +38,35 @@ import androidx.compose.material.TextField
import
androidx.compose.material.TextFieldDefaults
import
androidx.compose.material.TextFieldDefaults
import
androidx.compose.material.icons.Icons
import
androidx.compose.material.icons.Icons
import
androidx.compose.material.icons.filled.ArrowBack
import
androidx.compose.material.icons.filled.ArrowBack
import
androidx.compose.material.icons.filled.Cancel
import
androidx.compose.material.icons.filled.Close
import
androidx.compose.material.icons.filled.Search
import
androidx.compose.material.icons.filled.Search
import
androidx.compose.runtime.Composable
import
androidx.compose.runtime.Composable
import
androidx.compose.runtime.LaunchedEffect
import
androidx.compose.runtime.LaunchedEffect
import
androidx.compose.runtime.mutableStateOf
import
androidx.compose.runtime.mutableStateOf
import
androidx.compose.runtime.remember
import
androidx.compose.runtime.remember
import
androidx.compose.runtime.rememberCoroutineScope
import
androidx.compose.ui.Alignment
import
androidx.compose.ui.Alignment
import
androidx.compose.ui.ExperimentalComposeUiApi
import
androidx.compose.ui.ExperimentalComposeUiApi
import
androidx.compose.ui.Modifier
import
androidx.compose.ui.Modifier
import
androidx.compose.ui.focus.FocusRequester
import
androidx.compose.ui.focus.FocusRequester
import
androidx.compose.ui.focus.focusRequester
import
androidx.compose.ui.focus.focusRequester
import
androidx.compose.ui.graphics.vector.ImageVector
import
androidx.compose.ui.graphics.vector.ImageVector
import
androidx.compose.ui.input.key.Key
import
androidx.compose.ui.input.key.key
import
androidx.compose.ui.input.key.onKeyEvent
import
androidx.compose.ui.input.pointer.PointerIconDefaults
import
androidx.compose.ui.input.pointer.PointerIconDefaults
import
androidx.compose.ui.input.pointer.pointerHoverIcon
import
androidx.compose.ui.input.pointer.pointerHoverIcon
import
androidx.compose.ui.platform.LocalFocusManager
import
androidx.compose.ui.unit.dp
import
androidx.compose.ui.unit.dp
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.coroutineScope
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.job
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.runBlocking
import
kotlinx.coroutines.runInterruptible
import
org.briarproject.briar.desktop.theme.surfaceVariant
import
org.briarproject.briar.desktop.theme.surfaceVariant
import
org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
import
org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
...
@@ -138,6 +154,13 @@ fun SearchInput(
...
@@ -138,6 +154,13 @@ fun SearchInput(
onBack
:
()
->
Unit
,
onBack
:
()
->
Unit
,
)
{
)
{
val
focusRequester
=
remember
{
FocusRequester
()
}
val
focusRequester
=
remember
{
FocusRequester
()
}
val
focusManager
=
LocalFocusManager
.
current
fun
endSearch
()
{
onValueChange
(
""
)
focusManager
.
clearFocus
(
true
)
onBack
()
}
TextField
(
TextField
(
value
=
searchValue
,
value
=
searchValue
,
onValueChange
=
onValueChange
,
onValueChange
=
onValueChange
,
...
@@ -150,19 +173,33 @@ fun SearchInput(
...
@@ -150,19 +173,33 @@ fun SearchInput(
colors
=
TextFieldDefaults
.
textFieldColors
(
backgroundColor
=
MaterialTheme
.
colors
.
surfaceVariant
),
colors
=
TextFieldDefaults
.
textFieldColors
(
backgroundColor
=
MaterialTheme
.
colors
.
surfaceVariant
),
leadingIcon
=
{
leadingIcon
=
{
IconButton
(
IconButton
(
{
{
endSearch
()
},
focusRequester
.
freeFocus
()
onValueChange
(
""
)
onBack
()
},
Modifier
.
padding
(
start
=
20
.
dp
,
end
=
16
.
dp
).
size
(
24
.
dp
).
pointerHoverIcon
(
PointerIconDefaults
.
Default
)
Modifier
.
padding
(
start
=
20
.
dp
,
end
=
16
.
dp
).
size
(
24
.
dp
).
pointerHoverIcon
(
PointerIconDefaults
.
Default
)
)
{
)
{
Icon
(
Icons
.
Filled
.
ArrowBack
,
i18n
(
"access.contacts.search"
))
Icon
(
Icons
.
Filled
.
ArrowBack
,
i18n
(
"access.contacts.search"
))
}
}
},
},
modifier
=
Modifier
.
fillMaxSize
().
focusRequester
(
focusRequester
)
trailingIcon
=
{
if
(
searchValue
.
isNotEmpty
())
{
IconButton
(
{
onValueChange
(
""
)
focusRequester
.
requestFocus
()
},
Modifier
.
size
(
24
.
dp
).
pointerHoverIcon
(
PointerIconDefaults
.
Default
)
)
{
Icon
(
Icons
.
Filled
.
Close
,
"clear search text"
)
}
}
},
modifier
=
Modifier
.
fillMaxSize
().
focusRequester
(
focusRequester
).
onKeyEvent
{
if
(
it
.
key
==
Key
.
Escape
)
{
endSearch
()
}
true
}
)
)
LaunchedEffect
(
Unit
)
{
LaunchedEffect
(
Unit
)
{
focusRequester
.
requestFocus
()
this
.
coroutineContext
.
job
.
invokeOnCompletion
{
focusRequester
.
requestFocus
()
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment