我正在使用react-native-bootsplash(2.2.6)软件包在我的React Native(0.63.2)应用程序中显示启动屏幕。
它可以在Android上运行,但是不能在iOS上运行(物理iPhone 8,iOS 14,但是在模拟器上也无法运行)。
当我记录软件包导入时,我确实看到这两种方法(show
和hide
)都存在。
但是,调用它没有区别。
我在componentDidMount
和componentDidCatch
的生命周期中都称呼它。我认为它可能与树下的组件有关,所以我只是渲染了一个View而不是我的实际应用程序,但它仍然无法正常工作。
这是我的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;
答案 0 :(得分:0)
我不知道为什么它不起作用以及为什么现在可以起作用,但是注释掉我在问题中提到的内容可以解决问题。 我只是注释了以下几行:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"BootSplash" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
rootView.loadingView = vc.view;
答案 1 :(得分:0)
您可能通过 AppDelegate.m 中的某些代码多次制作启动画面
例如,下面将保持飞溅显示。最好用 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 });