2019-07-29 16:33:28 +00:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Keyboard, StyleSheet, View } from 'react-native';
|
2019-07-29 16:33:28 +00:00
|
|
|
import ShareExtension from 'rn-extensions-share';
|
|
|
|
|
|
|
|
import SearchBox from '../../../containers/SearchBox';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../../containers/HeaderButton';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
2019-07-29 16:33:28 +00:00
|
|
|
import sharedStyles from '../../Styles';
|
2019-09-19 13:32:24 +00:00
|
|
|
import { animateNextTransition } from '../../../utils/layoutAnimation';
|
2019-07-29 16:33:28 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
...sharedStyles.separatorBottom
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Header = React.memo(({ searching, onChangeSearchText, initSearch, cancelSearch, theme }) => {
|
2019-07-29 16:33:28 +00:00
|
|
|
const [text, setText] = useState('');
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const onChangeText = searchText => {
|
2019-07-29 16:33:28 +00:00
|
|
|
onChangeSearchText(searchText);
|
|
|
|
setText(searchText);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onCancelPress = () => {
|
|
|
|
Keyboard.dismiss();
|
|
|
|
onChangeText('');
|
|
|
|
cancelSearch();
|
2019-09-19 13:32:24 +00:00
|
|
|
animateNextTransition();
|
2019-07-29 16:33:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const onFocus = () => {
|
|
|
|
initSearch();
|
2019-09-19 13:32:24 +00:00
|
|
|
animateNextTransition();
|
2019-07-29 16:33:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.container,
|
|
|
|
{
|
|
|
|
borderColor: themes[theme].separatorColor,
|
|
|
|
backgroundColor: themes[theme].headerBackground
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
]}>
|
|
|
|
{!searching ? <HeaderButton.CancelModal onPress={ShareExtension.close} testID='share-extension-close' /> : null}
|
2019-07-29 16:33:28 +00:00
|
|
|
<SearchBox
|
|
|
|
value={text}
|
|
|
|
hasCancel={searching}
|
|
|
|
onFocus={onFocus}
|
|
|
|
onCancelPress={onCancelPress}
|
|
|
|
onChangeText={onChangeText}
|
|
|
|
testID='rooms-list-view-search'
|
|
|
|
key='rooms-list-view-search'
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Header.propTypes = {
|
|
|
|
searching: PropTypes.bool,
|
|
|
|
onChangeSearchText: PropTypes.func,
|
|
|
|
initSearch: PropTypes.func,
|
2019-12-04 16:39:53 +00:00
|
|
|
cancelSearch: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-07-29 16:33:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Header;
|