updated search input to support back button instead rewriting back handler everytime

This commit is contained in:
Nouman Tahir 2021-05-12 05:11:24 +05:00
parent 15e206ee8d
commit 984a35ab2c
7 changed files with 74 additions and 57 deletions

View File

@ -15,7 +15,7 @@ import {
fetchSubscribedCommunitiesSuccess, fetchSubscribedCommunitiesSuccess,
} from '../../../../redux/actions/communitiesAction'; } from '../../../../redux/actions/communitiesAction';
const SelectCommunityModalContainer = ({ onPressCommunity, currentAccount }) => { const SelectCommunityModalContainer = ({ onPressCommunity, currentAccount, onCloseModal }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const [searchedCommunities, setSearchedCommunities] = useState([]); const [searchedCommunities, setSearchedCommunities] = useState([]);
@ -58,6 +58,7 @@ const SelectCommunityModalContainer = ({ onPressCommunity, currentAccount }) =>
searchedCommunities={searchedCommunities} searchedCommunities={searchedCommunities}
showSearchedCommunities={showSearchedCommunities} showSearchedCommunities={showSearchedCommunities}
currentAccount={currentAccount} currentAccount={currentAccount}
onCloseModal={onCloseModal}
/> />
</> </>
); );

View File

@ -18,6 +18,7 @@ const SelectCommunityModalView = ({
searchedCommunities, searchedCommunities,
showSearchedCommunities, showSearchedCommunities,
currentAccount, currentAccount,
onCloseModal,
intl, intl,
}) => { }) => {
return ( return (
@ -27,7 +28,10 @@ const SelectCommunityModalView = ({
onChangeText={onChangeSearch} onChangeText={onChangeSearch}
placeholder="search" placeholder="search"
autoFocus={false} autoFocus={false}
backEnabled={true}
onBackPress={onCloseModal}
/> />
{showSearchedCommunities ? ( {showSearchedCommunities ? (
<FlatList <FlatList
ItemSeparatorComponent={() => <Separator />} ItemSeparatorComponent={() => <Separator />}

View File

@ -1,6 +1,11 @@
import EStyleSheet from 'react-native-extended-stylesheet'; import EStyleSheet from 'react-native-extended-stylesheet';
export default EStyleSheet.create({ export default EStyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
paddingLeft: 12,
},
inputWrapper: { inputWrapper: {
marginTop: 20, marginTop: 20,
backgroundColor: '$primaryLightBackground', backgroundColor: '$primaryLightBackground',
@ -31,4 +36,15 @@ export default EStyleSheet.create({
color: '$iconColor', color: '$iconColor',
fontSize: 22, fontSize: 22,
}, },
backIcon: {
fontSize: 24,
color: '$iconColor',
justifyContent: 'center',
},
backButtonContainer: {
flex: 1,
marginTop: 20,
marginLeft: 12,
marginRight: 4,
},
}); });

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { SafeAreaView } from 'react-native'; import { SafeAreaView, View } from 'react-native';
// Components // Components
import { Icon } from '../../icon'; import { Icon } from '../../icon';
@ -26,6 +26,8 @@ const SearchInputView = ({
showClearButton = false, showClearButton = false,
prefix = '', prefix = '',
style, style,
backEnabled = false,
onBackPress,
}) => { }) => {
const [inputValue, setInputValue] = useState(value || ''); const [inputValue, setInputValue] = useState(value || '');
@ -53,8 +55,22 @@ const SearchInputView = ({
/> />
); );
const inputWrapperFlex = { flex: backEnabled ? 16 : 1 };
return ( return (
<SafeAreaView style={[styles.inputWrapper, style]}> <SafeAreaView style={styles.container}>
{backEnabled && (
<View style={styles.backButtonContainer}>
<IconButton
iconType="MaterialIcons"
name="arrow-back"
iconStyle={styles.backIcon}
onPress={onBackPress}
/>
</View>
)}
<View style={[styles.inputWrapper, inputWrapperFlex, style]}>
<TextInput <TextInput
style={styles.input} style={styles.input}
onChangeText={_onChangeText} onChangeText={_onChangeText}
@ -67,6 +83,7 @@ const SearchInputView = ({
/> />
{handleOnModalClose && _renderCrossButton(() => handleOnModalClose())} {handleOnModalClose && _renderCrossButton(() => handleOnModalClose())}
{showClearButton && _renderCrossButton(() => setInputValue(''))} {showClearButton && _renderCrossButton(() => setInputValue(''))}
</View>
</SafeAreaView> </SafeAreaView>
); );
}; };

View File

@ -338,6 +338,9 @@ class EditorScreen extends Component {
<SelectCommunityModalContainer <SelectCommunityModalContainer
onPressCommunity={this._handlePressCommunity} onPressCommunity={this._handlePressCommunity}
currentAccount={currentAccount} currentAccount={currentAccount}
onCloseModal={() => {
this.setState({ isCommunitiesListModalOpen: false });
}}
/> />
</Modal> </Modal>
<BasicHeader <BasicHeader

View File

@ -39,26 +39,15 @@ const SearchResultScreen = ({ navigation }) => {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<SafeAreaView>
<View style={styles.headerContainer}>
<View style={{ flex: 1, marginTop: 20 }}>
<IconButton
iconType="MaterialIcons"
name="arrow-back"
iconStyle={styles.backIcon}
onPress={_navigationGoBack}
/>
</View>
<View style={{ flex: 16 }}>
<SearchInput <SearchInput
showClearButton={true} showClearButton={true}
placeholder={intl.formatMessage({ id: 'header.search' })} placeholder={intl.formatMessage({ id: 'header.search' })}
onChangeText={_handleChangeText} onChangeText={_handleChangeText}
value={searchValue} value={searchValue}
backEnabled={true}
onBackPress={_navigationGoBack}
/> />
</View>
</View>
</SafeAreaView>
<ScrollableTabView <ScrollableTabView
style={globalStyles.tabView} style={globalStyles.tabView}
renderTabBar={_renderTabbar} renderTabBar={_renderTabbar}

View File

@ -39,28 +39,15 @@ const TagResultScreen = ({ navigation }) => {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<SafeAreaView>
<View style={styles.headerContainer}>
<View style={{ flex: 1, marginTop: 20 }}>
<IconButton
iconType="MaterialIcons"
name="arrow-back"
iconStyle={styles.backIcon}
onPress={_navigationGoBack}
/>
</View>
<View style={{ flex: 16 }}>
<SearchInput <SearchInput
showClearButton={true} showClearButton={true}
onBackPress={_navigationGoBack}
autoFocus={false} autoFocus={false}
onChangeText={_setTag} onChangeText={_setTag}
value={tag} value={tag}
prefix="#" prefix="#"
backEnabled={true}
onBackPress={_navigationGoBack}
/> />
</View>
</View>
</SafeAreaView>
<View style={styles.tabbarItem}> <View style={styles.tabbarItem}>
<TabbedPosts <TabbedPosts