import React, { useContext, useState } from 'react' import { Dimensions, StyleSheet, View } from 'react-native' import { UserContext } from '../../Contexts/UserContext' import { RelayPoolContext } from '../../Contexts/RelayPoolContext' import { AnimatedFAB, Text, TouchableRipple } from 'react-native-paper' import RBSheet from 'react-native-raw-bottom-sheet' import ProfileCard from '../../Components/ProfileCard' import { useFocusEffect, useTheme } from '@react-navigation/native' import { navigate } from '../../lib/Navigation' import { t } from 'i18next' import GlobalFeed from '../GlobalFeed' import MyFeed from '../MyFeed' import { AppContext } from '../../Contexts/AppContext' interface HomeFeedProps { navigation: any } export const HomeFeed: React.FC = ({ navigation }) => { const theme = useTheme() const { showPublicImages } = useContext(AppContext) const { privateKey } = useContext(UserContext) const { relayPool } = useContext(RelayPoolContext) const [tabKey, setTabKey] = React.useState('myFeed') const [profileCardPubkey, setProfileCardPubKey] = useState() const bottomSheetProfileRef = React.useRef(null) useFocusEffect( React.useCallback(() => { return () => relayPool?.unsubscribe([ 'homepage-global-main', 'homepage-contacts-main', 'homepage-reactions', 'homepage-contacts-meta', 'homepage-replies', ]) }, []), ) const bottomSheetStyles = React.useMemo(() => { return { container: { backgroundColor: theme.colors.background, paddingTop: 16, paddingRight: 16, paddingBottom: 32, paddingLeft: 16, borderTopRightRadius: 28, borderTopLeftRadius: 28, height: 'auto', }, } }, []) const renderScene: Record = { globalFeed: ( { setProfileCardPubKey(value) bottomSheetProfileRef.current?.open() }} /> ), myFeed: ( { setProfileCardPubKey(value) bottomSheetProfileRef.current?.open() }} /> ), } return ( { relayPool?.unsubscribe([ 'homepage-contacts-main', 'homepage-reactions', 'homepage-contacts-meta', 'homepage-replies', ]) setTabKey('globalFeed') }} > {t('homeFeed.globalFeed')} { relayPool?.unsubscribe(['homepage-global-main']) setTabKey('myFeed') }} > {t('homeFeed.myFeed')} {renderScene[tabKey]} {privateKey && ( navigate('Send')} animateFrom='right' iconMode='static' extended={false} /> )} ) } const styles = StyleSheet.create({ noteCard: { marginBottom: 16, }, fab: { right: 16, position: 'absolute', }, container: { padding: 16, }, center: { alignContent: 'center', textAlign: 'center', }, blank: { justifyContent: 'space-between', height: 220, marginTop: 91, }, tab: { flex: 1, }, textWrapper: { justifyContent: 'center', height: '100%', textAlign: 'center', }, tabText: { textAlign: 'center', }, tabsNavigator: { flexDirection: 'row', alignItems: 'center', height: 48, }, feed: { paddingBottom: 95, paddingLeft: 16, paddingRight: 16, }, }) export default HomeFeed