diff --git a/apps/mobile/src/components/Container/ContainerBottomButton.js b/apps/mobile/src/components/Container/ContainerBottomButton.js index f8378cfd5..e14019912 100644 --- a/apps/mobile/src/components/Container/ContainerBottomButton.js +++ b/apps/mobile/src/components/Container/ContainerBottomButton.js @@ -5,84 +5,84 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {useTracked} from '../../provider'; import {getElevation} from '../../utils'; import {PressableButton} from '../PressableButton'; -import {pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; -import {DDS} from "../../services/DeviceDetection"; +import {normalize, pv, SIZE, WEIGHT} from '../../utils/SizeUtils'; +import {DDS} from '../../services/DeviceDetection'; export const ContainerBottomButton = ({title, onPress, color}) => { - const [state,] = useTracked(); - const {colors} = state; - const [buttonHide, setButtonHide] = useState(false); - const insets = useSafeAreaInsets(); + const [state] = useTracked(); + const {colors} = state; + const [buttonHide, setButtonHide] = useState(false); + const insets = useSafeAreaInsets(); - const onKeyboardHide = () => { - if (DDS.isTab) return; - setButtonHide(false); - } + const onKeyboardHide = () => { + if (DDS.isTab) return; + setButtonHide(false); + }; - const onKeyboardShow = () => { - if (DDS.isTab) return; - setButtonHide(true); - } + const onKeyboardShow = () => { + if (DDS.isTab) return; + setButtonHide(true); + }; - useEffect(() => { - Keyboard.addListener('keyboardDidShow', onKeyboardShow); - Keyboard.addListener('keyboardDidHide', onKeyboardHide); - return () => { - Keyboard.removeListener('keyboardDidShow', onKeyboardShow); - Keyboard.removeListener('keyboardDidHide', onKeyboardHide); - }; - }, []); + useEffect(() => { + Keyboard.addListener('keyboardDidShow', onKeyboardShow); + Keyboard.addListener('keyboardDidHide', onKeyboardHide); + return () => { + Keyboard.removeListener('keyboardDidShow', onKeyboardShow); + Keyboard.removeListener('keyboardDidHide', onKeyboardHide); + }; + }, []); - return ( + return ( + + + + - - - - - {' ' + title} - - - + {' ' + title} + - ); + + + ); }; diff --git a/apps/mobile/src/components/Header/HeaderLeftMenu.js b/apps/mobile/src/components/Header/HeaderLeftMenu.js index a4a8b6a2b..70a7eaba7 100644 --- a/apps/mobile/src/components/Header/HeaderLeftMenu.js +++ b/apps/mobile/src/components/Header/HeaderLeftMenu.js @@ -1,45 +1,76 @@ -import React from 'react'; +import React, {useEffect} from 'react'; import {useTracked} from '../../provider'; -import {SIZE} from "../../utils/SizeUtils"; -import {DDS} from "../../services/DeviceDetection"; -import {ActionIcon} from "../ActionIcon"; -import NavigationService from "../../services/Navigation"; +import {SIZE} from '../../utils/SizeUtils'; +import {DDS} from '../../services/DeviceDetection'; +import {ActionIcon} from '../ActionIcon'; +import NavigationService from '../../services/Navigation'; +import {eSendEvent} from '../../services/EventManager'; +import {eClearSearch} from '../../utils/Events'; +import {BackHandler} from 'react-native'; export const HeaderLeftMenu = () => { - const [state,] = useTracked(); - const {colors, headerMenuState} = state; + const [state] = useTracked(); + const {colors, headerMenuState, searchResults} = state; - const onLeftButtonPress = () => { - if (headerMenuState) { - NavigationService.openDrawer(); - return; - } - NavigationService.goBack(); + const onLeftButtonPress = () => { + if (searchResults.results.length > 0) { + eSendEvent(eClearSearch); + return; + } + if (headerMenuState) { + NavigationService.openDrawer(); + return; + } + NavigationService.goBack(); + }; + + const onBackPress = () => { + if (searchResults.results.length > 0) { + eSendEvent(eClearSearch); + return true; + } + return false; + }; + + useEffect(() => { + if (searchResults.results.length > 0) { + BackHandler.addEventListener('hardwareBackPress', onBackPress); + } else { + BackHandler.removeEventListener('hardwareBackPress', onBackPress); + } + + return () => { + BackHandler.removeEventListener('hardwareBackPress', onBackPress); }; + }, [searchResults.results]); - return ( - <> - {!DDS.isTab ? ( - - ) : undefined} - - ); + return ( + <> + {!DDS.isTab ? ( + 0 + ? 'arrow-left' + : 'menu' + } + size={SIZE.xxxl} + color={colors.pri} + iconStyle={{ + marginLeft: !headerMenuState ? -5 : 0, + }} + /> + ) : undefined} + + ); }; diff --git a/apps/mobile/src/components/SearchInput/index.js b/apps/mobile/src/components/SearchInput/index.js index 345517c7e..b6b018225 100644 --- a/apps/mobile/src/components/SearchInput/index.js +++ b/apps/mobile/src/components/SearchInput/index.js @@ -16,9 +16,10 @@ import {selection} from '../../utils'; import Animated, {Easing} from 'react-native-reanimated'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {TextInput, Text} from 'react-native'; -import {br, SIZE, WEIGHT} from '../../utils/SizeUtils'; +import {br, normalize, SIZE, WEIGHT} from '../../utils/SizeUtils'; import {db} from '../../utils/DB'; import {DDS} from '../../services/DeviceDetection'; +import {ActionIcon} from '../ActionIcon'; const {Value, timing, block} = Animated; let searchResult = []; @@ -54,6 +55,8 @@ const animation = (margin, opacity, border) => { }, 200); }; +let timeout = null; + export const Search = (props) => { const [state, dispatch] = useTracked(); const {colors, searchResults} = state; @@ -142,6 +145,15 @@ export const Search = (props) => { keyword: null, }, }); + } else { + dispatch({ + type: Actions.SEARCH_RESULTS, + results: { + results: [], + type: null, + keyword: null, + }, + }); } }; @@ -152,15 +164,22 @@ export const Search = (props) => { }; }, []); + useEffect(() => { + if (!text || text.length === 0) { + clearSearch(); + } + }, [text]); + const onChangeText = (value) => { setText(value); }; + const onSubmitEditing = async () => { if (!text || text.length < 1) { - ToastEvent.show('Please enter a search keyword'); clearSearch(); return; } + let type = searchState.type; if (!type) return; @@ -208,25 +227,40 @@ export const Search = (props) => { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', - paddingLeft: 12, width: '100%', alignSelf: 'center', borderRadius: br, - height: '90%', + height: normalize(55), backgroundColor: focus ? searchState.color ? searchState.color : colors.shade : colors.nav, }}> + { placeholder={searchState.placeholder} placeholderTextColor={colors.icon} /> - diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js index 7c938e23d..feb085e5b 100644 --- a/apps/mobile/src/components/SimpleList/index.js +++ b/apps/mobile/src/components/SimpleList/index.js @@ -13,7 +13,12 @@ import {DataProvider, LayoutProvider, RecyclerListView} from 'recyclerlistview'; import {useTracked} from '../../provider'; import {Actions} from '../../provider/Actions'; import {eSendEvent, ToastEvent} from '../../services/EventManager'; -import {eClearSearch, eOpenJumpToDialog, eOpenLoginDialog, eScrollEvent} from '../../utils/Events'; +import { + eClearSearch, + eOpenJumpToDialog, + eOpenLoginDialog, + eScrollEvent, +} from '../../utils/Events'; import {PressableButton} from '../PressableButton'; import {COLORS_NOTE} from '../../utils/Colors'; import {SIZE, WEIGHT} from '../../utils/SizeUtils'; @@ -35,7 +40,7 @@ const SimpleList = ({ refreshCallback, sortMenuButton, scrollRef, - jumpToDialog + jumpToDialog, }) => { const [state, dispatch] = useTracked(); const {colors, selectionMode, messageBoardState} = state; @@ -59,7 +64,7 @@ const SimpleList = ({ useEffect(() => { loadData(); - }, [listData]); + }, [listData, searchResults.results]); const loadData = () => { let mainData = @@ -85,18 +90,18 @@ const SimpleList = ({ }}> { - console.log('clicekd'); - if (jumpToDialog) { - eSendEvent(eOpenJumpToDialog); - } + console.log('clicekd'); + if (jumpToDialog) { + eSendEvent(eOpenJumpToDialog); + } }} style={[ styles.sectionHeader, { color: colors.accent, - height:30, - minWidth:60, - textAlignVertical:"bottom" + height: 30, + minWidth: 60, + textAlignVertical: 'bottom', }, ]}> {item.title} @@ -367,14 +372,7 @@ const MessageCard = ({data}) => { }; const ListHeaderComponent = ({type, data}) => { - const [state] = useTracked(); - const searchResults = {...state.searchResults}; - - return searchResults.type === type && searchResults.results.length > 0 ? ( - - ) : ( - - ); + return ; }; const styles = StyleSheet.create({