启动画面没有隐藏。

huangapple go评论57阅读模式
英文:

Splash screen does not hide

问题

我已翻译您提供的文本,以下是翻译好的部分:

我遵循了这篇博客关于iOS的说明:在React Native中构建启动画面

我成功构建了应用程序,并且在打开时显示了启动画面。然而,启动画面从未消失。

这是App.tsx文件:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 */

import React, { useEffect } from 'react';
import type { PropsWithChildren } from 'react';
import {
  SafeAreaView,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  useColorScheme,
  View,
} from 'react-native';
import SplashScreen from "react-native-splash-screen";

import {
  Colors,
  DebugInstructions,
  Header,
  LearnMoreLinks,
  ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';

type SectionProps = PropsWithChildren<{
  title: string;
}>;

function Section({ children, title }: SectionProps): JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';
  return (
    <View style={styles.sectionContainer}>
      <Text
        style={[
          styles.sectionTitle,
          {
            color: isDarkMode ? Colors.white : Colors.black,
          },
        ]}
      >
        {title}
      </Text>
      <Text
        style={[
          styles.sectionDescription,
          {
            color: isDarkMode ? Colors.light : Colors.dark,
          },
        ]}
      >
        {children}
      </Text>
    </View>
  );
}

function App(): JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  useEffect(() => {
    SplashScreen.hide(); // 在应用程序加载时隐藏启动画面。
  }, []);

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar
        barStyle={isDarkMode ? 'light-content' : 'dark-content'}
        backgroundColor={backgroundStyle.backgroundColor}
      />
      <ScrollView
        contentInsetAdjustmentBehavior="automatic"
        style={backgroundStyle}
      >
        <Header />
        <View
          style={{
            backgroundColor: isDarkMode ? Colors.black : Colors.white,
          }}
        >
          <Section title="Step One">
            Edit <Text style={styles.highlight}>App.tsx</Text> to change this
            screen and then come back to see your edits.
          </Section>
          <Section title="Bye world!">
            <ReloadInstructions />
          </Section>
          <Section title="Debug">
            <DebugInstructions />
          </Section>
          <Section title="Learn More">
            Read the docs to discover what to do next:
          </Section>
          <LearnMoreLinks />
        </View>
      </ScrollView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
  },
  sectionDescription: {
    marginTop: 8,
    fontSize: 18,
    fontWeight: '400',
  },
  highlight: {
    fontWeight: '700',
  },
});

export default App;

至于我所知,我已导入了必要的库并按照教程中解释的方式添加了useEffect函数调用。不确定如何开始排除此问题。

以下是AppDelegate.mm文件的翻译:

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import "RNSplashScreen.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleName = @"AwesomeProject2";
  // 您可以在下面的字典中添加自定义初始属性。
  // 它们将传递给React Native使用的ViewController。
  self.initialProps = @{};

  [RNSplashScreen show]; 
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

/// 此方法控制是否启用React18的“concurrentRoot”功能。
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: 这需要在Fabric上呈现(即在新架构上呈现)。
/// @return: 如果启用了“concurrentRoot”功能,则返回`true`。否则,返回`false`。
- (BOOL)concurrentRootEnabled
{
  return true;
}

@end

希望这可以帮助您开始解决问题。如果您有任何其他问题,请随时提出。

英文:

I followed the instructions for this blog for iOS: Building a splash screen in React Native

I was able to get the app built and the splash screen is displayed when open. However, the splash screen never disappears.

Here's the App.tsx file:

/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from &#39;react&#39;;
import type {PropsWithChildren} from &#39;react&#39;;
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from &#39;react-native&#39;;
import React, { useEffect } from &#39;react&#39;; //import useEffect();
import SplashScreen from &quot;react-native-splash-screen&quot;;
import {
Colors,
DebugInstructions,
Header,
LearnMoreLinks,
ReloadInstructions,
} from &#39;react-native/Libraries/NewAppScreen&#39;;
type SectionProps = PropsWithChildren&lt;{
title: string;
}&gt;;
function Section({children, title}: SectionProps): JSX.Element {
const isDarkMode = useColorScheme() === &#39;dark&#39;;
return (
&lt;View style={styles.sectionContainer}&gt;
&lt;Text
style={[
styles.sectionTitle,
{
color: isDarkMode ? Colors.white : Colors.black,
},
]}&gt;
{title}
&lt;/Text&gt;
&lt;Text
style={[
styles.sectionDescription,
{
color: isDarkMode ? Colors.light : Colors.dark,
},
]}&gt;
{children}
&lt;/Text&gt;
&lt;/View&gt;
);
}
function App(): JSX.Element {
const isDarkMode = useColorScheme() === &#39;dark&#39;;
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
useEffect(() =&gt; {
SplashScreen.hide(); //hides the splash screen on app load.
}, []);
return (
&lt;SafeAreaView style={backgroundStyle}&gt;
&lt;StatusBar
barStyle={isDarkMode ? &#39;light-content&#39; : &#39;dark-content&#39;}
backgroundColor={backgroundStyle.backgroundColor}
/&gt;
&lt;ScrollView
contentInsetAdjustmentBehavior=&quot;automatic&quot;
style={backgroundStyle}&gt;
&lt;Header /&gt;
&lt;View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}&gt;
&lt;Section title=&quot;Step One&quot;&gt;
Edit &lt;Text style={styles.highlight}&gt;App.tsx&lt;/Text&gt; to change this
screen and then come back to see your edits.
&lt;/Section&gt;
&lt;Section title=&quot;Bye world!&quot;&gt;
&lt;ReloadInstructions /&gt;
&lt;/Section&gt;
&lt;Section title=&quot;Debug&quot;&gt;
&lt;DebugInstructions /&gt;
&lt;/Section&gt;
&lt;Section title=&quot;Learn More&quot;&gt;
Read the docs to discover what to do next:
&lt;/Section&gt;
&lt;LearnMoreLinks /&gt;
&lt;/View&gt;
&lt;/ScrollView&gt;
&lt;/SafeAreaView&gt;
);
}
const styles = StyleSheet.create({
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: &#39;600&#39;,
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: &#39;400&#39;,
},
highlight: {
fontWeight: &#39;700&#39;,
},
});
export default App;

