import React, {useEffect, useState} from 'react'; import { Keyboard, KeyboardAvoidingView, Platform, SafeAreaView, Text, TouchableOpacity, View, } from 'react-native'; import * as Animatable from 'react-native-animatable'; import Icon from 'react-native-vector-icons/Feather'; import {br, opacity, pv, SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager'; import {eScrollEvent} from '../../services/events'; import {getElevation, h, w} from '../../utils/utils'; import {Header} from '../header'; import {Search} from '../SearchInput'; import SelectionHeader from '../SelectionHeader'; import {DDS} from '../../../App'; export const AnimatedSafeAreaView = Animatable.createAnimatableComponent( SafeAreaView, ); const AnimatedTouchableOpacity = Animatable.createAnimatableComponent( TouchableOpacity, ); export const Container = ({ children, bottomButtonOnPress, bottomButtonText, noBottomButton = false, data = [], heading, canGoBack = true, menu, customIcon, verticalMenu = false, preventDefaultMargins, navigation = null, isLoginNavigator, placeholder = '', noSearch = false, noSelectionHeader = false, }) => { // State const [state, dispatch] = useTracked(); const {colors, selectionMode, searchResults, loading} = state; const [text, setText] = useState(''); const [hideHeader, setHideHeader] = useState(false); const [buttonHide, setButtonHide] = useState(false); let offsetY = 0; let countUp = 1; let countDown = 0; let searchResult = []; const onScroll = y => { if (searchResults.length > 0) return; if (y < 30) { countUp = 1; countDown = 0; setHideHeader(false); } if (y > offsetY) { if (y - offsetY < 150 || countDown > 0) return; countDown = 1; countUp = 0; setHideHeader(true); } else { if (offsetY - y < 50 || countUp > 0) return; countDown = 0; countUp = 1; setHideHeader(false); } offsetY = y; }; const onChangeText = value => { //setText(value); }; const onSubmitEditing = async () => { if (!text || text.length < 1) { clearSearch(); } else { //setKeyword(text); searchResult = await db.searchNotes(text); if (searchResult && searchResult.length > 0) { //setSearchResults([...searchResult]); } else { ToastEvent.show('No search results found', 'error', 3000, () => {}, ''); } } }; const onBlur = () => { if (text && text.length < 1) { clearSearch(); } }; const onFocus = () => { //setSearch(false); }; const clearSearch = () => { searchResult = null; //setSearchResults([...[]]); }; useEffect(() => { Keyboard.addListener('keyboardDidShow', () => { setTimeout(() => { setButtonHide(true); }, 300); }); Keyboard.addListener('keyboardDidHide', () => { setTimeout(() => { setButtonHide(false); }, 300); }); return () => { Keyboard.removeListener('keyboardDidShow', () => { setTimeout(() => { setButtonHide(true); }, 300); }); Keyboard.removeListener('keyboardDidHide', () => { setTimeout(() => { setButtonHide(false); }, 300); }); }; }, []); useEffect(() => { eSubscribeEvent(eScrollEvent, onScroll); return () => { eUnSubscribeEvent(eScrollEvent, onScroll); }; }); // Render return ( {noSelectionHeader ? null : }
{ setHideHeader(false); countUp = 0; countDown = 0; }} navigation={navigation} colors={colors} isLoginNavigator={isLoginNavigator} preventDefaultMargins={preventDefaultMargins} heading={heading} canGoBack={canGoBack} customIcon={customIcon} /> {data[0] && !noSearch ? ( setText('')} hide={hideHeader} onChangeText={onChangeText} onSubmitEditing={onSubmitEditing} placeholder={placeholder} onBlur={onBlur} onFocus={onFocus} clearSearch={clearSearch} value={text} /> ) : null} {children} {noBottomButton ? null : ( {' ' + bottomButtonText} )} ); }; export default Container;