有什么方法可以删除默认的本机“启动”屏幕。或修改默认启动屏幕。就像我想在初始屏幕中添加加载栏和淡入淡出效果一样。我想为公司和应用创建2个初始屏幕。可以更改加载时间吗?
答案 0 :(得分:0)
如果您只想将图像设置为启动画面,则可以像this那样修改app.json,
如果要进行动画飞溅,可以使用'expo-splash-screen'
。我曾经使用这段代码。最重要的部分是preventAutoHideAsync().catch(console.warn);
,该动画将动画显示为应用程序中的第一个组件,在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>
)}
</>
);
}
答案 1 :(得分:0)
如果您想更改默认启动画面的图片,请考虑将其用于 android。
转到android\app\src\main\res\drawable
然后更改图片splashscreen_image.png
您也可以在那里编辑 splashscreen.xml