mirror of https://github.com/tooot-app/app
Updates
This commit is contained in:
parent
3427b613aa
commit
b679b56a0e
|
@ -1,40 +1,20 @@
|
||||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
import React, { useCallback, useEffect, useState } from 'react'
|
||||||
import { Dimensions, FlatList, StyleSheet, View } from 'react-native'
|
import { Dimensions, StyleSheet, View } from 'react-native'
|
||||||
import SegmentedControl from '@react-native-community/segmented-control'
|
import SegmentedControl from '@react-native-community/segmented-control'
|
||||||
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
|
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import { Feather } from '@expo/vector-icons'
|
|
||||||
|
|
||||||
import Timeline from '@components/Timelines/Timeline'
|
import Timeline from '@components/Timelines/Timeline'
|
||||||
import sharedScreens from '@screens/Shared/sharedScreens'
|
import sharedScreens from '@screens/Shared/sharedScreens'
|
||||||
import {
|
import { getLocalUrl, getRemoteUrl } from '@utils/slices/instancesSlice'
|
||||||
getLocalUrl,
|
|
||||||
getRemoteUrl,
|
|
||||||
InstancesState
|
|
||||||
} from '@utils/slices/instancesSlice'
|
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import getCurrentTab from '@utils/getCurrentTab'
|
import getCurrentTab from '@utils/getCurrentTab'
|
||||||
import { HeaderRight } from './Header'
|
import { HeaderRight } from './Header'
|
||||||
|
import { TabView } from 'react-native-tab-view'
|
||||||
|
|
||||||
const Stack = createNativeStackNavigator()
|
const Stack = createNativeStackNavigator()
|
||||||
|
|
||||||
const Page = ({
|
|
||||||
item: { page },
|
|
||||||
localRegistered
|
|
||||||
}: {
|
|
||||||
item: { page: App.Pages }
|
|
||||||
localRegistered: InstancesState['local']['url'] | undefined
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<View style={{ width: Dimensions.get('window').width }}>
|
|
||||||
{localRegistered || page === 'RemotePublic' ? (
|
|
||||||
<Timeline page={page} />
|
|
||||||
) : null}
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
name: 'Screen-Local-Root' | 'Screen-Public-Root'
|
name: 'Screen-Local-Root' | 'Screen-Public-Root'
|
||||||
content: { title: string; page: App.Pages }[]
|
content: { title: string; page: App.Pages }[]
|
||||||
|
@ -53,46 +33,22 @@ const Timelines: React.FC<Props> = ({ name, content }) => {
|
||||||
return
|
return
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const horizontalPaging = useRef<FlatList>(null!)
|
|
||||||
|
|
||||||
const onChangeSegment = useCallback(({ nativeEvent }) => {
|
|
||||||
horizontalPaging.current.scrollToIndex({
|
|
||||||
index: nativeEvent.selectedSegmentIndex
|
|
||||||
})
|
|
||||||
}, [])
|
|
||||||
const onPressSearch = useCallback(() => {
|
const onPressSearch = useCallback(() => {
|
||||||
navigation.navigate(getCurrentTab(navigation), {
|
navigation.navigate(getCurrentTab(navigation), {
|
||||||
screen: 'Screen-Shared-Search'
|
screen: 'Screen-Shared-Search'
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const flGetItemLayout = useCallback(
|
const [routes] = useState(content.map(p => ({ key: p.page })))
|
||||||
(data, index) => ({
|
const renderScene = ({
|
||||||
length: Dimensions.get('window').width,
|
route
|
||||||
offset: Dimensions.get('window').width * index,
|
}: {
|
||||||
index
|
route: {
|
||||||
}),
|
key: App.Pages
|
||||||
[]
|
}
|
||||||
)
|
}) => {
|
||||||
const flKeyExtrator = useCallback(({ page }) => page, [])
|
return <Timeline page={route.key} />
|
||||||
const flRenderItem = useCallback(
|
}
|
||||||
({ item, index }) => {
|
|
||||||
if (!localRegistered && index === 0) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
return <Page item={item} localRegistered={localRegistered} />
|
|
||||||
},
|
|
||||||
[localRegistered]
|
|
||||||
)
|
|
||||||
const flOnScroll = useCallback(
|
|
||||||
({ nativeEvent }) =>
|
|
||||||
setSegment(
|
|
||||||
nativeEvent.contentOffset.x <= Dimensions.get('window').width / 2
|
|
||||||
? 0
|
|
||||||
: 1
|
|
||||||
),
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator>
|
<Stack.Navigator>
|
||||||
|
@ -108,7 +64,9 @@ const Timelines: React.FC<Props> = ({ name, content }) => {
|
||||||
appearance={mode}
|
appearance={mode}
|
||||||
values={[content[0].title, content[1].title]}
|
values={[content[0].title, content[1].title]}
|
||||||
selectedIndex={segment}
|
selectedIndex={segment}
|
||||||
onChange={onChangeSegment}
|
onChange={({ nativeEvent }) =>
|
||||||
|
setSegment(nativeEvent.selectedSegmentIndex)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
),
|
),
|
||||||
|
@ -120,19 +78,16 @@ const Timelines: React.FC<Props> = ({ name, content }) => {
|
||||||
>
|
>
|
||||||
{() => {
|
{() => {
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<TabView
|
||||||
horizontal
|
style={styles.base}
|
||||||
pagingEnabled
|
navigationState={{ index: segment, routes }}
|
||||||
data={content}
|
renderScene={renderScene}
|
||||||
bounces={false}
|
renderTabBar={() => null}
|
||||||
onScroll={flOnScroll}
|
onIndexChange={index => setSegment(index)}
|
||||||
ref={horizontalPaging}
|
initialLayout={{ width: Dimensions.get('window').width }}
|
||||||
style={styles.flatList}
|
lazy
|
||||||
renderItem={flRenderItem}
|
swipeEnabled
|
||||||
extraData={localRegistered}
|
swipeVelocityImpact={1}
|
||||||
keyExtractor={flKeyExtrator}
|
|
||||||
getItemLayout={flGetItemLayout}
|
|
||||||
showsHorizontalScrollIndicator={false}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
|
@ -147,9 +102,8 @@ const styles = StyleSheet.create({
|
||||||
segmentsContainer: {
|
segmentsContainer: {
|
||||||
flexBasis: '60%'
|
flexBasis: '60%'
|
||||||
},
|
},
|
||||||
flatList: {
|
base: {
|
||||||
width: Dimensions.get('window').width,
|
width: Dimensions.get('window').width
|
||||||
height: '100%'
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useCallback, useEffect, useMemo, useRef } from 'react'
|
import React, { useCallback, useEffect, useMemo, useRef } from 'react'
|
||||||
import { AppState, FlatList, StyleSheet } from 'react-native'
|
import { AppState, StyleSheet } from 'react-native'
|
||||||
import { setFocusHandler, useInfiniteQuery } from 'react-query'
|
import { setFocusHandler, useInfiniteQuery } from 'react-query'
|
||||||
|
|
||||||
import TimelineNotifications from '@components/Timelines/Timeline/Notifications'
|
import TimelineNotifications from '@components/Timelines/Timeline/Notifications'
|
||||||
|
@ -10,6 +10,7 @@ import TimelineSeparator from '@components/Timelines/Timeline/Separator'
|
||||||
import TimelineEmpty from '@components/Timelines/Timeline/Empty'
|
import TimelineEmpty from '@components/Timelines/Timeline/Empty'
|
||||||
import TimelineEnd from '@components/Timelines/Timeline/Shared/End'
|
import TimelineEnd from '@components/Timelines/Timeline/Shared/End'
|
||||||
import { useScrollToTop } from '@react-navigation/native'
|
import { useScrollToTop } from '@react-navigation/native'
|
||||||
|
import { FlatList } from 'react-native-gesture-handler'
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
page: App.Pages
|
page: App.Pages
|
||||||
|
@ -67,7 +68,7 @@ const Timeline: React.FC<Props> = ({
|
||||||
const flattenPointer = data ? data.flatMap(d => [d?.pointer]) : []
|
const flattenPointer = data ? data.flatMap(d => [d?.pointer]) : []
|
||||||
const flattenPinnedLength = data ? data.flatMap(d => [d?.pinnedLength]) : []
|
const flattenPinnedLength = data ? data.flatMap(d => [d?.pinnedLength]) : []
|
||||||
|
|
||||||
const flRef = useRef<FlatList>(null)
|
const flRef = useRef<FlatList<any>>(null)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (toot && isSuccess) {
|
if (toot && isSuccess) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useCallback, useContext } from 'react'
|
import React, { useCallback, useContext, useState } from 'react'
|
||||||
import { Dimensions, StyleSheet } from 'react-native'
|
import { Dimensions, StyleSheet } from 'react-native'
|
||||||
import { TabView, SceneMap } from 'react-native-tab-view'
|
import { TabView, SceneMap } from 'react-native-tab-view'
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ export interface Props {
|
||||||
const AccountToots: React.FC<Props> = ({ id }) => {
|
const AccountToots: React.FC<Props> = ({ id }) => {
|
||||||
const { accountState, accountDispatch } = useContext(AccountContext)
|
const { accountState, accountDispatch } = useContext(AccountContext)
|
||||||
|
|
||||||
const [routes] = React.useState([
|
const [routes] = useState([
|
||||||
{ key: 'Account_Default' },
|
{ key: 'Account_Default' },
|
||||||
{ key: 'Account_All' },
|
{ key: 'Account_All' },
|
||||||
{ key: 'Account_Media' }
|
{ key: 'Account_Media' }
|
||||||
|
|
Loading…
Reference in New Issue