Created
May 20, 2025 05:49
-
-
Save toy-crane/ec62586bb28e0cd750ebd8820090f7bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Updates from 'expo-updates'; | |
import * as SplashScreen from 'expo-splash-screen'; | |
import { useEffect, useState } from 'react'; | |
import { View, Text, StyleSheet } from 'react-native'; | |
// 스플래시 화면 유지 | |
SplashScreen.preventAutoHideAsync(); | |
export default function App() { | |
const [appIsReady, setAppIsReady] = useState(false); | |
useEffect(() => { | |
async function prepareApp() { | |
try { | |
if (__DEV__) { | |
// 개발 모드에서는 업데이트 체크 생략 | |
setAppIsReady(true); | |
return; | |
} | |
// 업데이트 확인 및 다운로드 | |
const update = await Updates.checkForUpdateAsync(); | |
if (update.isAvailable) { | |
await Updates.fetchUpdateAsync(); | |
// 업데이트 적용 (즉시 재시작) | |
await Updates.reloadAsync(); | |
} | |
} catch (e) { | |
console.error('업데이트 확인 실패:', e); | |
} finally { | |
// 업데이트 여부와 관계없이 앱 준비 완료 | |
setAppIsReady(true); | |
} | |
} | |
prepareApp(); | |
}, []); | |
// 앱이 준비되면 스플래시 화면 숨기기 | |
useEffect(() => { | |
if (appIsReady) { | |
SplashScreen.hideAsync(); | |
} | |
}, [appIsReady]); | |
if (!appIsReady) { | |
// 스플래시 화면 대체 UI (필요 시 커스텀) | |
return ( | |
<View style={styles.container}> | |
<Text>Loading...</Text> | |
</View> | |
); | |
} | |
return ( | |
<View style={styles.container}> | |
<Text>앱 메인 화면</Text> | |
{/* 앱의 나머지 컴포넌트 */} | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment