11import { Toolbar } from "../../components/ui/Toolbar" ;
22import { useFocusEffect , useNavigation } from "@react-navigation/native" ;
3- import { use , useCallback , useEffect , useRef } from "react" ;
4- import { Platform } from "react-native" ;
3+ import { use , useCallback , useEffect , useRef , type ReactNode } from "react" ;
4+ import { Platform , Pressable , type TextInputInstance } from "react-native" ;
5+ import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller" ;
6+ import Animated , { useAnimatedStyle } from "react-native-reanimated" ;
7+ import { useSafeAreaInsets } from "react-native-safe-area-context" ;
58import { isDuoDevice } from "../../lib/device-type" ;
69import { useDeviceType } from "../../native/native-layout-metrics" ;
710import type { SearchBarCommands } from "react-native-screens" ;
811
12+ import { SymbolView } from "../../components/ui/AppSymbol" ;
13+ import { GlassSurface } from "../../components/ui/GlassSurface" ;
914import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass" ;
1015import { NativeStackScreenOptions } from "../../native/StackHeader" ;
1116import { NativeWorkspaceTabActivityContext } from "../../native/v5-workspace-context" ;
1217import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands" ;
1318import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout" ;
1419import { useWorkspaceTabs } from "./WorkspaceTabsContext" ;
20+ import { WorkspaceSearchField } from "./WorkspaceSearchField" ;
21+ import { WORKSPACE_TOOLBAR } from "./workspace-tabs-state" ;
1522import { useSidebarWorkspaceTabs } from "./useSystemWorkspaceTabBar" ;
1623import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab" ;
1724import { useMobileNavigationTheme } from "../../lib/useMobileNavigationTheme" ;
1825
1926// Tabler's git-pull-request geometry, shared with the UIKit tab bar.
2027const PULL_REQUEST_ICON = require ( "../../../assets/icons/pull-request.png" ) ;
2128
29+ /**
30+ * Rises once the keyboard reaches its content. UIKit also reports keyboards without height, with a
31+ * hardware keyboard and around a fold, and those must not move it.
32+ */
33+ function AboveKeyboard ( props : { readonly bottom : number ; readonly children : ReactNode } ) {
34+ const keyboard = useReanimatedKeyboardAnimation ( ) ;
35+ const { bottom } = props ;
36+ const lift = useAnimatedStyle ( ( ) => ( {
37+ transform : [ { translateY : Math . min ( 0 , keyboard . height . value + bottom - 8 ) } ] ,
38+ } ) ) ;
39+ return (
40+ < Animated . View
41+ pointerEvents = "box-none"
42+ className = "absolute inset-x-0 bottom-0 flex-row items-center"
43+ style = { [
44+ {
45+ gap : WORKSPACE_TOOLBAR . gap ,
46+ paddingHorizontal : WORKSPACE_TOOLBAR . edge ,
47+ paddingBottom : bottom ,
48+ } ,
49+ lift ,
50+ ] }
51+ >
52+ { props . children }
53+ </ Animated . View >
54+ ) ;
55+ }
56+
2257export function WorkspaceToolbar ( props : {
2358 readonly onNewTask : ( ) => void ;
2459 readonly sidebar ?: boolean ;
@@ -35,16 +70,16 @@ export function WorkspaceToolbar(props: {
3570 ( isDuoDevice ( deviceType )
3671 ? deviceType === "duo-folded" && workspace . state . selectedTab === "threads"
3772 : deviceType === "pad" ) ;
38- // The expanded Duo sidebar keeps a full search field in its bottom toolbar. UIKit holds the
39- // integrated field there, but moves the button form into the detail column's vertical bar.
40- // Folded, the workspace tab bar owns the bottom of the vertical bar, so search keeps UIKit's
41- // own placement.
42- const toolbarSearch =
43- NATIVE_LIQUID_GLASS_SUPPORTED && deviceType === "duo-unfolded" && props . sidebar === true ;
73+ // The Duo searches from a field at the bottom of the list in every pose. UIKit has no such
74+ // placement once the vertical bar holds the toolbar, and re-placing its search controller on
75+ // each fold replaces the search field.
76+ const listSearch = isDuoDevice ( deviceType ) ;
77+ const insets = useSafeAreaInsets ( ) ;
4478 const { isTabActive } = workspace ;
4579 const tabActive = use ( NativeWorkspaceTabActivityContext ) ?. active ?? true ;
4680 const { panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout ( ) ;
4781 const searchRef = useRef < SearchBarCommands > ( null ) ;
82+ const fieldRef = useRef < TextInputInstance > ( null ) ;
4883 const tab = workspace . state . tabs [ workspace . state . selectedTab ] ;
4984 const selectedTab = workspace . state . selectedTab ;
5085 const enterSearch = useCallback ( ( ) => {
@@ -58,10 +93,25 @@ export function WorkspaceToolbar(props: {
5893 } , [ workspace , selectedTab , props . sidebar , panes . primarySidebarVisible , togglePrimarySidebar ] ) ;
5994 const focusSearch = useCallback ( ( ) => {
6095 if ( ! workspace . isTabActive ( selectedTab ) ) return false ;
96+ if ( listSearch ) {
97+ fieldRef . current ?. focus ( ) ;
98+ return true ;
99+ }
61100 if ( ! NATIVE_LIQUID_GLASS_SUPPORTED ) enterSearch ( ) ;
62101 searchRef . current ?. focus ( ) ;
63102 return true ;
64- } , [ workspace , selectedTab , enterSearch ] ) ;
103+ } , [ workspace , selectedTab , listSearch , enterSearch ] ) ;
104+ const cancelSearch = useCallback ( ( ) => {
105+ workspace . recordScrollOffset ( selectedTab , tab . searchEntryOffset ) ;
106+ workspace . dispatch ( { type : "cancel" , tab : selectedTab } ) ;
107+ } , [ workspace , selectedTab , tab . searchEntryOffset ] ) ;
108+ const searchFocused = useCallback (
109+ ( ) =>
110+ tab . searchMode === "resting"
111+ ? enterSearch ( )
112+ : workspace . dispatch ( { type : "search" , tab : selectedTab } ) ,
113+ [ tab . searchMode , enterSearch , workspace , selectedTab ] ,
114+ ) ;
65115 useHardwareKeyboardCommand ( "focusSearch" , focusSearch ) ;
66116 const restoreSearch = useCallback ( ( ) => {
67117 if ( isTabActive ( selectedTab ) && tab . searchMode !== "resting" )
@@ -86,30 +136,20 @@ export function WorkspaceToolbar(props: {
86136 // Liquid Glass keeps search mounted as UIKit's own header button, which
87137 // morphs into the field; swapping a stacked bar in and out cannot animate.
88138 headerSearchBarOptions :
89- NATIVE_LIQUID_GLASS_SUPPORTED || tab . searchMode !== "resting"
139+ ! listSearch && ( NATIVE_LIQUID_GLASS_SUPPORTED || tab . searchMode !== "resting" )
90140 ? {
91141 ref : searchRef ,
92142 autoFocus : tab . searchMode === "active" ,
93143 autoCapitalize : "none" ,
94144 hideNavigationBar : false ,
95145 hideWhenScrolling : false ,
96146 obscureBackground : false ,
97- placement : toolbarSearch
98- ? "integrated"
99- : NATIVE_LIQUID_GLASS_SUPPORTED
100- ? "integratedButton"
101- : "stacked" ,
102- // Folded, the tab bar owns the bottom of the vertical bar; refusing toolbar
103- // integration also makes UIKit re-place a visible search in the navigation bar.
104- allowToolbarIntegration :
105- NATIVE_LIQUID_GLASS_SUPPORTED && deviceType !== "duo-folded" ,
147+ placement : NATIVE_LIQUID_GLASS_SUPPORTED ? "integratedButton" : "stacked" ,
148+ allowToolbarIntegration : NATIVE_LIQUID_GLASS_SUPPORTED ,
106149 placeholder :
107150 selectedTab === "pullRequests" ? "Search pull requests" : "Search threads" ,
108151 cancelButtonText : "✕" ,
109- onFocus : ( ) =>
110- tab . searchMode === "resting"
111- ? enterSearch ( )
112- : workspace . dispatch ( { type : "search" , tab : selectedTab } ) ,
152+ onFocus : searchFocused ,
113153 onBlur : ( ) => workspace . dispatch ( { type : "expand" , tab : selectedTab } ) ,
114154 onSearchButtonPress : ( ) => searchRef . current ?. blur ( ) ,
115155 onChangeText : ( { nativeEvent } ) =>
@@ -118,10 +158,7 @@ export function WorkspaceToolbar(props: {
118158 query : nativeEvent . text ,
119159 tab : selectedTab ,
120160 } ) ,
121- onCancelButtonPress : ( ) => {
122- workspace . recordScrollOffset ( selectedTab , tab . searchEntryOffset ) ;
123- workspace . dispatch ( { type : "cancel" , tab : selectedTab } ) ;
124- } ,
161+ onCancelButtonPress : cancelSearch ,
125162 }
126163 : undefined ,
127164 } }
@@ -168,7 +205,6 @@ export function WorkspaceToolbar(props: {
168205 />
169206 ) : null }
170207 { nativeToolbarCompose ? < Toolbar . Spacer flexible /> : null }
171- { toolbarSearch ? < Toolbar . SearchBarSlot /> : null }
172208 { nativeToolbarCompose ? (
173209 < Toolbar . Button
174210 identifier = "workspace-compose"
@@ -179,6 +215,45 @@ export function WorkspaceToolbar(props: {
179215 />
180216 ) : null }
181217 </ Toolbar >
218+ { listSearch ? (
219+ < AboveKeyboard bottom = { Math . max ( insets . bottom , 12 ) } >
220+ < WorkspaceSearchField
221+ ref = { fieldRef }
222+ tab = { selectedTab }
223+ query = { tab . query }
224+ onChangeQuery = { ( query ) =>
225+ workspace . dispatch ( { type : "query" , query, tab : selectedTab } )
226+ }
227+ onFocus = { searchFocused }
228+ onBlur = { ( ) => workspace . dispatch ( { type : "expand" , tab : selectedTab } ) }
229+ onClear = { ( ) => {
230+ workspace . dispatch ( { type : "query" , query : "" , tab : selectedTab } ) ;
231+ fieldRef . current ?. focus ( ) ;
232+ } }
233+ />
234+ { tab . searchMode === "resting" ? null : (
235+ < GlassSurface
236+ style = { {
237+ width : WORKSPACE_TOOLBAR . height ,
238+ height : WORKSPACE_TOOLBAR . height ,
239+ borderRadius : WORKSPACE_TOOLBAR . height / 2 ,
240+ } }
241+ >
242+ < Pressable
243+ accessibilityRole = "button"
244+ accessibilityLabel = "Cancel search"
245+ onPress = { ( ) => {
246+ cancelSearch ( ) ;
247+ fieldRef . current ?. blur ( ) ;
248+ } }
249+ className = "flex-1 items-center justify-center"
250+ >
251+ < SymbolView name = "xmark" size = { 20 } tintColorClassName = "accent-icon" />
252+ </ Pressable >
253+ </ GlassSurface >
254+ ) }
255+ </ AboveKeyboard >
256+ ) : null }
182257 </ >
183258 ) ;
184259}
0 commit comments