As far as I can tell, I've imported the necessary libraries and added in the useEffect function call the way the tutorial explained it. Not sure how to begin to troubleshoot this.

And here is the AppDelegate.mm file:

#import &quot;AppDelegate.h&quot;
#import &lt;React/RCTBundleURLProvider.h&gt;
#import &quot;RNSplashScreen.h&quot;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.moduleName = @&quot;AwesomeProject2&quot;;
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};
[RNSplashScreen show]; 
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@&quot;index&quot;];
#else
return [[NSBundle mainBundle] URLForResource:@&quot;main&quot; withExtension:@&quot;jsbundle&quot;];
#endif
}
/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
return true;
}
@end

答案1

得分: 7

2023年6月23日解决方案 - React Native "0.72.0" 启动画面不隐藏的问题 AppDelegate.mm

在搜索了“web 2”的解决方案后,我找到了以下方法来解决这个问题...

App.tsx 文件 - 导入和 useEffect

  import SplashScreen from 'react-native-splash-screen';

  useEffect(() => {
    const ac = new AbortController();

    setTimeout(() => {
      SplashScreen.hide();
    }, 10000);

    return function cleanup() {
      ac.abort();
    };
  }, []);

AppDelegate.mm 文件

#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import "RNSplashScreen.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleName = @"Closer";
  // 您可以在下面的字典中添加自定义的初始属性。
  // 它们将传递给React Native使用的ViewController。
  self.initialProps = @{};
  
  [super application:application didFinishLaunchingWithOptions:launchOptions];
  [RNSplashScreen show];
  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

就这些了! 🤓

英文:

June 23rd 2023 Solution - React Native "0.72.0" splash screen not hiding AppDelegate.mm

After scraping the "web 2" for a solution, I got it to work using the following...

App.tsx file - import and useEffect

  import SplashScreen from &#39;react-native-splash-screen&#39;;
useEffect(() =&gt; {
const ac = new AbortController();
setTimeout(() =&gt; {
SplashScreen.hide();
}, 10000);
return function cleanup() {
ac.abort();
};
}, []);

AppDelegate.mm file

#import &quot;AppDelegate.h&quot;
#import &lt;React/RCTBundleURLProvider.h&gt;
#import &quot;RNSplashScreen.h&quot;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.moduleName = @&quot;Closer&quot;;
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};
[super application:application didFinishLaunchingWithOptions:launchOptions];
[RNSplashScreen show];
return YES;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@&quot;index&quot;];
#else
return [[NSBundle mainBundle] URLForResource:@&quot;main&quot; withExtension:@&quot;jsbundle&quot;];
#endif
}
@end

That's all folks! 😜

答案2

得分: 1

I have this exact problem, and it seems like we're not alone (Source 1, Source 2). It appears that the library is no longer maintained (Source 3, Source 4).

Consider switching to react-native-bootsplash. It has worked perfectly for me. It appears to be the new standard.

英文:

I have this exact problem, and it seems like we're not alone (Source 1, Source 2). It appears that the library is no longer maintained (Source 3, Source 4).

Consider switching to react-native-bootsplash. It has worked perfectly for me. It appears to be the new standard.

答案3

得分: 0

我有完全相同的问题。
return YES;之前调用[RNSplashScreen show];,对某些人来说是解决办法,但对我并没有解决。

甚至明确地隐藏启动屏幕,如下所示

-(void)applicationDidBecomeActive:(UIApplication *)application 
{
   [RNSplashScreen hide];
}

也无法隐藏启动屏幕。在我升级react-native后,这个问题突然出现了,看起来对很多人都是个问题,正如Daniels提出的,我认为bootsplash可能是正确的解决方法。

英文:

I have the exact same problem.
Calling [RNSplashScreen show]; right before the return YES; which is the solution for some also does not solve this.

Even hiding the splash screen explicitly like this

-(void)applicationDidBecomeActive:(UIApplication *)application 
{
[RNSplashScreen hide];
}

does not hide the splash screen. This appeared for me all of a sudden after upgrading react-native and it seems to be a problem for many, as Daniels proposes I think bootsplash is the way to go.

答案4

得分: 0

This worked for me.

Mentioned here: (https://github.com/crazycodeboy/react-native-splash-screen/issues/71#issuecomment-1743383657)

[RNSplashScreen show]; return [super application:application didFinishLaunchingWithOptions:launchOptions];

to

BOOL ret = [super application:application didFinishLaunchingWithOptions:launchOptions]; if (ret == YES) { [RNSplashScreen show]; } return ret;

I encountered this issue with:
"react-native": "0.72.4"
"react-native-splash-screen": "^3.3.0"

英文:

This worked for me.

Mentioned here: (https://github.com/crazycodeboy/react-native-splash-screen/issues/71#issuecomment-1743383657)

[RNSplashScreen show];  return [super application:application didFinishLaunchingWithOptions:launchOptions];

to

BOOL ret = [super application:application didFinishLaunchingWithOptions:launchOptions]; if (ret == YES) { [RNSplashScreen show];  } return ret;

I encountered this issue with:
"react-native": "0.72.4"
"react-native-splash-screen": "^3.3.0"

huangapple
  • 本文由 发表于 2023年4月20日 02:55:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057963.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定