admin管理员组文章数量:1277910
I'm working on a React Native app using Expo SDK 52. I'm having a problem the splash screen. The app works fine on the development build and through Expo Go, but it stays stuck infinitely on the splash screen when I run it from a preview build. It doesn't timeout or show any errors. I thought there was something wrong with the login screen so I deleted everything and left just a basic hello world, it still gets stuck on the splash screen. Another post suggested I install some packages from .x/upgrading-from-5.x/ but that never helped.
import * as SplashScreen from "expo-splash-screen";
// Prevent splash screen auto-hiding
SplashScreen.preventAutoHideAsync();
const App = () => {
const [appIsReady, setAppIsReady] = useState(false);
const [pushToken, setPushToken] = useState(null);
const [loaded, setLoaded] = useState(false);
// In App component's prepare function
useEffect(() => {
async function prepare() {
try {
await SplashScreen.preventAutoHideAsync();
// Load all resources
await Promise.all([
Font.loadAsync({
'Poppins': require('./fonts/Poppins-Regular.ttf'),
}),
registerForPushNotificationsAsync().then(token => setPushToken(token)),
new Promise(resolve => {
const unsubscribe = onAuthStateChanged(auth, user => {
unsubscribe();
resolve();
});
})
]);
// Mark resources loaded
setLoaded(true);
} catch (e) {
console.warn(e);
}
}
prepare();
}, []);
useEffect(() => {
if (loaded) {
// Safety timeout to ensure splash screen hides
const timeout = setTimeout(async () => {
await SplashScreen.hideAsync();
setAppIsReady(true);
}, 500);
return () => clearTimeout(timeout);
}
}, [loaded]);
if (!appIsReady) {
return null;
}
I'm working on a React Native app using Expo SDK 52. I'm having a problem the splash screen. The app works fine on the development build and through Expo Go, but it stays stuck infinitely on the splash screen when I run it from a preview build. It doesn't timeout or show any errors. I thought there was something wrong with the login screen so I deleted everything and left just a basic hello world, it still gets stuck on the splash screen. Another post suggested I install some packages from https://reactnavigation./docs/6.x/upgrading-from-5.x/ but that never helped.
import * as SplashScreen from "expo-splash-screen";
// Prevent splash screen auto-hiding
SplashScreen.preventAutoHideAsync();
const App = () => {
const [appIsReady, setAppIsReady] = useState(false);
const [pushToken, setPushToken] = useState(null);
const [loaded, setLoaded] = useState(false);
// In App component's prepare function
useEffect(() => {
async function prepare() {
try {
await SplashScreen.preventAutoHideAsync();
// Load all resources
await Promise.all([
Font.loadAsync({
'Poppins': require('./fonts/Poppins-Regular.ttf'),
}),
registerForPushNotificationsAsync().then(token => setPushToken(token)),
new Promise(resolve => {
const unsubscribe = onAuthStateChanged(auth, user => {
unsubscribe();
resolve();
});
})
]);
// Mark resources loaded
setLoaded(true);
} catch (e) {
console.warn(e);
}
}
prepare();
}, []);
useEffect(() => {
if (loaded) {
// Safety timeout to ensure splash screen hides
const timeout = setTimeout(async () => {
await SplashScreen.hideAsync();
setAppIsReady(true);
}, 500);
return () => clearTimeout(timeout);
}
}, [loaded]);
if (!appIsReady) {
return null;
}
Share
Improve this question
asked Feb 24 at 8:34
Kyle MabasoKyle Mabaso
631 silver badge6 bronze badges
2 Answers
Reset to default 0Here are some additional dependencies you might be missing (which are not mentioned in the link you have posted):
- react-native-reanimated
- react-native-gesture-handler
If that doesn't fix it, I suggest you try LogCat
from android studio and see the logs in real time when you launch the application. You'll find some clue about why it won't go past the splash screen.
i think the issue is u call SplashScreen.preventAutoHideAsync();
this method 2 times which is not exactly required as Your Code is more like in the documentation of splashScreen in expo docs,
i think u need to check this, i found this line in expo docs for splashscreen : Important note: It is recommended to call this in global scope without awaiting, rather than inside React components or hooks, because otherwise this might be called too late, when the splash screen is already hidden.
this works in expo go as the expo go environmnet handles the edge case scenerios which differ from the actual app,
i suggest u to use development build
instead for better development environment
i hope so u understand what im explaning!!
本文标签: React Native Expo App stuck infinitely on the splash screen in preview buildStack Overflow
版权声明:本文标题:React Native Expo App stuck infinitely on the splash screen in preview build - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741285623a2370251.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论