Please provide the following:
- SDK Version: 39.0.2
- Platforms(Android/iOS/web/all): iOS
- Add the appropriate “Tag” based on what Expo library you have a question on.
Hi everybody, i looking for some help with expo-splash-screen
See, i’m getting this error and a white screen when testing my app in expo iOS client (Production mode) and when test my standalone app on iOS Test Flight but not in android
[Error: Native splash screen is already hidden. Call this method before rendering any view.]
so, basically, i prevent the splash from hiding in my app.js this is the code
import React, {
useState,
useReducer,
useCallback,
useMemo,
useEffect,
} from "react";
import { View, StatusBar, SafeAreaView, StyleSheet } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import * as SplashScreen from "expo-splash-screen";
import AsyncStorage from "@react-native-community/async-storage";
import {
AuthContext,
SettingContext,
} from "./src/contexts/index";
import { authInitialState, authReducer } from "./src/reducers/auth";
import { settingReducer } from "./src/reducers/setting";
const Stack = createStackNavigator();
export default function App() {
const [isAppReady, setIsAppReady] = useState(false);
const [splashScreenClosed, setSplashScreenClosed] = useState(false);
const [authState, authDispatch] = useReducer(authReducer, authInitialState);
const [settingState, settingDispatch] = useReducer(settingReducer, {});
const authContext = useMemo(
() => ({
signIn: () => authDispatch({ type: "SIGN_IN" }),
signOut: () => authDispatch({ type: "SIGN_OUT" }),
),
[authState.user]
);
//Settings
const settingContext = useMemo(
() => ({
setSetting: (setting) => settingDispatch({ type: "SET", setting }),
setting: settingState,
}),
[settingState]
);
useEffect(() => {
const fetchCommonData = async () => {
firestore
.collection("mycollection")
.doc("client")
.onSnapshot(
(doc) => {
settingContext.setSetting(doc.data());
},
(error) => console.error(error)
);
const providersResult = await firestore.collection("providers").get();
const providers = providersResult.docs.map((doc) => ({
id: doc.id,
...doc.data(),
}));
providersContext.addProviders(providers);
};
//AsyncStorage.clear();
const initApp = async () => {
await SplashScreen.preventAutoHideAsync();
await fetchCommonData();
const storage = await AsyncStorage.getItem(KEY);
};
initApp()
.then(() => {
firebase.auth().onAuthStateChanged(
async (user) => {
if (user) {
firestore
.collection("mycollection")
.doc(user.uid)
.onSnapshot(
async (doc) => {
const userInfo = { id: user.uid, ...doc.data() };
authContext.updateLoggedInUser(userInfo);
authContext.signIn();
setIsAppReady(true);
},
() => {}
);
} else {
authContext.signOut();
cleanAllDataState();
setIsAppReady(true);
}
},
() => {}
);
})
.catch((error) => {
console.error(error);
});
}, []);
const onLayoutRootView = useCallback(async () => {
if (isAppReady && !splashScreenClosed) {
setSplashScreenClosed(true);
await SplashScreen.hideAsync();
}
}, [isAppReady, splashScreenClosed]);
if (!isAppReady) return null;
return (
<View style={{ ...StyleSheet.absoluteFill }} onLayout={onLayoutRootView}>
<AuthContext.Provider value={authContext}>
<SafeAreaView />
<StatusBar
/>
<SettingContext.Provider value={settingContext}>
<NavigationContainer
>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="Main" component={MainTab} />
</Stack.Navigator>
</NavigationContainer>
</SettingContext.Provider>
</AuthContext.Provider>
</View>
);
}
my app prevent the splash from closing before loading some data and then closes de splash screen but i get the error message. is there something i’m missing?