Skip to content

Commit e6492a3

Browse files
authored
Merge pull request #17 from codenapse/master
ios: ability to use a custom image name for splash screen, allowing re-use of LaunchScreen.xib
2 parents bb32bf9 + 1679cac commit e6492a3

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ npm install react-native-smart-splash-screen --save
2929

3030
* In your project, Look for Header Search Paths and make sure it contains $(SRCROOT)/../node_modules/react-native-smart-splash-screen/ios/RCTSplashScreen/RCTSplashScreen
3131

32-
* delete your project's LaunchScreen.xib
33-
34-
* Dray SplashScreenResource folder to your project *if you want change image, replace splash.png*
32+
* Click on LaunchScreen.xib > right utilities panel "Attributes Inspector" > get the name of the image used (labeled "Image") (PS: you should follow the Apple XCode guide to set the LaunchScreen if there's not Image field set)
3533

3634
* In AppDelegate.m
3735

@@ -45,7 +43,7 @@ RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
4543
initialProperties:nil
4644
launchOptions:launchOptions];
4745
48-
[RCTSplashScreen open:rootView]; //activate splashscreen
46+
[RCTSplashScreen open:rootView withImageNamed:@"image-name-from-LaunchScreen.xib"]; // activate splashscreen, imagename from LaunchScreen.xib
4947
5048
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
5149

ios/RCTSplashScreen/RCTSplashScreen/RCTSplashScreen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ typedef NS_ENUM(NSInteger, RCTCameraAspect) {
1010
};
1111

1212
+ (void)open:(RCTRootView *)v;
13+
+ (void)open:(RCTRootView *)v withImageNamed:(NSString *)imgName;
1314

1415
@end

ios/RCTSplashScreen/RCTSplashScreen/RCTSplashScreen.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,27 @@ @implementation RCTSplashScreen
1111

1212
RCT_EXPORT_MODULE(SplashScreen)
1313

14+
1415
+ (void)open:(RCTRootView *)v {
16+
[RCTSplashScreen open:v withImageNamed:@"splash"];
17+
}
18+
19+
20+
+ (void)open:(RCTRootView *)v withImageNamed:(NSString *)imageName {
1521
rootView = v;
22+
1623
UIImageView *view = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
17-
view.image = [UIImage imageNamed:@"splash"];
24+
25+
view.image = [UIImage imageNamed:imageName];
1826

1927
[[NSNotificationCenter defaultCenter] removeObserver:rootView name:RCTContentDidAppearNotification object:rootView];
2028

2129
[rootView setLoadingView:view];
2230
}
2331

32+
33+
34+
2435
RCT_EXPORT_METHOD(close:(NSInteger *)animationType
2536
duration:(NSInteger)duration
2637
delay:(NSInteger)delay) {

0 commit comments

Comments
 (0)