tooot/src/screens/Shared/sharedScreens.tsx

262 lines
7.6 KiB
TypeScript
Raw Normal View History

2021-01-07 19:13:09 +01:00
import { HeaderLeft } from '@components/Header'
2021-01-16 00:00:31 +01:00
import { ParseEmojis } from '@components/Parse'
2021-01-07 22:18:14 +01:00
import { StackNavigationState, TypedNavigator } from '@react-navigation/native'
import { StackScreenProps } from '@react-navigation/stack'
2020-12-13 14:04:25 +01:00
import ScreenSharedAccount from '@screens/Shared/Account'
2021-01-04 18:29:02 +01:00
import ScreenSharedAnnouncements from '@screens/Shared/Announcements'
2021-01-07 22:18:14 +01:00
import Compose from '@screens/Shared/Compose'
2020-12-13 14:04:25 +01:00
import ScreenSharedHashtag from '@screens/Shared/Hashtag'
2021-01-04 18:29:02 +01:00
import ScreenSharedImagesViewer from '@screens/Shared/ImagesViewer'
import ScreenSharedRelationships from '@screens/Shared/Relationships'
2020-12-13 14:04:25 +01:00
import ScreenSharedSearch from '@screens/Shared/Search'
2021-01-07 22:18:14 +01:00
import ScreenSharedToot from '@screens/Shared/Toot'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import { debounce } from 'lodash'
import React, { useCallback, useState } from 'react'
2020-11-30 00:24:53 +01:00
import { useTranslation } from 'react-i18next'
import { StyleSheet, Text, View } from 'react-native'
import { TextInput } from 'react-native-gesture-handler'
2021-01-07 22:18:14 +01:00
import { NativeStackNavigationOptions } from 'react-native-screens/lib/typescript'
import {
NativeStackNavigationEventMap,
NativeStackNavigatorProps
} from 'react-native-screens/lib/typescript/types'
2021-01-16 00:00:31 +01:00
import ScreenSharedAttachments from './Attachments'
2021-01-07 22:18:14 +01:00
2021-01-10 02:12:14 +01:00
export type BaseScreens =
2021-01-07 22:18:14 +01:00
| Nav.LocalStackParamList
| Nav.RemoteStackParamList
| Nav.NotificationsStackParamList
| Nav.MeStackParamList
export type SharedAccountProp = StackScreenProps<
BaseScreens,
'Screen-Shared-Account'
>
export type SharedAnnouncementsProp = StackScreenProps<
BaseScreens,
'Screen-Shared-Announcements'
>
2021-01-16 00:00:31 +01:00
export type SharedAttachmentsProp = StackScreenProps<
BaseScreens,
'Screen-Shared-Attachments'
>
2021-01-07 22:18:14 +01:00
export type SharedComposeProp = StackScreenProps<
BaseScreens,
'Screen-Shared-Compose'
>
export type SharedHashtagProp = StackScreenProps<
BaseScreens,
'Screen-Shared-Hashtag'
>
2020-11-21 13:19:05 +01:00
2021-01-07 22:18:14 +01:00
export type SharedImagesViewerProp = StackScreenProps<
BaseScreens,
'Screen-Shared-ImagesViewer'
>
export type SharedRelationshipsProp = StackScreenProps<
BaseScreens,
'Screen-Shared-Relationships'
>
2021-01-16 00:00:31 +01:00
export type SharedSearchProp = StackScreenProps<
BaseScreens,
'Screen-Shared-Search'
>
2021-01-07 22:18:14 +01:00
export type SharedTootProp = StackScreenProps<BaseScreens, 'Screen-Shared-Toot'>
const sharedScreens = (
Stack: TypedNavigator<
BaseScreens,
StackNavigationState<Record<string, object | undefined>>,
NativeStackNavigationOptions,
NativeStackNavigationEventMap,
({
initialRouteName,
children,
screenOptions,
...rest
}: NativeStackNavigatorProps) => JSX.Element
>
) => {
const { theme } = useTheme()
2020-11-30 00:24:53 +01:00
const { t } = useTranslation()
const [searchTerm, setSearchTerm] = useState<string>()
const onChangeText = useCallback(
debounce(text => setSearchTerm(text), 1000, {
trailing: true
}),
[]
)
2020-11-21 13:19:05 +01:00
return [
<Stack.Screen
key='Screen-Shared-Account'
name='Screen-Shared-Account'
component={ScreenSharedAccount}
2021-01-07 22:18:14 +01:00
options={({ navigation }: SharedAccountProp) => {
return {
headerTranslucent: true,
headerStyle: {
backgroundColor: `rgba(255, 255, 255, 0)`
},
headerCenter: () => null,
2020-12-26 23:27:53 +01:00
headerLeft: () => <HeaderLeft onPress={() => navigation.goBack()} />
}
}}
2020-11-21 13:19:05 +01:00
/>,
<Stack.Screen
2021-01-07 22:18:14 +01:00
key='Screen-Shared-Announcements'
name='Screen-Shared-Announcements'
component={ScreenSharedAnnouncements}
options={{
stackPresentation: 'transparentModal',
2021-01-14 00:43:35 +01:00
stackAnimation: 'fade',
headerShown: false
2021-01-07 22:18:14 +01:00
}}
2020-11-21 13:19:05 +01:00
/>,
2021-01-16 00:00:31 +01:00
<Stack.Screen
key='Screen-Shared-Attachments'
name='Screen-Shared-Attachments'
component={ScreenSharedAttachments}
options={({
route: {
params: { account }
},
navigation
}: SharedAttachmentsProp) => {
return {
headerLeft: () => <HeaderLeft onPress={() => navigation.goBack()} />,
headerCenter: () => (
<Text numberOfLines={1}>
<ParseEmojis
content={account.display_name || account.username}
emojis={account.emojis}
fontBold
/>
<Text
style={{
...StyleConstants.FontStyle.M,
color: theme.primary,
fontWeight: StyleConstants.Font.Weight.Bold
}}
>
{' '}
</Text>
</Text>
)
}
}}
/>,
2020-11-21 13:19:05 +01:00
<Stack.Screen
2020-11-22 00:57:43 +01:00
key='Screen-Shared-Compose'
name='Screen-Shared-Compose'
component={Compose}
2020-11-21 13:19:05 +01:00
options={{
2021-01-14 00:43:35 +01:00
stackPresentation: 'fullScreenModal',
headerShown: false
2020-11-21 13:19:05 +01:00
}}
2020-11-24 00:18:47 +01:00
/>,
<Stack.Screen
2021-01-07 22:18:14 +01:00
key='Screen-Shared-Hashtag'
name='Screen-Shared-Hashtag'
component={ScreenSharedHashtag}
2021-01-16 00:00:31 +01:00
options={({ route, navigation }: SharedHashtagProp) => ({
2021-01-07 22:18:14 +01:00
title: `#${decodeURIComponent(route.params.hashtag)}`,
2021-01-04 18:29:02 +01:00
headerLeft: () => <HeaderLeft onPress={() => navigation.goBack()} />
})}
2020-12-23 01:31:11 +01:00
/>,
2020-12-25 18:20:09 +01:00
<Stack.Screen
key='Screen-Shared-ImagesViewer'
name='Screen-Shared-ImagesViewer'
component={ScreenSharedImagesViewer}
options={{
stackPresentation: 'transparentModal',
2021-01-14 00:43:35 +01:00
stackAnimation: 'none',
headerShown: false
2020-12-25 18:20:09 +01:00
}}
2021-01-04 18:29:02 +01:00
/>,
<Stack.Screen
key='Screen-Shared-Relationships'
name='Screen-Shared-Relationships'
component={ScreenSharedRelationships}
2021-01-16 00:00:31 +01:00
options={({ navigation }: SharedRelationshipsProp) => ({
2021-01-04 18:29:02 +01:00
headerLeft: () => <HeaderLeft onPress={() => navigation.goBack()} />
})}
2021-01-07 22:18:14 +01:00
/>,
<Stack.Screen
key='Screen-Shared-Search'
name='Screen-Shared-Search'
2021-01-16 00:00:31 +01:00
options={({ navigation }: SharedSearchProp) => ({
headerLeft: () => <HeaderLeft onPress={() => navigation.goBack()} />,
// https://github.com/react-navigation/react-navigation/issues/6746#issuecomment-583897436
headerCenter: () => (
<View style={styles.searchBar}>
<Text
style={{ ...StyleConstants.FontStyle.M, color: theme.primary }}
>
</Text>
<TextInput
style={[
styles.textInput,
{
color: theme.primary
}
]}
autoFocus
onChangeText={onChangeText}
autoCapitalize='none'
autoCorrect={false}
clearButtonMode='never'
keyboardType='web-search'
onSubmitEditing={({ nativeEvent: { text } }) =>
setSearchTerm(text)
}
placeholder={'些什么'}
placeholderTextColor={theme.secondary}
returnKeyType='go'
/>
</View>
)
2021-01-07 22:18:14 +01:00
})}
>
{() => <ScreenSharedSearch searchTerm={searchTerm} />}
</Stack.Screen>,
2021-01-07 22:18:14 +01:00
<Stack.Screen
key='Screen-Shared-Toot'
name='Screen-Shared-Toot'
component={ScreenSharedToot}
2021-01-16 00:00:31 +01:00
options={({ navigation }: SharedTootProp) => ({
2021-01-07 22:18:14 +01:00
title: t('sharedToot:heading'),
headerLeft: () => <HeaderLeft onPress={() => navigation.goBack()} />
})}
2020-11-21 13:19:05 +01:00
/>
]
}
const styles = StyleSheet.create({
searchBar: {
flexBasis: '80%',
flexDirection: 'row',
alignItems: 'center'
},
textInput: {
...StyleConstants.FontStyle.M,
paddingLeft: StyleConstants.Spacing.XS,
marginBottom:
(StyleConstants.Font.LineHeight.M - StyleConstants.Font.Size.M) / 2
}
})
2020-11-21 13:19:05 +01:00
export default sharedScreens