@@ -13,7 +13,7 @@ type Suggestion = { id: string; name: string };
1313// `onPress` fires - so `setMention` would do nothing. Preventing the default
1414// mousedown keeps focus in the editor. It's a no-op on native, where tapping a
1515// Pressable never steals focus.
16- const keepEditorFocused : any =
16+ const keepEditorFocused : { onMouseDown : ( e : React . MouseEvent ) => void } | null =
1717 Platform . OS === 'web'
1818 ? { onMouseDown : ( e : { preventDefault ( ) : void } ) => e . preventDefault ( ) }
1919 : null ;
@@ -32,33 +32,17 @@ const CHANNELS: Suggestion[] = [
3232 { id : 'c4' , name : 'announcements' } ,
3333] ;
3434
35- // Each mention kind is styled by its indicator.
36- const htmlStyle : HtmlStyle = {
37- mention : {
38- '@' : {
39- color : '#2b7a4b' ,
40- backgroundColor : '#d8f3e3' ,
41- textDecorationLine : 'none' ,
42- } ,
43- '#' : {
44- color : '#2b5f9e' ,
45- backgroundColor : '#d8e6f9' ,
46- textDecorationLine : 'none' ,
47- } ,
48- } ,
49- } ;
50-
5135export default function App ( ) {
5236 const ref = useRef < EnrichedTextInputInstance > ( null ) ;
53- // The indicator of the mention being edited ('@' | '#'), or null when idle.
5437 const [ indicator , setIndicator ] = useState < string | null > ( null ) ;
5538 const [ query , setQuery ] = useState ( '' ) ;
5639
5740 const suggestions = useMemo ( ( ) => {
5841 if ( indicator === null ) return [ ] ;
5942 const source = indicator === '#' ? CHANNELS : USERS ;
60- const q = query . toLowerCase ( ) ;
61- return source . filter ( item => item . name . toLowerCase ( ) . startsWith ( q ) ) ;
43+ return source . filter ( item =>
44+ item . name . toLowerCase ( ) . startsWith ( query . toLowerCase ( ) )
45+ ) ;
6246 } , [ indicator , query ] ) ;
6347
6448 const openPicker = ( nextIndicator : string ) => {
@@ -80,6 +64,11 @@ export default function App() {
8064 closePicker ( ) ;
8165 } ;
8266
67+ const updateQuery = ( { indicator : ind , text } : OnChangeMentionEvent ) => {
68+ setIndicator ( ind ) ;
69+ setQuery ( text ) ;
70+ } ;
71+
8372 return (
8473 < View style = { styles . container } >
8574 < EnrichedTextInput
@@ -89,10 +78,7 @@ export default function App() {
8978 placeholder = "Type '@' for people or '#' for channels..."
9079 mentionIndicators = { [ '@' , '#' ] }
9180 onStartMention = { openPicker }
92- onChangeMention = { ( { indicator : ind , text } : OnChangeMentionEvent ) => {
93- setIndicator ( ind ) ;
94- setQuery ( text ) ;
95- } }
81+ onChangeMention = { updateQuery }
9682 onEndMention = { closePicker }
9783 />
9884 { suggestions . length > 0 && (
@@ -115,6 +101,22 @@ export default function App() {
115101 ) ;
116102}
117103
104+ // Each mention kind is styled by its indicator.
105+ const htmlStyle : HtmlStyle = {
106+ mention : {
107+ '@' : {
108+ color : '#2b7a4b' ,
109+ backgroundColor : '#d8f3e3' ,
110+ textDecorationLine : 'none' ,
111+ } ,
112+ '#' : {
113+ color : '#2b5f9e' ,
114+ backgroundColor : '#d8e6f9' ,
115+ textDecorationLine : 'none' ,
116+ } ,
117+ } ,
118+ } ;
119+
118120const styles = StyleSheet . create ( {
119121 container : { gap : 8 } ,
120122 input : {
0 commit comments