From 10b70c2ac476c6c1c5f1cd1976af099ee31877cc Mon Sep 17 00:00:00 2001 From: Caspian Date: Sat, 16 Dec 2023 21:48:55 +0000 Subject: [PATCH 1/2] feat: Hide the splash screen after the navigation is rendered. --- .changeset/five-cows-talk.md | 5 +++++ src/navigation/root.tsx | 7 ++++++- src/providers/preload-provider.tsx | 7 ------- 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 .changeset/five-cows-talk.md diff --git a/.changeset/five-cows-talk.md b/.changeset/five-cows-talk.md new file mode 100644 index 0000000..c9cf86b --- /dev/null +++ b/.changeset/five-cows-talk.md @@ -0,0 +1,5 @@ +--- +"xlog": patch +--- + +Hide the splash screen after the navigation is rendered. diff --git a/src/navigation/root.tsx b/src/navigation/root.tsx index 2e7b95e..567c030 100644 --- a/src/navigation/root.tsx +++ b/src/navigation/root.tsx @@ -1,9 +1,10 @@ -import React from "react"; +import React, { useEffect } from "react"; import { useTranslation } from "react-i18next"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { HeaderBackButton } from "@react-navigation/elements"; import { createNativeStackNavigator } from "@react-navigation/native-stack"; +import * as SplashScreen from "expo-splash-screen"; import { CharacterListPage } from "@/pages/CharacterList"; import { ClaimCSBPage } from "@/pages/ClaimCSB"; @@ -34,6 +35,10 @@ export const RootNavigator = () => { const { bottom } = useSafeAreaInsets(); const i18n = useTranslation("common"); + useEffect(() => { + SplashScreen.hideAsync(); + }, []); + return ( {/* Without header */} diff --git a/src/providers/preload-provider.tsx b/src/providers/preload-provider.tsx index ea41a89..41597cb 100644 --- a/src/providers/preload-provider.tsx +++ b/src/providers/preload-provider.tsx @@ -1,7 +1,6 @@ import { type FC, type PropsWithChildren, useEffect } from "react"; import { useFonts } from "expo-font"; -import * as SplashScreen from "expo-splash-screen"; export const PreloadProvider: FC> = ({ children }) => { const [fontsLoadingReady] = useFonts({ @@ -13,12 +12,6 @@ export const PreloadProvider: FC> = ({ children }) => { const allReady = fontsLoadingReady; - useEffect(() => { - if (allReady) { - SplashScreen.hideAsync(); - } - }, [allReady]); - if (!allReady) return null; From 0fd4bbc6d64ad64b893eb76dbc5da9bd227f039e Mon Sep 17 00:00:00 2001 From: Caspian Date: Sat, 16 Dec 2023 22:56:27 +0000 Subject: [PATCH 2/2] faet: Only reload the feed in the shorts page. --- .changeset/weak-flowers-dream.md | 5 +++++ src/components/FeedList/useFeedList.tsx | 21 ++++++++++++++++----- src/hooks/use-post-indicator-store.ts | 14 ++++++++++++-- src/pages/Feed/index.tsx | 1 + src/providers/post-indicator-provider.tsx | 3 +++ 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 .changeset/weak-flowers-dream.md diff --git a/.changeset/weak-flowers-dream.md b/.changeset/weak-flowers-dream.md new file mode 100644 index 0000000..092b468 --- /dev/null +++ b/.changeset/weak-flowers-dream.md @@ -0,0 +1,5 @@ +--- +"xlog": patch +--- + +Only reload the feed in the shorts page. diff --git a/src/components/FeedList/useFeedList.tsx b/src/components/FeedList/useFeedList.tsx index 7ef3c9c..73a5f6d 100644 --- a/src/components/FeedList/useFeedList.tsx +++ b/src/components/FeedList/useFeedList.tsx @@ -32,16 +32,17 @@ export interface Props { characterId?: number ListHeaderComponent?: React.ReactNode visibility?: PageVisibilityEnum + updateFeedAfterPost?: boolean } export const useFeedList = (props: Props & T) => { - const { ListHeaderComponent, visibility, handle, type, searchKeyword, contentContainerStyle = {}, tags = [], topic, daysInterval = 7, onScroll, characterId, ...restProps } = props; + const { ListHeaderComponent, updateFeedAfterPost = false, visibility, handle, type, searchKeyword, contentContainerStyle = {}, tags = [], topic, daysInterval = 7, onScroll, characterId, ...restProps } = props; const { width } = useWindowDimensions(); const { feedList, feed } = useFeedData(props); const [isRefetching, setIsRefetching] = useState(false); const listRef = useRef>(null); const { isDarkMode } = useThemeStore(); - const { isProcessing } = usePostIndicatorStore(); + const { subscribe } = usePostIndicatorStore(); const i18nC = useTranslation("common"); useEffect(() => { @@ -75,10 +76,20 @@ export const useFeedList = (props: Props & T) => { }, [feed.refetch, isRefetching]); useEffect(() => { - if (!isProcessing) { - onRefetch(); + if (!updateFeedAfterPost) { + return; } - }, [isProcessing]); + + const unsubscribe = subscribe((isProcessing) => { + if (!isProcessing) { + onRefetch(); + } + }); + + return () => { + unsubscribe(); + }; + }, [subscribe, updateFeedAfterPost]); return useMemo>(() => ({ data: feedList, diff --git a/src/hooks/use-post-indicator-store.ts b/src/hooks/use-post-indicator-store.ts index 9a08590..b3cbc66 100644 --- a/src/hooks/use-post-indicator-store.ts +++ b/src/hooks/use-post-indicator-store.ts @@ -1,7 +1,17 @@ -import { useContext } from "react"; +import { useCallback, useContext } from "react"; import { PostIndicatorContext } from "@/context/post-indicator-context"; +import { postIndicatorSubscribers } from "@/providers/post-indicator-provider"; export const usePostIndicatorStore = () => { - return useContext(PostIndicatorContext); + const { isProcessing, addPostTask } = useContext(PostIndicatorContext); + + const subscribe = useCallback((callback) => { + postIndicatorSubscribers.add(callback); + return () => { + postIndicatorSubscribers.delete(callback); + }; + }, []); + + return { isProcessing, addPostTask, subscribe }; }; diff --git a/src/pages/Feed/index.tsx b/src/pages/Feed/index.tsx index f05b0a2..d7f0ced 100644 --- a/src/pages/Feed/index.tsx +++ b/src/pages/Feed/index.tsx @@ -94,6 +94,7 @@ export const FeedPage: FC} onScroll={onScroll} contentContainerStyle={{ diff --git a/src/providers/post-indicator-provider.tsx b/src/providers/post-indicator-provider.tsx index 021834d..cc193df 100644 --- a/src/providers/post-indicator-provider.tsx +++ b/src/providers/post-indicator-provider.tsx @@ -25,6 +25,8 @@ interface PostIndicatorProviderProps extends React.PropsWithChildren { } +export const postIndicatorSubscribers: Set<(isProcessing: boolean) => void> = new Set(); + export function PostIndicatorProvider({ children }: PostIndicatorProviderProps) { const [task, setTask] = React.useState(null); const [isProcessing, setIsProcessing] = React.useState(false); @@ -35,6 +37,7 @@ export function PostIndicatorProvider({ children }: PostIndicatorProviderProps) const onPublish = React.useCallback(() => { setIsProcessing(false); + postIndicatorSubscribers.forEach(callback => callback(false)); }, []); const addPostTask = React.useCallback((params: TaskType) => {