feat: 앱 이름 '날씨각'·해 아이콘·스플래시, 위치 찾기 10초 제한, 첫 로딩 덮개가 안 걷히던 것 수정
This commit is contained in:
1 parent
b5d9adf396
commit
4fc9214de5
27 files changed
+30
-61
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import type { TimeKind } from '@nalssigak/shared/lib';
|
||||
import { useIsFetching } from '@tanstack/react-query';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { StyleSheet, Text, View } from 'react-native';
|
||||
import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withRepeat, withSequence, withTiming } from 'react-native-reanimated';
|
||||
@@ -38,19 +38,23 @@ function Hop({ name }: { name: string }) {
|
||||
|
||||
/** 처음 들어올 때만: 첫 데이터를 다 받을 때까지 하늘 위에 캐릭터와 '날씨 불러오는 중…'. 한 번 사라지면 다시 안 뜬다 */
|
||||
export function FirstLoad() {
|
||||
const fetching = useIsFetching();
|
||||
const queryClient = useQueryClient();
|
||||
const { kind } = useSky();
|
||||
const [started, setStarted] = useState(false);
|
||||
const [done, setDone] = useState(false);
|
||||
const [gone, setGone] = useState(false);
|
||||
// 받기 시작했다가 받는 게 없어지면 끝 (렌더 중에 바로 맞춘다)
|
||||
if (fetching > 0 && !started) setStarted(true);
|
||||
if (fetching === 0 && started && !done) setDone(true);
|
||||
// 느린 망에서도 10초 넘게 막지 않는다 (그 뒤는 화면 안 스켈레톤이 맡는다)
|
||||
// 받기 시작했다가 받는 게 없어지면 끝. 느린 망에서도 10초 넘게 막지 않는다 (그 뒤는 화면 안 스켈레톤이 맡는다)
|
||||
useEffect(() => {
|
||||
let seen = false;
|
||||
const unsubscribe = queryClient.getQueryCache().subscribe(() => {
|
||||
if (queryClient.isFetching() > 0) seen = true;
|
||||
else if (seen) setDone(true);
|
||||
});
|
||||
const id = setTimeout(() => setDone(true), 10000);
|
||||
return () => clearTimeout(id);
|
||||
}, []);
|
||||
return () => {
|
||||
unsubscribe();
|
||||
clearTimeout(id);
|
||||
};
|
||||
}, [queryClient]);
|
||||
const shown = useSharedValue(1);
|
||||
useEffect(() => {
|
||||
if (!done) return;
|
||||
|
||||
@@ -29,11 +29,16 @@ function readStored(): RegionData | null {
|
||||
}
|
||||
}
|
||||
|
||||
/** 위치를 못 잡으면(실내·에뮬레이터) 끝없이 기다리지 않게 웹처럼 10초에 끊는다 */
|
||||
function withTimeout<T>(p: Promise<T>, ms: number): Promise<T> {
|
||||
return Promise.race([p, new Promise<never>((_, reject) => setTimeout(() => reject(new Error('위치 찾기 시간 초과')), ms))]);
|
||||
}
|
||||
|
||||
/** 위치 권한을 받아 가장 가까운 구. 권한이 없으면 'denied' */
|
||||
async function findNearest(): Promise<RegionData | 'denied'> {
|
||||
const { status } = await Location.requestForegroundPermissionsAsync();
|
||||
if (status !== 'granted') return 'denied';
|
||||
const pos = (await Location.getLastKnownPositionAsync({ maxAge: 600000 })) ?? (await Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.Balanced }));
|
||||
const pos = (await Location.getLastKnownPositionAsync({ maxAge: 600000 })) ?? (await withTimeout(Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.Balanced }), 10000));
|
||||
const { data } = await nearestRegion({ query: { lat: pos.coords.latitude, lon: pos.coords.longitude } });
|
||||
if (!data.region) throw new Error('가까운 구를 찾지 못함');
|
||||
return data.region;
|
||||
|
||||
Reference in new issue
Block a user