Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions android/src/main/java/com/tailscale/ipn/ui/view/MainView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,8 @@ fun PeerList(
var isListFocussed by remember { mutableStateOf(false) }
val expandedPeer = viewModel.expandedMenuPeer.collectAsState()
val localClipboardManager = LocalClipboardManager.current
// Restrict search to devices running API 33+ (see https://github.com/tailscale/corp/issues/27375)
val enableSearch = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
Column(modifier = Modifier.fillMaxSize()) {
if (enableSearch && FeatureFlags.isEnabled("enable_new_search")) {
if (FeatureFlags.isEnabled("enable_new_search")) {
Search(onSearchBarClick)
} else {
if (!isAndroidTV()) {
Expand Down
19 changes: 3 additions & 16 deletions android/src/main/java/com/tailscale/ipn/ui/view/SearchView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

package com.tailscale.ipn.ui.view

import android.app.Activity
import android.os.Build
import android.window.OnBackInvokedCallback
import android.window.OnBackInvokedDispatcher
import androidx.annotation.RequiresApi
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
Expand All @@ -33,7 +29,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SearchBar
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand All @@ -45,7 +40,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
Expand All @@ -60,7 +55,6 @@ import com.tailscale.ipn.ui.util.Lists
import com.tailscale.ipn.ui.viewModel.MainViewModel
import kotlinx.coroutines.delay

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SearchView(
Expand All @@ -80,7 +74,6 @@ fun SearchView(
val focusRequester = remember { FocusRequester() }
val focusManager = LocalFocusManager.current
var expanded by rememberSaveable { mutableStateOf(true) }
val context = LocalContext.current as Activity
val listState = rememberLazyListState()

val noResultsBackground =
Expand All @@ -90,19 +83,13 @@ fun SearchView(
MaterialTheme.colorScheme.surfaceContainer // color for light mode
}

val callback = OnBackInvokedCallback {
BackHandler {
focusManager.clearFocus(force = true)
keyboardController?.hide()
onNavigateBack()
viewModel.updateSearchTerm("")
}

DisposableEffect(Unit) {
val dispatcher = context.onBackInvokedDispatcher
dispatcher?.registerOnBackInvokedCallback(OnBackInvokedDispatcher.PRIORITY_DEFAULT, callback)
onDispose { dispatcher?.unregisterOnBackInvokedCallback(callback) }
}

LaunchedEffect(searchTerm, filteredPeers) {
if (searchTerm.isEmpty() && filteredPeers.isNotEmpty()) {
delay(100) // Give Compose time to update list
Expand Down