From c1076b8e947f8d70e1d44c798cc7e193318fb646 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Sun, 13 Dec 2020 23:02:54 +0100 Subject: [PATCH] Now can scroll to top --- App.tsx | 6 +- src/components/Timelines/Timeline.tsx | 3 + .../Timelines/Timeline/Conversation.tsx | 54 ++++++++------ src/components/Timelines/Timeline/Default.tsx | 19 ++--- .../Timelines/Timeline/Notifications.tsx | 73 ++++++++++++------- src/screens/Me/Root.tsx | 8 +- 6 files changed, 101 insertions(+), 62 deletions(-) diff --git a/App.tsx b/App.tsx index 1651ea77..e9453456 100644 --- a/App.tsx +++ b/App.tsx @@ -55,10 +55,12 @@ const App: React.FC = () => { - + setAppLoaded(true)} + > {bootstrapped => { if (bootstrapped) { - setAppLoaded(true) require('@root/i18n/i18n') return ( diff --git a/src/components/Timelines/Timeline.tsx b/src/components/Timelines/Timeline.tsx index e8df36d6..db1d5404 100644 --- a/src/components/Timelines/Timeline.tsx +++ b/src/components/Timelines/Timeline.tsx @@ -9,6 +9,7 @@ import { timelineFetch } from '@utils/fetches/timelineFetch' import TimelineSeparator from '@components/Timelines/Timeline/Separator' import TimelineEmpty from '@components/Timelines/Timeline/Empty' import TimelineEnd from '@components/Timelines/Timeline/Shared/End' +import { useScrollToTop } from '@react-navigation/native' export interface Props { page: App.Pages @@ -148,6 +149,8 @@ const Timeline: React.FC = ({ ) }, []) + useScrollToTop(flRef) + return ( = ({ ) const conversationChildren = useMemo(() => { - return item.last_status && + return ( + item.last_status && ( + + + + ) + ) }, []) return ( - - + + - - - - + + + = ({ } const styles = StyleSheet.create({ - statusView: { + conversationView: { flex: 1, flexDirection: 'column', padding: StyleConstants.Spacing.Global.PagePadding }, - status: { + header: { flex: 1, + width: '100%', flexDirection: 'row' - }, - details: { - flex: 1, - flexGrow: 1 } }) diff --git a/src/components/Timelines/Timeline/Default.tsx b/src/components/Timelines/Timeline/Default.tsx index 67804870..4e93bec0 100644 --- a/src/components/Timelines/Timeline/Default.tsx +++ b/src/components/Timelines/Timeline/Default.tsx @@ -46,14 +46,12 @@ const TimelineDefault: React.FC = ({ const tootChildren = useMemo( () => ( {actualStatus.content.length > 0 && ( @@ -75,10 +73,12 @@ const TimelineDefault: React.FC = ({ {item.reblog && ( )} + + = ({ notification, queryKey }) => { +const TimelineNotifications: React.FC = ({ + notification, + queryKey, + highlighted = false +}) => { const navigation = useNavigation() const actualAccount = notification.status ? notification.status.account : notification.account - const contentWidth = - Dimensions.get('window').width - - StyleConstants.Spacing.Global.PagePadding * 2 - // Global page padding on both sides - StyleConstants.Avatar.S - // Avatar width - StyleConstants.Spacing.S // Avatar margin to the right + const contentWidth = highlighted + ? Dimensions.get('window').width - + StyleConstants.Spacing.Global.PagePadding * 2 // Global page padding on both sides + : Dimensions.get('window').width - + StyleConstants.Spacing.Global.PagePadding * 2 - // Global page padding on both sides + StyleConstants.Avatar.S - // Avatar width + StyleConstants.Spacing.S // Avatar margin to the right const tootOnPress = useCallback( () => navigation.navigate('Screen-Shared-Toot', { - toot: notification + toot: notification.status }), [] ) const tootChildren = useMemo( () => notification.status ? ( - <> + {notification.status.content.length > 0 && ( - + )} {notification.status.poll && ( @@ -55,7 +72,7 @@ const TimelineNotifications: React.FC = ({ notification, queryKey }) => { {notification.status.card && ( )} - + ) : null, [notification.status?.poll?.voted] ) @@ -68,33 +85,37 @@ const TimelineNotifications: React.FC = ({ notification, queryKey }) => { notification /> - + - - - - {notification.status && ( - - )} - + + + + + {notification.status && ( + + + + )} ) } const styles = StyleSheet.create({ notificationView: { - flex: 1, - flexDirection: 'column', - padding: StyleConstants.Spacing.Global.PagePadding + padding: StyleConstants.Spacing.Global.PagePadding, + paddingBottom: StyleConstants.Spacing.M }, - notification: { + header: { flex: 1, + width: '100%', flexDirection: 'row' - }, - details: { - flex: 1, - flexGrow: 1 } }) diff --git a/src/screens/Me/Root.tsx b/src/screens/Me/Root.tsx index 2ae473f6..2eab2080 100644 --- a/src/screens/Me/Root.tsx +++ b/src/screens/Me/Root.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useRef } from 'react' import { ScrollView } from 'react-native' import { useSelector } from 'react-redux' @@ -9,12 +9,16 @@ import MyInfo from '@screens/Me/Root/MyInfo' import Collections from '@screens/Me/Root/Collections' import Settings from '@screens/Me/Root/Settings' import Logout from '@screens/Me/Root/Logout' +import { useScrollToTop } from '@react-navigation/native' const ScreenMeRoot: React.FC = () => { const localRegistered = useSelector(getLocalUrl) + const scrollRef = useRef(null) + useScrollToTop(scrollRef) + return ( - + {localRegistered ? : } {localRegistered && }