React native: TypeError: null is not an object (evaluating 'SplashScreen.preventAutoHide')
The AppLoading component is not available in the bare workflow. As @gaurav-roy said you have to refactor your code.
Install the
expo-splash-screen
package withnpm install expo-splash-screen
Add a splash-screen to your Android and iOS projects. Run
npm run expo-splash-screen --help
and follow the instructions of this CLI tool. (Because of a bug you might have to run the command again with the-p "ios"
flag if it only adds the SplashScreen for Android after running it.Change your code inside
App.tsx
in a similar way as in this example.If you're working with hooks you probably want to add an
useEffect
hook with an empty dependency list which runs an async function. Here an example of how it could be done:
const App = (props: Props) => {
const [isLoadingComplete, setLoadingComplete] = useState(false);
const init = async () => {
try {
// Keep on showing the SlashScreen
await SplashScreen.preventAutoHideAsync();
await loadResourcesAsync();
} catch (e) {
console.warn(e);
} finally {
setLoadingComplete(true);
// Hiding the SplashScreen
await SplashScreen.hideAsync();
}
useEffect(() => {
init();
}, []);
const renderApp = () => {
if (!isLoadingComplete && !props.skipLoadingScreen) {
return null;
}
return (
<Main />
);
};
return <StoreProvider>{renderApp()}</StoreProvider>;
}
As its evident from docs , SplashScreen is an inbuilt api for expo apps, and since you ejected it , it throws an error since it cant be used.
You can see this in the docs expo splashscreen .
First you should download npm i expo-splash-screen
And then change your import statement to :
import * as SplashScreen from 'expo-splash-screen';
Hope it helps. feel free for doubts