我正在使用react- Native -bootsplash (2.2.6)包在我的React Native (0.63.2)应用程序中显示启动画面。
它可以在安卓上运行,但不能在iOS上运行(physical iPhone 8,iOS 14,但它不能在模拟器上运行)。
当我记录包导入时,我真正看到了这两个方法(show和hide)都存在。但是,调用它并没有区别。
我在componentDidMount生命周期和componentDidCatch中称之为它。因为我认为它可能与树下的组件相关,所以我只是呈现了一个视图,而不是我的实际应用程序,它仍然不起作用。
下面是我的AppDelegate.m文件和AppDelegate实现:
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <GoogleMaps/GoogleMaps.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <Firebase.h>
#import <RNCPushNotificationIOS.h>
#import <UserNotifications/UserNotifications.h>
#import "RNBootSplash.h"
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
static void InitializeFlipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addPlugin:[FlipperKitReactPlugin new]];
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
}
#endif
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
[GMSServices provideAPIKey:@"MY_API_KEY"];// add this line using the api key obtained from Google Console
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
#ifdef FB_SONARKIT_ENABLED
InitializeFlipper(application);
#endif
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"BUILDS"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
// I added the following 3 lines per react-native docs against blinking issue when Splash Screen is hiding (I used react-native-splash-screen package before.)
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"BootSplash" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
rootView.loadingView = vc.view;
center.delegate = self;
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // <- initialization using the storyboard file name
return YES;
}


这是我的index.js (注释掉了真实的应用程序,只是使用了一个带有文本的空视图)
import 'react-native-gesture-handler'
if (__DEV__) {
import('./ReactotronConfig').then(() => console.log('Reactotron Configured'))
}
import { AppRegistry } from 'react-native';
// import App from './src/app/App';
import { name as appName } from './app.json';
import RNBootSplash from 'react-native-bootsplash'
import React, { Component } from 'react'
import { Text, View } from 'react-native'
export default class App extends Component {
componentDidMount() {
RNBootSplash.hide()
}
render() {
return (
<View style={ { flex: 1, justifyContent: 'center', alignItems: 'center' } } >
<Text> textInComponent </Text>
</View>
)
}
}
AppRegistry.registerComponent(appName, () => App);
console.disableYellowBox = true;发布于 2020-10-08 04:22:52
我不知道为什么它不工作,为什么它现在工作,但注释掉我在问题中提到的行解决了问题。我刚刚注释掉了以下几行:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"BootSplash" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
rootView.loadingView = vc.view;发布于 2021-04-27 14:53:26
您可能在AppDelegate.m中的某些代码中多次执行splash show
例如,下面的示例将持续显示开机画面。最好将其隐藏/替换为BootSplash代码。
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
rootView.loadingView = vc.view;更新为
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView];确保还隐藏在代码中,例如
RNBootSplash.hide({ fade: true });https://stackoverflow.com/questions/64223293
复制相似问题