简体   繁体   English

Create-React-App中的启动画面

[英]Splash screen in Create-React-App

I'm using create-react-app to design a PWA. 我正在使用create-react-app来设计PWA。 The default Splash screen provided by the App is an icon (in middle of the screen) and a name of the app below that icon. 应用程序提供的默认启动画面是一个图标(位于屏幕中间)以及该图标下方的应用程序名称。 Icon & name must be provided in the manifest file. 必须在清单文件中提供图标和名称。

Question: Is there any way to customize the Splash Screen instead of using the default one? 问题:有没有办法自定义启动画面而不是使用默认屏幕?

Following is the possible solution but searching for a better way to do that. 以下是可能的解决方案,但寻找更好的方法来做到这一点。

Possible Solution: 可能解决方案

  1. Add a component for Splash Screen. 为Splash Screen添加组件。
  2. On the main component, render SplashScreen component untill the API response is returned from the server. 在主要组件上,渲染SplashScreen组件,直到从服务器返回API响应。 I am using renderSplashscreen state for rendering the SplashScreen component. 我使用renderSplashscreen状态来渲染SplashScreen组件。

     // Component for Splash Screen class SplashScreen extends React.Component { render() { const style = {top: 0, bottom: 0, right: 0, left: 0, position: 'fixed'}; return ( <img src={'IMAGE-URL'} style={style}/> ); } } class MainComponent extends React.Component { constructor(props) { this.state = { renderSplashscreen: true }; } apiCallback(data) { // After getting the API response from server this.setState({renderSplashscreen: false}); } render() { let view; if(this.state.renderSplashscreen) return <SplashScreen/>; else return <OtherComponent/> } } 

Here's my own possible solution added in the question, as for now, this is the only solution that works well. 这是我在问题中添加的自己可能的解决方案 ,目前,这是唯一运行良好的解决方案。

  1. Add a component for Splash Screen. 为Splash Screen添加组件。
  2. On the main component, render SplashScreen component untill the API response is returned from the server. 在主要组件上,渲染SplashScreen组件,直到从服务器返回API响应。 I am using renderSplashscreen state for rendering the SplashScreen component. 我使用renderSplashscreen状态来渲染SplashScreen组件。

     // Component for Splash Screen class SplashScreen extends React.Component { render() { const style = {top: 0, bottom: 0, right: 0, left: 0, position: 'fixed'}; return ( <img src={'IMAGE-URL'} style={style}/> ); } } class MainComponent extends React.Component { constructor(props) { this.state = { renderSplashscreen: true }; } apiCallback(data) { // After getting the API response from server this.setState({renderSplashscreen: false}); } render() { let view; if(this.state.renderSplashscreen) return <SplashScreen/>; else return <OtherComponent/> } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM