[英]Customize Default Splash Screen of react-native
有什么辦法可以去掉 react-native 的默認啟動畫面。 或自定義默認啟動畫面。 就像我想在啟動畫面中添加加載欄和淡入淡出效果一樣。 我想為公司和應用程序創建 2 個啟動畫面。 是否可以更改加載時間?
如果您只想將圖像設置為啟動畫面,您可以像這樣修改您的 app.json ,
如果你想做一個動畫飛濺,你可以使用'expo-splash-screen'
。 我曾經使用過這段代碼。 最重要的部分是preventAutoHideAsync().catch(console.warn);
將 animation 顯示為應用程序中的第一個組件,並在hideAsync().catch(console.warn);
您繼續執行您的應用程序。
import 'react-native-gesture-handler';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
import Home from '_screens/Home';
import Splash from '_screens/Splash';
import { preventAutoHideAsync, hideAsync } from 'expo-splash-screen';
import React, { useState, useEffect } from 'react';
/* expo-splash-screen works fine but raise an exception because the managed expo workflow
* use the old version of this library, however a fix was merged and probably in the next version of
* expo this will be fixed, about this error https://github.com/expo/expo/issues/8067
*/
preventAutoHideAsync().catch(console.warn);
export type RootStackParamList = {
Home: undefined;
};
export default function App(): JSX.Element {
const [isLoadingSplash, setIsLoadingSplash] = useState(true);
const Drawer = createDrawerNavigator();
const init = (): void => {
setTimeout(async () => {
hideAsync().catch(console.warn);
setIsLoadingSplash(false);
}, 5000);
};
useEffect(() => {
init();
}, []);
return (
<>
{isLoadingSplash && <Splash />}
{!isLoadingSplash && (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Login" component={Login} />
<Drawer.Screen name="Home" component={Home} />
</Drawer.Navigator>
</NavigationContainer>
)}
</>
);
}
如果要更改默認啟動畫面的圖片,請考慮 android。
轉到android\app\src\main\res\drawable
然后更改圖片splashscreen_image.png
您也可以在那里編輯splashscreen.xml
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.