LaunchScreen์ ๋ํ ๋ชจ๋ฒ ์ฌ๋ก๊ฐ ์๋์ง ๊ถ๊ธํฉ๋๋ค. ๋ด๊ฐ ์ด๊ฒ์ ๋ฌป๋ ์ด์ ๋ LaunchScreen์ ์ถ๊ฐํ๋ฉด ๋ฐ์ ๋ค์ดํฐ๋ธ๊ฐ ์์๋๊ณ ์ฑ์ ๋ก๋ํ๊ธฐ ์ ์ ํฐ์ ํ๋์๊ฐ ์๊ธฐ ๋๋ฌธ์ ๋๋ค. ์ด๋ฅผ ๋ฐฉ์งํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
@alinz - ๋ค์ ๋ฆด๋ฆฌ์ค์์ ์์ ๋์์ต๋๋ค. https://github.com/tadeuzagallo/react-native/commit/8d992262ed2dcf0d46e8d22e605764902c33012f
@alinz ๋ https://www.dropbox.com/s/xq522ywqsd16vqe/example.mov?dl=0 ๊ณผ ๊ฐ์ด ๋ณด ์ ๋๊น?
@liubko ๋ค, ๋ฐ๋ก ์ด๊ฒ์ด ์ ๊ฐ ์์ ๊ณ ์ถ์ ๊ฒ์ ๋๋ค. ์์ง ํจ์น๋ฅผ ์ ์ฉํ์ง ์์์ง๋ง ์ค๋ ๋ฐค์ ํ ๊ฒ์ ๋๋ค.
@brentvatne : ๊ทธ ํจ์น๊ฐ ์ด ๋ฌธ์ ๋ฅผ ์ด๋ป๊ฒ ๊ณ ์น ์ง ๋ชจ๋ฅด๊ฒ ๋ค(๋ด๊ฐ ์ฅ๋/๋ฐ๋ณด๋ผ๋ฉด ์ฉ์ํด ์ฃผ์ธ์ :-). ๋ฌธ์ ๋ ์ฑ์ด ์์๋๊ณ React๊ฐ ์ฌ์ ํ ์๋ํ๋ ์ฌ์ด์ ์๊ฐ์ด ์๋ค๋ ๊ฒ์ ๋๋ค. ์ด์์ ์ผ๋ก LaunchScreen์ React๊ฐ ์๋ฃ๋๊ณ "์์ ๋ค์ดํฐ๋ธ" ์ฑ์์์ ๊ฐ์ด ์์ ํ ๋ ๋๋ง๋ ๋๊น์ง ํ์๋ฉ๋๋ค.
@oblador - ์, ์ด๋ ๊ฒ ํ๋ฉด "๊น๋ฐ์" ์๊ฐ์ ์์ ํ๋ฉด๊ณผ ๋์ผํ ๋ฐฐ๊ฒฝ์์ ์ฌ์ฉํ์ฌ ๋ ๋ถ๋๋ฝ๊ฒ ์ ํํ ์ ์์ต๋๋ค.
@vjeux - FB ์ฑ์์ ์ด ๋ฌธ์ ๋ฅผ ์ด๋ป๊ฒ ๊ทน๋ณตํฉ๋๊น? ๋ด๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์ดํดํ๋ฉด 100% React Native์ธ F8์ด ์์ ํ๋ฉด์์ ์ฑ์ผ๋ก ์ง์ ์ ํ๋๋ค๋ ๊ฒ์ ์์์ต๋๋ค. cc @nicklockwood
์ด ๋ฌธ์ ์ ๋ํ (๋ณ๋์) ์์ ์ฌํญ๋ ์์ต๋๋ค. RCTRootView
์ ์๋ก์ด loadingView
์์ฑ์ ์ฌ์ฉํ๊ณ ์์ ์ด๋ฏธ์ง๋ฅผ ํ์ํ๋ ์ ์ฒด ํ๋ฉด UIImageView
ํฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ ์ ์์ต๋๋ค.
UIImageView *launchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MyLaunchImage"];
rootView.loadingView = launchView;
๋ฐ์ฌ ์ด๋ฏธ์ง๋ฅผ ์๋์ผ๋ก ๊ฐ์งํ์ฌ ์ด๋ฅผ ์์ ํ ์๋์ผ๋ก ๋ง๋๋ ๋ฐฉ๋ฒ์ ์คํํด ์์ง๋ง ์์ง ์ค๋น๊ฐ ์๋ฃ๋์ง ์์์ต๋๋ค. ๊ด์ฌ์ด ์๋ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด ํ์๋ฉ๋๋ค.
// TODO: support landscape orientation
// Get launch image
NSString *launchImageName = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGFloat height = MAX(RCTScreenSize().width, RCTScreenSize().height);
if (height == 480) launchImageName = @"[email protected]"; // iPhone 4/4s
else if (height == 568) launchImageName = @"[email protected]"; // iPhone 5/5s
else if (height == 667) launchImageName = @"[email protected]"; // iPhone 6
else if (height == 736) launchImageName = @"[email protected]"; // iPhone 6+
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CGFloat scale = RCTScreenScale();
if (scale == 1) launchImageName = @"LaunchImage-700-Portrait~ipad.png"; // iPad
else if (scale == 2) launchImageName = @"LaunchImage-700-Portrait@2x~ipad.png"; // Retina iPad
}
// Create loading view
UIImage *image = [UIImage imageNamed:launchImageName];
if (image) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:(CGRect){CGPointZero, RCTScreenSize()}];
imageView.contentMode = UIViewContentModeBottom;
imageView.image = image;
rootView.loadingView = imageView;
}
@nicklockwood๊ฐ ์ค๋ช ํ ๊ฒ์ ๋ํ ์ฌ์ด ํด๊ฒฐ์ฑ ์ iOS 8 ์ด์์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์คํ ํ๋ฉด xib๋ฅผ ๋ก๋ํ๋ ๊ฒ์ ๋๋ค.
@ide ๋๋ launchscreen xib๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์์ ์ lauchscreen ๋ณด๊ธฐ๊ฐ ํ์๋์ง๋ง ์ฑ์ด ๋ถํ ๋๊ธฐ ์ ์ ํฐ์ ๋ณด๊ธฐ(ํ๋์)๊ฐ ํ์๋ฉ๋๋ค.
@alinz , @ide ๋ launchscreen xib๋ฅผ ์ฌ์ฉํ์ฌ RCTRootView loadingView๋ฅผ ์ค์ ํ๋ ๊ฒ์ ์๋ฏธํ๋ค๊ณ ์๊ฐํฉ๋๋ค(์ฌ์ ํ ์๋์ผ๋ก ์ํํด์ผ ํจ). (์์ง) ๊ทธ๋ ๊ฒ ํ๊ธฐ ์ํ ์๋ ์ง์์ ์์ต๋๋ค.
๋ช ํํ ํ์๋ฉด iOS๋ React๊ฐ ๋ก๋ฉ์ _์์_ํ๋ ์์ ์ ์์ ํ๋ฉด์ ์จ๊น๋๋ค. ๋น ํ๋ฉด์ด ํ์๋์ง ์๋๋ก ํ๋ ค๋ฉด RCTRootView์ loadingView์ ๋์ผํ ๋ณด๊ธฐ๋ฅผ ์๋์ผ๋ก ํ์ํ์ฌ ์์ ํ๋ฉด์ด ํ์๋๋ ์๊ฐ์ ์ฐ์ฅํด์ผ ํฉ๋๋ค.
@nicklockwood ์ ์ค๋ช ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๊ทธ๊ฒ ๋ด ์๋ชป์ด์๋ค. :)
http://stackoverflow.com/a/29115477/255765์ Curtesy ๋๋ ์ด๊ฒ์ผ๋ก ๋๋ฌ์ต๋๋ค.
for (NSString *imgName in allPngImageNames){
// Find launch images
if ([imgName containsString:@"LaunchImage"]){
UIImage *img = [UIImage imageNamed:imgName]; //-- this is a launch image
// Has image same scale and dimensions as our current device's screen?
if (img.scale == [UIScreen mainScreen].scale && CGSizeEqualToSize(img.size, [UIScreen mainScreen].bounds.size)) {
NSLog(@"Found launch image for current device %@", img.description);
UIImageView *launchView = [[UIImageView alloc] initWithImage: img];
rootView.loadingView = launchView;
}
}
}
์๋ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
ํ์ค/๋ฌธ์ํ๋ ๋ฐฉ๋ฒ์ ๊ฒฝ์ฐ +1์ ๋๋ค.
@dvine-multimedia๊ฐ ์์์ ์ ๊ณตํ ์ฝ๋ ์กฐ๊ฐ๋ณด๋ค ๋ ์ ์๋ํฉ๋๊น?
@myusuf3
@nicklockwood ์ค์ ๋ก ๊ทธ๋ค์ ๊ฑฐ์ ๊ฐ์ ์ผ์ ํฉ๋๋ค. ๋ด๊ฐ ์ด๊ฒ์ ์กฐ์ฌํ๊ธฐ ์์ํ์ ๋ ๋๋ xcode ๊ฒฝํ์ด ์ ํ ์๊ธฐ ๋๋ฌธ์ ๋น์ ์ ์ค๋ํ์ผ๋ก ๋ฌด์์ ํด์ผ ํ๋์ง ์ดํดํ์ง ๋ชปํ์ ๊ฒ์ ๋๋ค. ๋ง์นจ๋ด ๋ด๊ฐ ๋ฌด์์ ํด์ผ ํ๋์ง ์ดํดํ๋ ์ง์ ์ ์ด๋ฅด๋ ์ ๋, ๋๋ ๋น์ ์ด ์ด๋ฏธ ๊ฑฐ๊ธฐ์ ์์๋ค๋ ๊ฒ์ ๊นจ๋ซ์ง ๋ชปํ์ต๋๋ค. ๊ทธ ์ธ์๋ ๊ฐ์ธ์ ์ผ๋ก "๋ด"์๋ฃจ์ ์ด ์กฐ๊ธ ๋ ์ฝ๊ธฐ ์ฝ์ต๋๋ค. ๊ทธ๋ฌ๋ ๊ทธ ์์ํ ๋ฏธํ.
@nicklockwood ์ฝ๋๋ฅผ ์๋ํ์ง๋ง ์ฌ์ ํ ํฐ์ ํ๋์๊ฐ ํ์๋ฉ๋๋ค. ๋ก๋ฉ ๋ทฐ๋ก ์ค์ ํ ์์ ์ด๋ฏธ์ง๋ฅผ ๋ง๋ค์์ต๋๋ค. ์์ ์ด๋ฏธ์ง๋ launchScreen.xib์ ๋์ผํฉ๋๋ค.
์ด๊ฒ์ ์ฐ๋ฆฌ ์ฑ์ ์ถ์๋ฅผ ๋ณด๋ฅํ๋ ์ ์ผํ ๊ฒ์ ๋๋ค. ๋์์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
์คํ ์ด๋ฏธ์ง๋ฅผ ์จ๊ธด ํ ํ๋์๊ฐ ๋ํ๋๊ฑฐ๋ ์คํ ์ด๋ฏธ์ง๊ฐ ๋ํ๋์ง ์์ต๋๊น? (์ด๊ฒ์ ๊ทธ๋ฅ ๋ณด๋ ๊ฒ๋ง์ผ๋ก๋ ๊ฒฐ์ ํ๊ธฐ ์ด๋ ค์ธ ์ ์์ต๋๋ค. ์คํ ์ด๋ฏธ์ง๋ฅผ ์ผ์์ ์ผ๋ก ํ์คํ ๋นจ๊ฐ์ ์ง์ฌ๊ฐํ๊ณผ ๊ฐ์ ๊ฒ์ผ๋ก ๋ณ๊ฒฝํ์ญ์์ค).
@nicklockwood xib ํ์ผ๊ณผ launchScreen Image ๊ฐ์ ์์์ ๋ณ๊ฒฝํ๋ ค๊ณ ํ์ต๋๋ค. ๋๋ ์ฌ์ ํ ๊ทธ ํ๋์๋ฅผ ๋ณด๊ณ ์์๋ค.
๋ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
UIImageView *launchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"launchScreen1"]];
rootView.loadingView = launchView;
rootView.loadingViewFadeDelay = 0.0;
rootView.loadingViewFadeDuration = 0.15;
์ด์ ๋ง์ง๋ง ๋ ์ค loadingViewFadeDelay์ duration์ ์ ๊ฑฐํ๋๋ฐ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ ๊ฒ ๊ฐ์ต๋๋ค. ํ๋์๊ฐ ๋ณด์ด์ง ์์ต๋๋ค. ๋ถ๋๋ฌ์ด ์ ํ์ด ์ข์ต๋๋ค.
@chirag04 ๋ฐฉ๊ธ ์ํ ํ๋ก์ ํธ๋ก ์๋ํ๋๋ฐ ํ๋์๊ฐ ๋ณด์ด์ง ์์์ต๋๋ค :(
์ฌ๊ธฐ ๋ด๊ฐ ํ ์ผ์ด ์์ต๋๋ค
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"whiteFlash"
launchOptions:launchOptions];
//here's what I did
UIImage *image = [UIImage imageNamed:@"LaunchImage"];
if (image) {
UIImageView *launchView = [[UIImageView alloc] initWithImage: image];
launchView.contentMode = UIViewContentModeBottom;
launchView.image = image;
rootView.loadingView = launchView;
}
///////////////////////////
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
ํ์ธ. ๋ ๊น์ด ํ๊ณ ๋ค๋ฉด ํ๋์๊ฐ asyncstore์์ ๊ฐ์ ๋ก๋ํ ๋๊น์ง ๋ด ์ฑ์ด ์๋ฌด ๊ฒ๋ ๋ ๋๋งํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
render() {
if(!this.state.loaded) return (null);
return <View ...../>;
}
loadingView๋ js๊ฐ ๋ ๋๋ง์ ์๋ฃํ๋ค๊ณ ์๊ฐํ๊ณ loadingView๋ฅผ ์จ๊น๋๋ค. ๊ทธ๋ฌ๋ js๋ return null
๋ ๋๋ง์ ๋ง์ณค์ต๋๋ค.
@nicklockwood @alinz ๊ทธ๋ฅ ๊ณต์ค์์ ์ดฌ์ ์ค์ ๋๋ค. ์ค์ ์ด์ ๊ฐ ์๋ ์ ์์ต๋๋ค. ์ด๋ป๊ฒ ์๊ฐํ์ธ์?
๋ํ ๋ด๊ฐ ์์์ฐจ๋ฆฐ ํ ๊ฐ์ง๋ loadingViewFadeDelay ๋ฑ์ ๊ฐ์ 0.30 ์ด์์ผ๋ก ์ค์ ํ๋ฉด ์ ํ์ด ๋งค์ฐ ๋งค๋๋ฝ๋ค๋ ๊ฒ์ ๋๋ค. ๊ธฐ๋ณธ๊ฐ์ 0.25๋ก ๋ถ๋๋ฝ์ต๋๋ค.
loadingFadeDelay์ ๋ชฉ์ ์ ์ ํํ ์ฑ์ด ์๋ฌด ๊ฒ๋ ์ฆ์ ๋ ๋๋งํ์ง ์๋ ์๋๋ฆฌ์ค๋ฅผ ์ฒ๋ฆฌํ๋ ๊ฒ์ด๋ฏ๋ก ์ฌ๋ฐ๋ฅด๊ฒ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
๊ธฐ๋ณธ๊ฐ์ด ๋ณ๊ฒฝ๋๋ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ์ฌ loadingViewFadeDelay๋ฅผ ๋ช ์์ ์ผ๋ก ์ค์ ํ๋ ๊ฒ์ ๊ณ ๋ คํ ์ ์์ผ๋ฉฐ ๋ก๋ํ๋ ๋ฐ ์๊ฐ์ด ๋ ์ค๋ ๊ฑธ๋ฆฌ๋ ๊ฒฝ์ฐ ์ง์ํ๋ ๊ฐ์ฅ ๋๋ฆฐ ์ฅ์น์์ ํ ์คํธํด์ผ ํฉ๋๋ค.
@nicklockwood ์๋ฃจ์ ์ ์ข์ํ์ง๋ง ์์ธกํ ์ ์๋ ๋คํธ์ํฌ ๋๊ธฐ ์๊ฐ์ ๊ณ ๋ คํด์ผ ํฉ๋๋ค.
๋ค๋ฅธ ์๋ฃจ์ ์ ๊ตฌ์ฑ ์์ ์ํ๋ฅผ ์ผ์ข ์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์ ํ์ฌ ๊ตฌ์ฑ ์์์ ์ผ์ข ์ ๋ก๋ ๋ํ ์์๋ฅผ ํ์ํ๋๋ก ์ง์ํ๋ ๊ฒ์ ๋๋ค.
์์ํ. ๋๋ ํด๊ฒฐ์ฑ ์ด ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
์ธ ๊ฐ์ง ๊ตฌ์ฑ ์์๊ฐ ๋ชจ๋ ๋์ผํ ๊ฒ์ ๋ํด ์ด๋ป๊ฒ ์๊ฐํ์ญ๋๊น?
1) launchScreen.xib
2) loadingView
3) return null in render to actually render a view which is like loadingView and launchScreen.xib?
๊ทธ๋ฌ๋ ํฌ์ธํธ 3์ด ๋ค๋ฅธ ์ฅ์น์์ ์ด๋ป๊ฒ ํ์ฅ๋๋์ง ํ์คํ์ง ์์ต๋๋ค. ์ฌ๋ฌ๋ถ๋ ๊ทธ๋ ๊ฒ ์ ์ํ์๊ฒ ์ต๋๊น?
์์ ์๊ฐ์ด ๋คํธ์ํฌ ๋ค์ ํ ์คํธ์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋ ๊ฒฝ์ฐ ํ์ด๋ ์ง์ฐ๋ณด๋ค ๋น ๋ฅด๊ฒ ๋ค์ด๋ก๋๋๊ธฐ๋ฅผ ๋ฐ๋ผ๋ ๋์ "๋น" ๋ณด๊ธฐ๋ฅผ ์ฆ์ ๊ทธ๋ฆฌ๋ ๊ฒ์ ์นํธํฉ๋๋ค.
๋น๋๊ธฐ์ ๋ฐ๋ผ ๋ค๋ฆ ๋๋ค. ๋คํธ์ํฌ ์์
๋คํธ์ํฌ์ ์์กดํ๋ ๊ทธ๋ ์ง ์๋ ์ ๋ ํ์๋ฒ ์ด์ค ๋์คํ๋ ์ด๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๋ณ๋ก ์ข์ํ์ง ์์ต๋๋ค. ์ค์ ํ ์๊ฐ์ด ์ ํํ๋ค๊ณ 100% ๋ณด์ฅํ ์ ์๋ ๋ฐฉ๋ฒ์ ์์ต๋๋ค. ๋ฌด์ธ๊ฐ๊ฐ ์ผ์ด๋๊ณ ์์ง๋ง ํ์ํ ์ค๋น๊ฐ ๋์ง ์์์์ ๋ํ๋ด๊ธฐ ์ํด ํญ์ ์ฌ์ฉ์์๊ฒ ๋ฌด์ธ๊ฐ๋ฅผ ํ์ํด์ผ ํฉ๋๋ค. ์ด๊ฒ์ ๋จ์ง ์ ์์ผ ๋ฟ์ ๋๋ค.
๋์. ํ์ค iOS ๋ก๋ฉ ์ด๋ฏธ์ง์ ๋ง์ฐฌ๊ฐ์ง๋ก loadingView์ ๋ชฉ์ ์ ์ฑ์ด ํ์ํ ์ค๋น๊ฐ ๋ ๋ชจ๋ ๊ฒ์ด ๋ก๋ฉ ์คํผ๋์ธ ๊ฒฝ์ฐ์๋ ์ฑ์ด ๋ฌด์ธ๊ฐ๋ฅผ ํ์ํ ์ค๋น๊ฐ ๋ ๋๊น์ง ๋ฎ๋ ๊ฒ์ ๋๋ค.
์ฆ, ์ด๋ฏธ์ง ๋์ ๋ทฐ๋ก ๋ง๋ ์ด์ ๋ ์ ์ ์ด ์๋ ์ํ๋ก ๋ง๋ค ์ ์๊ธฐ ๋๋ฌธ์ ๋๋ค. ์ํ๋ ๊ฒฝ์ฐ loadingView์ UIActivityIndicatorView๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค.
๋ฐ์ฌ ์ด๋ฏธ์ง๋ ์ด๋ป๊ฒ ๋ฐฐ์นํ ์ ์์ต๋๊น? ํ๋ ์ ์์ ์ ์กฐ์ ํด ๋ณด์์ง๋ง ์ด๋ค ์์ ์ ์ฌ์ฉํ๋ ํญ์ ์ค์์ ์์นํฉ๋๋ค. ์๋จ์ ๋ฐฐ์นํ๊ณ ์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ๋ป์ด์๋ ์์ ์๋จ ๋ง๋ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค.
์ด๊ฒ์ด ๋ด๊ฐ ๊ฐ์ง ๊ฒ์ ๋๋ค.
UIImageView *launchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LaunchImage"]];
CGRect frame = launchView.frame;
frame.origin.x = 0;
frame.origin.y = 0;
launchView.frame = frame;
rootView.loadingView = launchView;
rootView.loadingViewFadeDelay = 0.0;
rootView.loadingViewFadeDuration = 0.0;
์์ ์ด๋ฏธ์ง๊ฐ ์๋๋ผ ์์ _view_์ด๋ฏ๋ก ๋ค๋ฅธ ์ปจํ ์ด๋ ๋ณด๊ธฐ ๋ด๋ถ์ imageView๋ฅผ ๋ฐฐ์นํ๊ณ ์ปจํ ์ด๋๋ฅผ ์์ ๋ณด๊ธฐ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค.
UIView *launchView = [[UIView alloc] init];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LaunchImage"]];
imageView.frame = CGRectMake(whatever);
[launchView addSubview:imageView];
...
์ฌ์ค, ๋ํผ๋ก ํ๋ฉด ๊ณต๊ฐ์ ์ฑ์ฐ๊ณ ์ด๋ฏธ์ง๋ฅผ ๋งจ ์์ ๋ฐฐ์นํ ์ ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค. ๋ํผ๋ RootView์ ์ํด ์๋์ผ๋ก ์ค์์ ๋ฐฐ์น๋ฉ๋๋ค .
@Intellicode ๋ค.
@dvine-multimedia์ ์ฝ๋๋ฅผ ์ฌ์ฉํ์ฌ iphone 4s์์ ํ๋ก๋์ ํ๊ฒฝ์์ ์ฑ์ ์ค๋จํ์ต๋๋ค. ์์ ์ if์ ํด์์ ๋ฃ๋ ๊ฒ์ ๋๋ค.
containsString
ios 7์์ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์ ํ ๋ฒ ๋ ์ถฉ๋ํฉ๋๋ค.
@nicklockwood ๋ก๋ ๋ทฐ๊ฐ ๊ฐ๋ฅํ ์ต์์ ํด์๋๋ฅผ ์๋์ผ๋ก ์ ํํ๋์ง ๊ถ๊ธํ์ญ๋๊น?
loadingView๋ ์ด๋ฏธ์ง๋ฅผ ์ ํ ์ ํํ์ง ์๊ณ ์ ๋ฌํ ๋ด์ฉ๋ง ์ฌ์ฉํฉ๋๋ค. ์์ inage๋ฅผ ์ฐพ๊ธฐ ์ํด ์์ ๊ฒ์ํ ์ค๋ํซ์ ์ฅ์น์ ๋ํ ์ฌ๋ฐ๋ฅธ ํด์๋๋ฅผ ์ ํํฉ๋๋ค.
๊ทํ์ ์ค๋ํซ์ ์ฌ๋ฐ๋ฅธ ์น์๋ฅผ ๊ฐ์ง ๊ฒ์ ์ ํํ์ง ์์ต๋๋ค. ๊ทธ๊ฒ์ ๋ํ ์ด๋ค ์์ ?
๋ด ์๋ฃจ์ ์ด๋ dvine์ ์๋ฃจ์ ์ ์ฌ์ฉํ๊ณ ์์์ต๋๊น? ์ด๋ค iPhone ๋ชจ๋ธ์ ์ฌ์ฉํ๊ณ ์์ต๋๊น? ์ด์ํ ๋๋ ํ๊ฒฝ?
dvine์ ์ฌ์ฉํ ๋ ์ฌ๋ฐ๋ฅธ ์ฐจ์์ ์ ํํฉ๋๋ค. ur ์๋ฃจ์ ์ ์ฌ์ฉํ๋ฉด ์ด๋ฏธ์ง ์ฃผ์์ ๊ฒ์ ๊ณต๊ฐ์ด ์๊น๋๋ค. ๋๋ ๊ฒ์ ๊ณต๊ฐ์ด ์๋ชป๋ ์น์๋ก ์ด๋ฏธ์ง๋ฅผ ์ ํํ๊ธฐ ๋๋ฌธ์ ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค.
์ ๋ ์์ดํฐ 6์ ๋๋ค. ์ด์ํ์ ๋๋ค.
์ด๊ฒ์ด ์ด๋ป๊ฒ ์๊ฒผ๋์ง์ ๋๋ค. ํฐ์ ๋ฐฐ๊ฒฝ์ ์ฃผ๋ชฉํ์ธ์.
๋ค์ ์ฝ๋ ์ฌ์ฉ:
UIImageView *launchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LaunchImage"]];
rootView.loadingView = launchView;
rootView.loadingViewFadeDelay = 0.20;
rootView.loadingViewFadeDuration = 0.20;
๊ทธ๊ฒ์ ๋ด๊ฐ ๊ฒ์ ํ ์๋ฃจ์ ์ด ์๋ ์์ต๋๋ค. ์ด๊ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
// Get launch image
NSString *launchImageName = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGFloat height = MAX(RCTScreenSize().width, RCTScreenSize().height);
if (height == 480) launchImageName = @"[email protected]"; // iPhone 4/4s
else if (height == 568) launchImageName = @"[email protected]"; // iPhone 5/5s
else if (height == 667) launchImageName = @"[email protected]"; // iPhone 6
else if (height == 736) launchImageName = @"[email protected]"; // iPhone 6+
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CGFloat scale = RCTScreenScale();
if (scale == 1) launchImageName = @"LaunchImage-700-Portrait~ipad.png"; // iPad
else if (scale == 2) launchImageName = @"LaunchImage-700-Portrait@2x~ipad.png"; // Retina iPad
}
// Create loading view
UIImage *image = [UIImage imageNamed:launchImageName];
if (image) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:(CGRect){CGPointZero, RCTScreenSize()}];
imageView.contentMode = UIViewContentModeBottom;
imageView.image = image;
rootView.loadingView = imageView;
}
์ ์ฅ! ๊ทํ์ ์๊ฒฌ์ ์ฃผ์ ๊น๊ฒ ์ฝ์์ผ๋ฉด ํฉ๋๋ค. ๊ทํ์ ์๋ฃจ์ ์ ํจ๊ณผ๊ฐ ์์ผ๋ฉฐ ์ดํดํ๊ธฐ ์ฝ์ต๋๋ค.
I've been experimenting with a way to automatically detect the launch image and make this completely automatic, but it's not really ready yet. If you're interested, it looks like this:
์๋ง๋ experimenting
์ผ ๊ฒ์
๋๋ค. ๋ด๊ฐ ์ด๋ป๊ฒ ๋์ณค๋์ง ํ์คํ์ง ์์ต๋๋ค. ๋ฏธ์ ๋ด ์ค์.
๋์์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ๋ค์ ๋ฒ์ ์์ ์ด ์ฝ๋๋ฅผ ์ฌ์ฉํ ๊ฒ์ ๋๋ค. ๋ชจ๋ ๊ฒฝ์ฐ๋ฅผ ์ปค๋ฒํ๋ ๊ฒ ๊ฐ์ต๋๋ค. ํ๊ฒฝ์ด ํ์ํ์ง ์์ต๋๋ค.
ํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํ ๋๋ ์๋ง๋ "์ด๊ฒ์ด ์ฐ๋ฆฌ๊ฐ ์ง๊ธ ํ๋ก๋์ ์์ ์ฌ์ฉํ๊ณ ์๋ ๊ฒ์ด๊ณ , ์ ์์ ์ผ๋ก ์๋ํ๋ ๊ฒ ๊ฐ์ต๋๋ค"๋ผ๊ณ ๋งํ์ด์ผ ํ์ต๋๋ค :-)
"์ด๊ฒ์ ์ฐ๋ฆฌ๊ฐ ์ง๊ธ ํ๋ก๋์ ์์ ์ฌ์ฉํ๊ณ ์๋ ๊ฒ์ ๋๋ค"๋ ์ฑ ์คํ ์ด์์ ๋ณ 1๊ฐ๋ก๋ถํฐ ์ฐ๋ฆฌ๋ฅผ ๊ตฌํด ์ฃผ์์ ๊ฒ์ ๋๋ค. ใ . ๊ฑฑ์ ๋ง. ์ธ์์ ๊ตฌํ ์๋ก์ด ๋ฒ์ ์ด ํญ์ ์์ต๋๋ค. :)
์ด ๋ฌธ์ ๋ฅผ ์ข ๋ฃํ์๊ฒ ์ต๋๊น?
์ธ๋ถ ์ฌํญ์ ๋ํด ์ถฉ๋ถํ ๋ ผ์๋์๊ธฐ ๋๋ฌธ์ ์ด ํฐ์ผ์ ๋ซ๊ณ ๋ช ๊ฐ์ง ์ข์ ์๋ฃจ์ ์ ๊ฐ์ง๊ณ ์์ต๋๋ค.
LaunchScreen xib๋ฅผ ์ฌ์ฉํ๋ ์ฌ๋๋ค์ ์ํด ์ด๊ฒ์ 100% ๋ช ํํ๊ฒ ํ๊ธฐ ์ํด ๋ค์์ ํด๋น ์์ ์ ์ํํ๋ ์ฝ๋์ ๋๋ค.
UIView* launchScreenView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0];
launchScreenView.frame = self.window.bounds;
rootView.loadingView = launchScreenView;
return YES
๋ผ๊ณ ํ์๋ ์ค ๋ฐ๋ก ์์ ์๋ AppDelegate.m
ํ์ผ์ application didFinishLaunchingWithOptions
๋ฉ์๋์ ํด๋น ์ค์ ์ถ๊ฐํฉ๋๋ค.
@arnemart ๋ ์ด ๋ฐฉ๋ฒ์ด ios 8+์์๋ง ์๋ํ๋ค๋ ๊ฒ์ ๋ ๋ช ํํ๊ฒ ํ๊ณ ์์ต๋๋ค. ๋ง์ต๋๊น?
@arnemart ๊ฐ์ฌํฉ๋๋ค! ์๋ฒฝํ๊ฒ ์๋ํฉ๋๋ค .
LaunchImage
๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ด๋ฏธ์ง ํฌ๊ธฐ๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์กฐ์ ๋๋๋ก frame
๋ฐ contentMode
๋ฅผ ๋ชจ๋ ์ค์ ํด์ผ ํฉ๋๋ค.
UIImageView *launchScreenView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LaunchImage"]];
launchScreenView.frame = self.window.bounds;
launchScreenView.contentMode = UIViewContentModeScaleAspectFill;
rootView.loadingView = launchScreenView;
@arnemart ์ ์ฃผ์๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก AppDelegate.m
ํ์ผ์ return YES
์ค ์์ ์๋ application didFinishLaunchingWithOptions
๋ฉ์๋์ ๋ค์ ์ค์ ์ถ๊ฐํฉ๋๋ค.
๊ธฐ์ด ํ. RN v.0.11.4์์ ์ฑ์ ๋จผ์ ๊ฒ์์ ํ๋ฉด๊ณผ ํจ๊ป ์์๋ ๋ค์ ์ฑ์ ๋ก๋ํ๊ธฐ ์ ์ LaunchScreen.xib๋ฅผ ์์ํฉ๋๋ค. iOS 9 w/ @arnemart ์์ https://github.com/facebook/react-native/issues/1402#issuecomment -130236507. ์ด๋ค ์์ด๋์ด?
@irfaan์ window.backgroundColor๋ฅผ [UIColor redColor]์ ๊ฐ์ ๊ฒ์ผ๋ก ๋ณ๊ฒฝํ๋ ค๊ณ ์๋ํฉ๋๋ค. ๊ทธ๋ฌ๋ฉด ๊ฒ์ ์์ด ์ฐฝ์์
self.window.backgroundColor = [UIColor redColor];
๋ด๋ถ์ didFinishLaunchingWithOptions
๋) ์๋ฌด ๊ฒ๋ ๋ณ๊ฒฝ๋์ง ์์์ต๋๋ค. LaunchScreen.xib ์ ์๋ ์ฌ์ ํ ๊ฒ์์์
๋๋ค. ๊ทธ๋์ ์ฐฝ๋ฌธ์์๊ฐ ์๋๋ผ @nicklockwood ์ฒ๋ผ
๋๋ฒ๊น ์ ๋ํด ์ด๋ป๊ฒ ์ถ์ฒํฉ๋๊น?
iOS๋ ์ฑ์ด ๋ก๋๋ ๋๊น์ง launchScreen.xib๋ฅผ ์ ํ ๋ก๋ํ์ง ์๋ ๊ฒ์ฒ๋ผ ๋ค๋ฆฝ๋๋ค(์ด ์์ ์์ React๋ ์ด๋ฅผ loadingView๋ก ํ์ํฉ๋๋ค).
์๋ง๋ Xcode์ ๊ตฌ์ฑ ์ค๋ฅ์ ๋๊น? ์๋๋ฉด iOS 9์ ๋ฒ๊ทธ์ผ๊น์?
์ฅ์น์์ ์๋ํ์ต๋๊น, ์๋๋ฉด ์๋ฎฌ๋ ์ดํฐ์์๋ง ์๋ํ์ต๋๊น?
@nicklockwood ๊ฐ์ฌ
์๋
ํ์ธ์ @genexliu๋ , ์ด๋ฏธ์ง์ "LaunchImage" ์ธํธ๋ฅผ Images.xcassets/LaunchImage.launchimage/
ํ์ง๋ง ๋ถ์ฌ๋ฃ์ ์ฝ๋์ LaunchScreen.storyboard ๋ชจ๋ ํด๋น ์ด๋ฏธ์ง๋ฅผ ์ฐพ๊ฑฐ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค(๋ ๋ค ์๋์ผ๋ก ์คํจํจ). ๋ด LaunchScreen ์คํ ๋ฆฌ๋ณด๋๋ ๋ฐฐ๊ฒฝ์์ ๋ณผ ๋ ์ฌ๋ฐ๋ฅด๊ฒ ๋ก๋๋์ง๋ง ์ฐธ์กฐ๋ ์ด๋ฏธ์ง๋ ํ์ํ์ง ์์ต๋๋ค. ์ด๋ค ์์ด๋์ด?
๋ํ XCode์์ ์คํํ ๋์ ์์ ์์๋ ์ ์์ ์ผ๋ก ๋ณด์ด์ง๋ง cmd ํ์์ natal launch
๋ฅผ ์คํํ ๋ ์์ ์์/์ถ๊ฐ ํฐ์ ํ๋์ ๋ฑ์ ์ถ๊ฐ ์คํ์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
LaunchImage๋ฅผ ์ฐพ์ง ๋ชปํ๋ Storyboard์ ๋ฌธ์ ๋ ๋ถ๋ช
ํ XCode์ ๋ฒ๊ทธ์์ต๋๋ค. ์์ ์ค์ ์ '์์ฐ ์นดํ๋ก๊ทธ ์ฌ์ฉ'์ผ๋ก ๋ณ๊ฒฝํ ๋ค์ ๋ค์ '์คํ ๋ฆฌ๋ณด๋ ์ฌ์ฉ'์ผ๋ก ๋ณ๊ฒฝํ๊ณ ์๋์ ์์ํ์ต๋๋ค. @genexliu ์ ์ฝ๋๊ฐ ์ ์๊ฒ ํจ๊ณผ๊ฐ ์๋์ง loadingViewFadeDelay
ํจ๊ณผ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
UIImageView *launchScreenView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Images/LaunchImage"]];
launchScreenView.frame = self.window.bounds;
launchScreenView.contentMode = UIViewContentModeScaleAspectFill;
rootView.loadingView = launchScreenView;
rootView.loadingViewFadeDelay = 5000;
๊ทธ๋ฌ๋ ์คํ ๋ฆฌ๋ณด๋ LaunchImage ๋์คํ๋ ์ด์ ์ด๊ธฐ React render
์ฌ์ด์๋ ์ง์ฐ์ด ์์ต๋๋ค.
@"Images/LaunchImage"๊ฐ ๋์๊ฒ ๋ง์ง ์์ต๋๋ค. ์๋ง๋ @"LaunchImage"์ผ ๊ฒ์ ๋๋ค.
์ค, ์. ๋ค๊ฐ ์ณ์. ๊ทธ๊ฒ์ ๋ด๊ฐ ์๋ํ ์์ด ์ค ํ๋์ ๋๋ค(์ฒซ ๋ฒ์งธ๋ ์๋).
๋ํ 3๊ฐ์ ์ ์์ ๋ด ๋๊ธ์์ ์์ ์ฝ๋๋ฅผ ํ์ธํ์ญ์์ค. ๋ค๋ฅธ ์ฅ์น ํด๋์ค์ ๋ํ ๋ง์ ์์ ์ด๋ฏธ์ง ํ์ผ์ด ์์ต๋๋ค.
๋! ๋น์ ์ด ์ณ์. LaunchImage
๋ค์ ์ ํํ๋ฉด ์ด์ ์๋ํฉ๋๋ค. ๊ณ ๋ง์!
๋๊ตฌ๋ ์ง Android์ ๋ํ ์ด๊ฒ์ ๋ํ ๋ฌธ์๋ฅผ ์๋ ค์ค ์ ์์ต๋๊น?
์๋๋ก์ด๋์ฉ +1
cc @dmmiller Android์ loadingView ๊ธฐ๋ฅ์ด ์์ต๋๊น?
์๋ ํ์ธ์, ์ ๋ ์ด์ ๋์ผํ ๋ฌธ์ ๋ฅผ ๊ฒช๊ณ ์๋๋ฐ ์ฌ๊ธฐ์ ๋ช ๊ฐ์ง ๊ฒ์๋ ์๋ฃจ์ ์ด ์๋ ๊ฒ์ ๋ณด์์ง๋ง ์ด ์ฝ๋๋ฅผ ์ด๋์ ๋ฃ์ด์ผ ํ ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๋ด๊ฐ ์ดํดํ ๋ฐ์ ๋ฐ๋ฅด๋ฉด ํด๊ฒฐ์ฑ ์ React Native ์์ฒด ๋ด์์ ์ํํ ์ ์๋ ๊ฒ์ด ์๋๋ผ Objective-C ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ๋ ๊ฒ์ ๋๋ค. ๋ง์ต๋๊น? ์ด ๊ฒฝ์ฐ ๊ฒ์๋ ์ฝ๋๋ ์ด๋๋ก ๊ฐ๋์? xcode ํ๋ก์ ํธ ๋ฃจํธ์ main.m ํ์ผ์์? ๊ฐ์ฌ ํด์.
@CorpusCallosum ์ฝ๋๋ RCTRootView๊ฐ ์ค์ ๋ AppDelegate.m ํ์ผ์ ์์ด์ผ ํฉ๋๋ค.
@nicklockwood ๊ฐ์ฌํฉ๋๋ค. ์๋ํด ๋ณด๊ฒ ์ต๋๋ค.
์ด ์ฝ๋๋ ํฐ์ ํ๋์๊ฐ ๋ณด์ด์ง ์๋ ํ ์ง๊ธ์ ์๋ํ๊ณ ์์ผ๋ฉฐ ๋ด ์ด๋ฏธ์ง๊ฐ ์ด๊ธฐ ํ๋ฉด์ ๋ก๋๋์ง๋ง ์ด์ ์ค์ ์ฑ์ด ๋ก๋๋์ง ์์ต๋๋ค! ์ฝ์์์ ๋ณผ ์ ์์ง๋ง ์ฑ์ด ๋ก๋๋์ด ์คํ ์ค์ด๋ฉฐ ์ํธ ์์ฉ(ํญ ๋ฐ ์ค์์ดํ)๋ ์๋ํ์ง๋ง ์ค์ ๋ก๋ ์ฑ์ด ์ ํ ๋ณด์ด์ง ์๊ณ ๋ฉ์ถฅ๋๋ค. ๊ทธ ์ด๊ธฐ ํ๋ฉด์์ ์ด์ ๋ฅผ ์๊ฒ ์ด์?
๋ค์์ ๋ด AppDelegate.m ํ์ผ์ ์ฝ๋์ ๋๋ค.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
//use launch image as BG image for app
UIImageView *launchScreenView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LaunchImage-blank-grey"]];
launchScreenView.frame = self.window.bounds;
launchScreenView.contentMode = UIViewContentModeScaleAspectFill;
rootView.loadingView = launchScreenView;
rootView.loadingViewFadeDelay = 1000;
return YES;
@CorpusCallosum ์ค์ ์ ๊ฑฐํด ๋ณผ ์ ์์ต๋๋ค.
rootView.loadingViewFadeDelay = 1000;
๋๋ ์คํ๋์ ํ๋ฉด๊ณผ ์ฑ ์ฌ์ด์ ์ ํ์ ๊ฐ์ผ๋ก ๋ฏธ์ธ ์กฐ์ ํ์ญ์์ค(๋จ์๋ ๋ฐ๋ฆฌ์ด๊ฐ ์๋๋ผ ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. ์ด๊ฒ์ด ์คํ๋์์ "๊ณ ์ฐฉ"๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋ ์ด์ ์
๋๋ค).
์ค์ ์์ ํ ์ ๊ฑฐํ๋ ๊ฒ์ด ํจ๊ณผ๊ฐ ์์ผ๋ฉด 0-5 ์ฌ์ด์ ๊ฐ์ ์ค์ ํด ๋ณด์ญ์์ค(์ ์๊ฐ ์๋ ๊ฐ๋ ์ค์ ํ ์ ์์).
์ ๋ฅผ ์ํด ์ผํ๊ณ ์์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค. :)
launchscreen xib๋ฅผ loadingView๋ก ์ฌ์ฉํ๋ ค๋ ์ฌ๋๋ค์ ์ํด ๋ค์์ AppDelegate.m์ ์ฝ์ ํ ์ฝ๋์ ๋๋ค.
UIView *loading = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0];
rootView.loadingView = loading;
rootView.loadingViewFadeDelay = 1;
๋ง์ง๋ง ์ค์ ์ ํ ์ฌํญ์ ๋๋ค. ์์์ ์ธ๊ธํ๋ฏ์ด ์ฑ ์์ฒด๋ก ์ด๋ํ๊ธฐ ์ ์ loadingView๊ฐ ์ ์ง๋๋ ์๊ฐ์ ์ค์ ํฉ๋๋ค.
@david-์ ๋ง ๊ฐ์ฌํฉ๋๋ค! ๋๋ ๋ค์ดํฐ๋ธ ๋ฐ์ ํ ์คํธ๋ฅผ ์์ํ ์ดํ๋ก ์ด๊ฒ์ ๋ค๋ฃจ๊ณ ์์ต๋๋ค. ๐
@david-a, @geriux : ๋ด LaunchScreen.xib์ AspectFill ์ฝํ
์ธ ๋ชจ๋๊ฐ ์๋ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๊ฐ ์๊ณ ํฌ๊ธฐ๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์กฐ์ ๋์ง ์์๊ธฐ ๋๋ฌธ์ launchScreenView.frame = CGRectZero;
๋ ์ค์ ํด์ผ ํ์ต๋๋ค. ๋ช ๋ฒ์ ์ํ ์ฐฉ์ค ๋์ ํด๊ฒฐ์ฑ
์ ์ฐพ์์ง๋ง ์์ธ์ด ๋ฌด์์ธ์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
@BasitAli ์, ์ฃ์กํฉ๋๋ค. ๋ ์ ๋ฌธ์ํํด์ผ ํฉ๋๋ค. ๋ณด๊ธฐ์ ํฌ๊ธฐ๋ฅผ 0์ด ์๋ ๊ฐ์ผ๋ก ์ค์ ํ๋ฉด ํ๋ฉด ์ค์์ ํ์๋ฉ๋๋ค. 0์ผ๋ก ์ค์ ํ๋ฉด ํ๋ฉด์ ๋ง๊ฒ ํฌ๊ธฐ๊ฐ ์กฐ์ ๋ฉ๋๋ค.
@david-์ ๋ง ๊ฐ์ฌํฉ๋๋ค! ๊ทํ์ ์๊ฒฌ์ ์์ฉ๊ตฌ์ ํฌํจ๋๊ฑฐ๋ ์ต์ํ ๊ธฐ๋ณธ ๋ฐ์ ๊ธฐ๋ณธ ๋ฌธ์์ ์ผ๋ถ์ฌ์ผ ํฉ๋๋ค. ์ด ๋ฌธ์ ๊ฐ 2015๋ 3์์ ์ข ๋ฃ๋ ์ด์ ๊ฐ ํ์คํ์ง ์์ง๋ง 2016๋ 2์์ RN 0.20์ ์ฌ์ ํ ์กด์ฌํฉ๋๋ค.
๋๊ตฐ๊ฐ๊ฐ ๋ฌธ์์ ๋ํ PR์ ํ ์ ์๋ค๋ฉด ์ข์ ๊ฒ์ ๋๋ค.
์ฌ๋ฌ๋ถ์ ์กฐ์ธ์ ์ ์๊ฒ ๋ง์ ๋์์ด ๋ฉ๋๋ค(IOS์์๋ ์๋ฒฝํ๊ฒ ์๋ํจ). Android์์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ๋ฐฉ๋ฒ์ ์ฐพ๋ ์ฌ๋์ด ์์ต๋๊น?
๋์์ด ๋ ๊น์?
@weiyisheng , iOS์์ ์์์ ์ค๋ช ํ ์์ ์ฌํญ๊ณผ ํจ๊ป Android์์ @braco๊ฐ ์ ์ํ ๋๋ก react-native-splashscreen์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
@braco @BasitAli ์, ๋์์ด ๋์์ต๋๋ค. ์ ์ฑ์์ ์ฌ์ฉํ ๊ฒ์ ๋๋ค. ์ข์ ์๊ฐ์ ๋๋ค. ๊ณ ๋ง์์.
@BasitAli ํธ๊ธฐ์ฌ์ iOS์์ ์ฌ์ฉํ์ง
๋ด ์์ฉ ํ๋ก๊ทธ๋จ์ ์์ ํ๋ฉด์์ ๋ก๊ทธ์ธ ํ๋ฉด์ผ๋ก ๋งค๋๋ฝ๊ฒ ์ ๋๋ฉ์ด์ ๋ฉ๋๋ค(๋ก๊ณ ๊ฐ ์๋ก ์ด๋ํ๊ณ ๋ก๊ทธ์ธ ํ๋๊ฐ ํ์ด๋์ด). rn-splashscreen ํ๋ฌ๊ทธ์ธ์ด ํ์ด๋ ์์๋์ด ๋ด ์ ๋๋ฉ์ด์ ๊ณผ ์ ์ด์ธ๋ฆฌ์ง ์์ต๋๋ค. ๋ค๋ฅธ ์ ํ์ ์ฌ์ง๊ฐ ์์๊ธฐ ๋๋ฌธ์ Android์์ ์ฌ์ฉํด์ผํ์ต๋๋ค.
@BasitAli react-native-splashscreen ํ๋ฌ๊ทธ์ธ์ rootView.loadingViewFadeDuration
์ค์ ์ ๋ฐ๋ฅด๋ ๊ฒ์ฒ๋ผ ๋ณด์
๋๋ค. ๋จ, ์ฐ๊ฒฐ ํ ์ค์ ํ๋ค๋ฉด ํ์ด๋๋ฅผ ๋นํ์ฑํํด์ผ ํฉ๋๋ค.
[RCTSplashScreen show:rootView];
rootView.loadingViewFadeDuration = 0;
"๋ฏธ๋ฆฌ ๋ฒ๋ค๋ ํ์ผ์์ ๋ก๋ ์ค"์ด๋ผ๋ ์๋จ์ ์์ ๋ฉ์์ง๋ฅผ ์ ๊ฑฐํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
@rclai ๋ ๋ฆด๋ฆฌ์คํ ๊ณํ์ ์ค์ ํ์ต๋๋ค.
์! ๊ฐ์ฌ ํด์!
๋ ํ๋ซํผ ์คํ๋์ ํ๋ฉด์ ๋ํ ๋ฐ์ ๋ค์ดํฐ๋ธ ์๋ฃจ์ ์ด ์์ต๋๊น? ๋ ํ๋ซํผ ๋ชจ๋ ๋ด๋ถ ํ์ผ์ ์ ๋ ฅํ๋ฉด ๋ฐ์ ๋ค์ดํฐ๋ธ๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ๋ฉ๋๋ค. ๊ฐ๋จํ ๋ต๋ณ ๋ถํ๋๋ฆฝ๋๋ค. ๊ฐ์ฌ ํด์
@rclai
"๋ฏธ๋ฆฌ ๋ฒ๋ค๋ ํ์ผ์์ ๋ก๋ ์ค"์ด๋ผ๋ ์๋จ์ ์์ ๋ฉ์์ง๋ฅผ ์ ๊ฑฐํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
๋ฆด๋ฆฌ์ค ๋ชจ๋์์๋ ํ์๋์ง ์๊ณ ๋๋ฒ๊ทธ ๋ชจ๋์์๋ง ํ์๋ฉ๋๋ค. ๋๋ฒ๊ทธ ๋ชจ๋์์๋ ์จ๊ธฐ๋ ค๋ฉด AppDelegate์ [RCTDevLoadingView setEnabled:NO];
๋ฅผ ๋ฃ์ด ์จ๊ธธ ์ ์์ต๋๋ค.
@nicklockwood ์๋ ํ์ธ์, ๋ง์ต๋๊น? ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ ๋ฌด์์ ๋ณ๊ฒฝ/์ญ์ ํด์ผ ํฉ๋๊น?
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"SomeApp"
initialProperties:nil
launchOptions:launchOptions];
// Get launch image
NSString *launchImageName = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGFloat height = MAX(RCTScreenSize().width, RCTScreenSize().height);
if (height == 480) launchImageName = @"[email protected]"; // iPhone 4/4s
else if (height == 568) launchImageName = @"[email protected]"; // iPhone 5/5s
else if (height == 667) launchImageName = @"[email protected]"; // iPhone 6
else if (height == 736) launchImageName = @"[email protected]"; // iPhone 6+
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CGFloat scale = RCTScreenScale();
if (scale == 1) launchImageName = @"LaunchImage-700-Portrait~ipad.png"; // iPad
else if (scale == 2) launchImageName = @"LaunchImage-700-Portrait@2x~ipad.png"; // Retina iPad
}
// Create loading view
UIImage *image = [UIImage imageNamed:launchImageName];
if (image) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:(CGRect){CGPointZero, RCTScreenSize()}];
imageView.contentMode = UIViewContentModeBottom;
imageView.image = image;
rootView.loadingView = imageView;
}
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
@TeodorKolev ๊ฐ ๋์๊ฒ ๋ง๋ ๊ฒ ๊ฐ์ต๋๋ค. ์์ํ ๋ ์ฌ์ ํ ํ๋์๊ฐ ํ์๋๋ฉด ์ค์ ์ ์๋ํ์ญ์์ค.
rootView.loadingViewFadeDelay
๋ ํฐ ๊ฐ์ผ๋ก(์ด ๋จ์ - ๊ธฐ๋ณธ๊ฐ์ 0.25)
ํธ์งํ๋ค:
์ด ๋ผ์ธ
UIImageView *imageView = [[UIImageView alloc] initWithFrame:(CGRect){CGPointZero, RCTScreenSize()}];
์๋ง ๊ทธ๋ฅ ์์ด์ผํฉ๋๋ค
UIImageView *imageView = [[UIImageView alloc] init];
๊ฐ์ฌํฉ๋๋ค. ์ด๋ค ํด๋์ ํด๋น ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํด์ผ ํ๋์? ์ด๋ฅผ ์ํด ์ถ๊ฐ Contents.json์ด ํ์ํฉ๋๊น? ๋ค์์ผ๋ก ์์ํ๋ ํด๋น ์ฝ๋์ ์ฌ๋ฌ ์ค๋ฅ๊ฐ ์์ต๋๋ค.
(https://cloud.githubusercontent.com/assets/10398337/13778676/e01e3d32-eabf-11e5-95bf-d7a1205a5ca1.png)
์์:
CGFloat height = MAX(RCTScreenSize().width, RCTScreenSize().height);
@TeodorKolev Xcode์๋ ์ถ๊ฐํ๊ธฐ ์ํ GUI๊ฐ ์์ต๋๋ค. Images.xcassets๋ฅผ ํด๋ฆญํ ๋ค์ + ๋ฒํผ์ ํด๋ฆญํ๊ณ "์ฑ ์์ด์ฝ ๋ฐ ์์ ์ด๋ฏธ์ง" > "์ iOS ์์ ์ด๋ฏธ์ง"๋ฅผ ์ ํํฉ๋๋ค.
@TeodorKolev ์ค๋ฅ๋ฅผ ์์ ํ๋ ค๋ฉด ๋ค์์ ์ถ๊ฐํด์ผ ํฉ๋๋ค.
#import "RCTUtils.h"
AppDelegate์์.
๊ฐ์ฌํฉ๋๋ค. ํ์ง๋ง WebView URL์ด ์์ ํ ๋ก๋๋ ๋๊น์ง ์คํ๋์ ํ๋ฉด์ ๋ณด๊ณ ์ถ์๋ฐ ์ง๊ธ์ ๊ทธ๋ ๊ฒ ์๋ํ์ง ์์ต๋๋ค. ์กด๊ฒฝ!
@nicklockwood ์ด๊ฒ์ ๋ํ ํด๊ฒฐ์ฑ ์ด ์์ต๋๊น?
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ํ์ฌ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น? ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ง 1๋ ๋ช ๊ฐ์์ด ์ง๋ฌ๊ธฐ ๋๋ฌธ์ ์ค์ ๋ก ํด๊ฒฐ๋ ๊ฒ์ธ์ง ์์ฌ์ค๋ฌ์ ํ์ฌ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ๋ฌด์์ธ์ง ๊ถ๊ธํฉ๋๋ค. ์ด๋ค ํ์ผ์ ๋ณ๊ฒฝํด์ผ ํ๊ณ ์ด๋ค ์ฝ๋๋ฅผ ์์ ํด์ผ ํฉ๋๊น?
ํธ์ง: ์ ๋ launchscreen.xib์ ํจ๊ป ๊ฒ์์ ํ๋ฉด์ ์ฌ์ฉํ๊ณ ์์ง๋ง ์ค๊ฐ์ ์ฑ์ด ์์ ํ ๋ก๋๋๊ธฐ ์ ์ ํฐ์์ผ๋ก ๋ฐ๋๋๋ค.
@hasen6 ๋ฌธ์ ๋ ์ด๋ฏธ ํด๊ฒฐ๋์์ง๋ง ๊ฐ๋ฐ์ ์ธก์์ ์ฝ๊ฐ์ ์์ ์ด ํ์ํฉ๋๋ค.
์์ ์ค๋ช
์์ ์ธ๊ธ ํ ๋ฐ์ ๊ฐ์ด, ๋น์ ์ ์ค์ ํด์ผ rootView.loadingView
ํฐ์ ํ๋ฉด์ ์ฅ์์ ํ์ํ๊ณ ์กฐ์ ํ๋ ๋ช ๊ฐ์ง ๋ด์ฉ์ผ๋ก rootView.loadingViewFadeDelay
๋ก๋ ๋ทฐ๊ฐ ์ด์ ์ ์จ๊ฒจ์ง๋์ง ์๋๋กํ๋ ๋ฐฉ๋ฒ ์ฑ ๋ก๋๊ฐ ์๋ฃ๋์์ต๋๋ค.
๊ฒ์์ ํ๋ฉด๋ง ํ์ํ๋ ค๋ ๊ฒฝ์ฐ loadingView๋ฅผ ์ฌ์ฉํ์ง ์๊ณ rootView.backgroundColor
๋ฅผ ๊ฒ์์์ผ๋ก ์ค์ ํ๊ธฐ๋ง ํ๋ฉด ๋์ง๋ง ์คํ์ ํด์ผ ํฉ๋๋ค.
rootView.backgroundColor = [UIColor clearColor];
๋ฅผ rootView.backgroundColor
= [UIColor blackColor]๋ก ๋ณ๊ฒฝํ์ต๋๋ค. but it didn't make any difference. Doing a search in XCode for
rootView.loadingView`๊ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ์ง ์์์ต๋๋ค.
@hasen6 ํฐ์์ด ์ด๋์์ ์ค๋์ง ์์๋ด์ผ ํฉ๋๋ค. JS ์ฑ ๋ด๋ถ์ ํฐ์์ด๊ณ ์ฝํ ์ธ ๊ฐ ๋ก๋๋๊ธฐ ์ ์ ์ ์ ๋์ ํ์๋๋ ๋ณด๊ธฐ๊ฐ ์์ ์ ์์ต๋๋ค.
loadingView
๋ RCTRootView
์ ์์ฑ์
๋๋ค. ์ด ์์ฑ์ ์๋ง๋ AppDelegate ๋ด๋ถ์ ์ ์ธ์คํด์ค๊ฐ ์์ ๊ฒ์
๋๋ค. ์ค์ ์ฝ๋ rootView.loadingView
๋ ์ง์ ์ถ๊ฐํ์ง ์๋ ํ Xcode์ ํ์๋์ง ์์ต๋๋ค. ๋ค์์ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ์์
๋๋ค.
rootView.loadingView = [UIView new];
rootView.loadingView.backgroundColor = [UIColor blackColor];
rootView.loadingViewFadeDelay = 0.5; // measured in seconds
๋ด ์ฑ์ ์ด๋์๋ ํฐ์์ด ์๋๋๋ค. ๋ด ๋ชจ๋ ์ฑ์ ์คํ ํ๋ฉด์ด ํ์๋ ํ ๋ก๋ ์ ๋์ผํ ํฐ์ ํ๋ฉด์ ํ์ํ๋ฏ๋ก ๋ด ์ฑ์ ๋ฌธ์ ๊ฐ ์๋ค๊ณ ํ์ ํฉ๋๋ค.
๊ทธ๋์ ํด๋น ์ฝ๋๋ฅผ appdelegate.m์ ์ถ๊ฐํด์ผ ํฉ๋๊น? ๊ทธ๊ฒ๋ ํจ๊ณผ๊ฐ ์์์ต๋๋ค. ๋๋ ๊ทธ๊ฒ์ ๊ณ ์น๋ ๊ฒ์ด ๊ฑฐ์ ๋ถ๊ฐ๋ฅํ ๊ฒ์ด๋ผ๊ณ ์๊ฐํ๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ๊ฐ๋ฐ์๋ค์ด ์์ง๋ ๊ทธ๊ฒ์ ํด๊ฒฐํ์ง ๋ชปํ ์ฑ 1๋ ์ด ์ง๋์ง ์์์ ๊ฒ์ด๋ค. ์ฑ์ ์ผ๋ง๋ ๋์๊ฒ ๋ง๋๋์ง ๊ณ ๋ คํ๋ฉด ๋ถ๋ช ํ ํด๊ฒฐํด์ผ ํ ๋ชฉ๋ก์ ๋งจ ์์ ์์ ๊ฒ์ ๋๋ค.
FWIW, ์ด๊ฒ์ด ๋ด๊ฐ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ๋๋ค. ์ ๋ LaunchScreen.xib ๋ฐ David-a์ ์๋ฃจ์ ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
UIView *loading = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0];
rootView.loadingView = loading;
rootView.loadingViewFadeDelay = 1;
์ด ์ฝ๋๋ ๋ฐ๋ก ์๋์ ์ฝ์ ๋ฉ๋๋ค.
RCTRootView *rootView = [[RCTRootView alloc] etc etc etc...]
ํด๋น ์ฝ๋๋ฅผ nicklockwood์ ์ํ ์ฝ๋๋ก ๋ฐ๊พธ๋ฉด ํฐ์ ํ๋์๊ฐ ๋ฐํ๋ฉ๋๋ค.
์! ์ข์, ํ๋๋ ์๋ํฉ๋๋ค. ๊ณ ๋ง์ ๊ทธ๋ฆฌํ์ค!
@grittathh @hasen6 ์, ์๊ฒ ์ต๋๋ค. loadingView์ ํฌ๊ธฐ๊ฐ 0์ธ ๊ฒฝ์ฐ ํ๋ฉด์ ๋ง๊ฒ ์๋์ผ๋ก ํฌ๊ธฐ๊ฐ ์กฐ์ ๋๋ค๋ ์ฌ์ค์ ์๋ชป ๊ธฐ์ตํ์ง๋ง ๋ถ๋ช ํ ๊ทธ๋ ์ง๋ ์์์ต๋๋ค.
@hasen6 ์ฌ๊ธฐ์ ์๋ํด์ผ ํ๋ ์ฝ๋์ ์์ ๋ ๋ฒ์ ์ด ์์ต๋๋ค(xib ์๋ฃจ์ ๋ ๊ด์ฐฎ์ง๋ง ๊ฒ์์ ํ๋ฉด๋ง ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ค๋ณต๋จ).
rootView.loadingView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
rootView.loadingView.backgroundColor = [UIColor blackColor];
rootView.loadingViewFadeDelay = 0.5; // measured in seconds
์ฐธ๊ณ : 1์ loadingViewFadeDelay์ ๋ํด ์๋นํ ํฐ ๊ฐ์ ๋๋ค. ์ฑ์ด ์์๋๊ธฐ ์ ์ ์ฌ์ฉ์๊ฐ ์ถ๊ฐ๋ก 1์ด๋ฅผ โโ๊ธฐ๋ค๋ ค์ผ ํจ์ ์๋ฏธํ๊ธฐ ๋๋ฌธ์ ๋๋ค. ๋๋ ๊ทธ๊ฒ์ ๋ฒ์ด๋ ์์๋ ๊ฐ์ฅ ๋ฎ์ ๊ฐ์ผ๋ก ์ค์ ํ๋ ๊ฒ์ด ์ข์ต๋๋ค (0.25๊ฐ ๊ธฐ๋ณธ๊ฐ์ด๋ฉฐ ๋๋ถ๋ถ์ ์ฑ์ ์ ํฉํฉ๋๋ค).
์, 1์ด ์กฐ๊ธ ๊ธธ์๊ณ ๋ด ์ฑ ์ค ํ๋์์ ์์ ์ ๋๋ฉ์ด์ ์ด ๋๋ฝ๋์์ต๋๋ค. ๋๋ 0.1๋ ๊ด์ฐฎ๋ค๋ ๊ฒ์ ์์๋ค. ๋น์ ์ ๋์์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
@hasen6์ ๋์ํฉ๋๋ค. ์ฌ์ฉ์๊ฐ ์ฆ์ Objective-C( AppDelegate.m
)์ ๋ฐ์ด๋ค์ด React Native ์ฑ์ ์์ฑํ๋ ์ฆ์ ์ผ๋ถ ์ฝ๋๋ฅผ ์กฐ์ ํด์ผ ํ๋ค๋ ๊ฒ์ ํ์คํ ์กฐ๊ธ ์ด์ํด ๋ณด์
๋๋ค. React Native๊ฐ ์ด ์์ ์ฌํญ์ด ์ด๋ฏธ ์ ์ฉ๋ ์ฝ๋๋ฅผ ์์ฑํ ์ ์๋์? ์๋๋ฉด JavaScript(๋๋ ์ ์ธ์ ๊ตฌ์ฑ ์ธ์ด)์์ ์์ ํ๋ฉด ๊ตฌ์ฑ์ ์ํ ๋ณด๋ค ์ถ์์ ์ธ ์๋ฃจ์
์ ๋์
ํ์๊ฒ ์ต๋๊น?
@johanatan ์์ด๋ฌ๋ํ๊ฒ๋ React Native์ ๊ฐ์ฅ ํฌ๊ณ ์ค๋ ์ง์๋๋ ๋ ๊ฐ์ง ๋ฌธ์ ๋ ์ผ์ข ์ ํฐ์ ํ๋์์ ๊ด๋ จ์ด ์์ต๋๋ค. ์ด ์ค๋ฅ์ ์ด๋ฏธ์ง์ ํฐ์์ด ๊น๋ฐ์ ๋๋ค.
๋ด LaunchScreen xib๋ฅผ ์ฌ์ฉํ ๋ ๋ ์ปค์ง๋ ๊ฒฝํฅ์ด ์์ต๋๋ค. ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
๋ฌด์์ด ๋ ํฐ ๊ฒฝํฅ์ด ์์ต๋๊น?
UIView *loading = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil ] ๊ฐ์ฒด ctAtIndex:0 ];
rootView.loadingView = ๋ก๋ฉ;
๋ก๋ฉ UI ๋ณด๊ธฐ, ํฌ๊ธฐ๊ฐ ์กฐ์ ๋์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ด LaunchScreen.xib์ธ ์คํ๋์ ํ๋ฉด๊ณผ ๋์ผํ๋ค๊ณ ๊ฐ์ ํฉ๋๋ค.
ํฌ๊ธฐ ํด๋์ค์ ์ ์ฝ ์กฐ๊ฑด์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
@akoshdee ๋ง์ต๋๋ค . ํ๋ฉด ํฌ๊ธฐ์ ์ผ์นํ๋๋ก ๋ณด๊ธฐ ํฌ๊ธฐ๋ฅผ ๋ช ์์ ์ผ๋ก ์ค์ ํด์ผ ํฉ๋๋ค. ์ฌ์ฉ
loading.frame = [UIScreen mainScreen].bounds;
์ด๋ฏธ ํ๋ ์์ ๋ณ๊ฒฝํ์ง๋ง ์ฌ์ ํ ์๋ํ์ง ์์ต๋๋ค
์๋๋ก์ด๋์ ๋ํ ์ด๋ค ์๋ฃจ์ ?
@ajoshdee loadingView.frame = [UIScreen mainScreen].bounds;
ํ ๋น์ ์ ์๊ฒ ํจ๊ณผ๊ฐ ์์์ง๋ง ๋ค์์ ์๋ํ์ต๋๋ค: loadingView.frame = self.window.bounds;
์ด๊ฒ์ ๋ด๊ฐ ์ฌ์ฉํ๋ ๊ฒ์ ๋๋ค :
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil];
UIImageView *loadingView = [nibObjects objectAtIndex:0];
loadingView.frame = self.window.bounds;
rootView.loadingView = loadingView;
์ฌ๋ณด์ธ์! ๋ณด๊ธฐ์ ๋ฐ์ํ๊ธฐ ์ํด ์์์ ์ค์ ํ์ต๋๋ค.
rootViewController.view.backgroundColor = [UIColor blackColor];
@py110 @ajwhite
์๋๋ก์ด๋ ์๋ฃจ์ ์ ๊ทธ๊ฒ์ ์์๋ด๋ ๋ฐ ์ผ๋ง๋ ์ค๋ ์๊ฐ์ด ๊ฑธ๋ ธ๋์ง ๋ ์์ ์๊ฒ ์ง์ฆ์ด ๋ ์ ๋๋ก ์ด๋ฆฌ์๊ฒ ๊ฐ๋จํฉ๋๋ค.
3๋จ๊ณ ์คํ๋์ ํ๋ฉด์ด ํฌํจ๋ฉ๋๋ค.
๋น์ทํ ๊ตฌํ @mehcode ๊ฐ ์์ต๋๋ค. ํ์ง๋ง ์ฌ๊ธฐ์ ์๋ ๊ฒ์ด ๋ง์์ getReactNativeHost()
ํธ์ถ์ด ์๋ ๊ฒ์ ๋ณด์ง ๋ชปํ์ต๋๋ค. ์๊ฒ ๋์ด์ ๋งค์ฐ ์ข์ต๋๋ค.
๋๋ ๋ค์์ ์ํํ์ต๋๋ค (๋ง์กฑํ์ง ์์)
SplashActivity
์ฑ์ด ์ด๋ฆด ๋ ์์๋จMainActivity
๋ฐ finish()
์ฆ์ ์ด๊ธฐMainActivity
๋ MainActivity
์์ ์คํ๋์๋ฅผ ํ์ํ๊ธฐ ์์ํ์๋ง์ "์ ๊ฒฝ ๋ชจ๋"์์ ๋ํ๋ด๋ ํ๋๊ทธ๋ก SplashActivity
๋ฅผ ์์ํฉ๋๋ค. ์ ์ ํ SplashActivity
๊ฐ ๋ซํ๊ณ ์ฑ์ด ํ์๋ฉ๋๋ค.@ajwhite
๊ฐ์ฌ ํด์. ํจ๊ณผ๋ ๋งค์ฐ ๋ถ๋๋ฝ์ต๋๋ค.
๋ด ํ์ฌ ํ๋ก์ ํธ์์ ๋๋ ๋ง ๊ทธ๋๋ก ReactActivity
๋ฅผ ๋ด ์ฝ๋๋ฒ ์ด์ค์ ๋ณต์ฌํ๊ณ mReactInstanceMangager
๋ฅผ private ๋์ protected๋ก ๋ง๋ค์์ต๋๋ค.
react-native 0.29(๋๊ธ์์ ๋งํ์ด์ผ ํจ)์์ react-native ํ์ ์ฐ๋ฆฌ์๊ฒ ๊ณต๊ฐ ๋ฉ์๋ getReactNativeHost()
๋ฅผ ์ ๊ณตํ์ต๋๋ค.
ReactNativeHost
์ปจํ
์ด๋๋ ํ๋ฅญํ ์์ง์์
๋๋ค. ์ด๊ฒ์ด ๋ฐ๋ก ๋ด๊ฐ ๊ฒช์ ๋ฌธ์ ์
๋๋ค. MainActivity์์ ์๋ช
์ฃผ๊ธฐ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.
๊ด์ฌ ์ฐธ์กฐ: https://github.com/facebook/react-native/commit/49f20f41546e3ba8e7fe43c84c4c701684d0434d#diff -1346852de0c7f8466a36d42de50ec808R2
์ฌ๊ธฐ์ ์ถ๊ฐํ๋ ค๋ฉด...
๋ด๊ฐ ์ฐพ์ ํด๊ฒฐ์ฑ
์ rootView
์ ๋ฐฐ๊ฒฝ์์ ํ ๋นํ์ง๋ง [UIColor colorWithPatternImage:img]
์
๋๋ค.
์์ ํ ๋ก๋๋ ๋๊น์ง ๊ณ์ ํ์๋๋๋ก ํ๊ธฐ ์ํด ์ง์ฐ์ด ํ์ํ์ง ์์ต๋๋ค.
์ฅ์น์ ๋ํด ์ํ๋ LaunchImage๋ฅผ ์ฐพ๋ ์ ์ฒด ์ค๋ํซ(๋ฐ @dvine-multimedia์์ ์ ๊ณตํ ํ ์ฌ์ฉ)์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
NSArray *allPngImageNames = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
for (NSString *imgName in allPngImageNames){
if ([imgName containsString:@"LaunchImage"]){
UIImage *img = [UIImage imageNamed:imgName];
if (img.scale == [UIScreen mainScreen].scale && CGSizeEqualToSize(img.size, [UIScreen mainScreen].bounds.size)) {
rootView.backgroundColor = [UIColor colorWithPatternImage:img];
}
}
}
์ด์ LaunchImage๋ react-native ๋ฒ๋ค์ด ์์ ํ ๋ก๋๋ ๋๊น์ง ๊ณ์ ํ์๋ฉ๋๋ค.
๋๋ ๊ธฐํ ์์ด ์ด ๋ํ์์ ๊ฑฐ์ ๋ชจ๋ ์ฝ๋ ๋ธ๋ก์ ์๋ํ์ง๋ง ์ด๊ฒ์ ์๋ฒฝํ๊ฒ ์๋ํ์ต๋๋ค.
@dbonner1987 ๊ฐ์ฌํฉ๋๋ค!
์๋๋ก์ด๋์ ๋ํ ์ด๋ค ์๋ฃจ์ ?
@pareekkhushboo77 https://github.com/mehcode/rn-splash-screen/blob/master/docs/android.md
@sercanov @dbonner1987 ์ด๊ฒ์ ๋ํ iOS์ ๋ํด ์์์ ์ธ๊ธํ ์ ๊ทผ ๋ฐฉ์์ ์ฌ์ฉํ์ฌ ์๋ฐ์คํฌ๋ฆฝํธ ์คํ ํ๋ฉด์ ์ํํฉ๋๋ค.
@arnemart ๊ฐ์ฌํฉ๋๋ค. ์ฌ์ ํ RN 0.30.0์์ ์๋ํฉ๋๋ค. ์ฑ์ ์ญ์ ํ๊ณ ๋ค์ ์ค์นํด์ผ ํ์ต๋๋ค. ์ฒ์์๋ ํฐ์ ํ๋์๊ฐ ์์์ง๋ง ๊ทธ ์ดํ์๋ ์์์ต๋๋ค.
@nicklockwood ์ค์ ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ๋ก๋๋๋ ์๊ธฐ๋ฅผ ์๊ธฐ ์ํด ์ฌ์ฉํ ์ ์๋ ์ผ์ข
์ ์ฝ๋ฐฑ์ด
๊ทธ๋์ ์ ๋ ๋ค์๊ณผ ๊ฐ์ด ํ๊ณ ์ถ์ต๋๋ค.
๊ทธ๋์ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ก๋ฉ์ด ์๋ฃ๋๋ฉด ์ฝ๋ฐฑ์ด ํ์ํฉ๋๋ค.
@UKDeveloper99 ์ ๊ฐ ์์ ๋ช ๋ฒ ๋งํฌํ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ธ์. ์ฌ์ฉ ๊ฐ๋ฅํ ์ฝ๋ฐฑ์ด ์์ต๋๋ค.
https://github.com/mehcode/rn-splash-screen/blob/master/docs/android.md
@mehcode ์์ ๊ฐ์ฌํฉ๋๋ค!!
๋ฒ๋ค์ด ๋ก๋๋๋ฉด ๊บผ์ง๋ LaunchScreen.storyboard
๊ตฌํ ๋ฐฉ๋ฒ์ ๋ํ ์ ์์ด ์๋ ์ฌ๋์ด ์์ต๋๊น? ํ์ฌ ๊ณ ์ ๋ ์๊ฐ ๋์ ํ์๋๊ณ ํฐ์ ํ๋ฉด์ด ํ์๋ ๋ค์ ์ ํ๋ฆฌ์ผ์ด์
์ด RN 34.1 xcode 8์ ๋ก๋ํฉ๋๋ค.
@ajoshdee ๋ณด๊ธฐ๊ฐ ํ๋ฉด๋ณด๋ค ํจ์ฌ ์ปค์ง๋ ๋น์ทํ ๋ฌธ์ ๊ฐ ์์์ต๋๋ค. ๊ด๋ จ์ด ์๋์ง ํ์คํ์ง ์์ง๋ง LaunchScreen.xib
์์ AutoLayout์ ์ฌ์ฉํ๊ณ ์์์ต๋๋ค.
๋๋ ๋ํ ์ค์ ํด์ผํ๋ค
launchScreenView.autoresizingMask = UIViewAutoresizingNone;
์ฌ์ด์ฆ๋ฅผ ์๋ง๊ฒ ๋ง์ถ๋ ค๋ฉด.
๋ฐ๋ผ์ ์์ ์ถ๊ฐ๋ ํ๊ณผ ํจ๊ป https://github.com/facebook/react-native/issues/1402#issuecomment -166963438
appdelegate.m ์์ ์ด ์ค์ ๊ต์ฒดํ์ฌ ์์ ์์์ ์ ๋ฐ์ดํธํ ์๋ ์์ต๋๋ค.
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
์ด ์ค๋ก :
rootView.backgroundColor = [[UIColor alloc] initWithRed:0.94 green:0.90 blue:0.89 alpha:1.0];
์ด ์น์ฌ์ดํธ์์ ์ํ๋ ์์ ์ฐพ๊ธฐ
๋๊ตฐ๊ฐ Android์์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๊น?
ios์ android ๋ชจ๋์ ๋ํ ์๋ฃจ์
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. https://github.com/mehcode/rn-splash-screen .
๋ด app.tsx(์ง์
์ )์ ๋ ๋๋ง ๊ธฐ๋ฅ์์ ์คํ๋์ ํ๋ฉด์ ์จ๊ธฐ๊ณ ๋ด ๋ชจ๋ https ์์ฒญ์ด ์๋ฃ๋ ๋๊น์ง ๋์ผํ ์ด๋ฏธ์ง๋ฅผ ํ์ํ์ต๋๋ค.
๋ด ์ฝ๋:
```
๊ณต๊ฐ ๋ ๋๋ง()
{
SplashScreen.hide();
//after everything has finished loading - show my app.
if (this.state.isFinishedloading)
{
return (
<this.navigator screenProps={{ ...providers }} />
);
}
// Until then show the same image as the splash screen with an ActivityIndicator.
return (
<View style={{ flex: 1 }}>
<Image style={styles.image} source={require('../assets/img/splash.png')} >
<ActivityIndicator style={styles.indicator} color="#fff"></ActivityIndicator>
</Image>
</View>
);
}
```
์คํ๋์ ํ๋ฉด์ ์คํ ๋ฆฌ๋ณด๋๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ด์ ๋ํ ํด๊ฒฐ์ฑ ์ด ์์ต๋๊น? ๋ ์ด์ ๊ฐ ์ฐจ์์ ๋ํ ์์ ํ๋ฉด ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค.
AppDelegate.m
๋ด๋ถ์ iOS์ฉ ๊ธฐ๋ณธ ๋ฐ์์์ ๊ทธ์ ๋ฐ๋ผ RGB ์์ ์ฝ๋๋ฅผ ์์ฑํ์ฌ ๋ค์ ์ค์ ๋ณ๊ฒฝํฉ๋๋ค.
rootView.backgroundColor = [[UIColor alloc] initWithRed:52.0f/255.0f green:73.0f/255.0f blue:94.0f/255.0f alpha:1];
RED์ ๊ฒฝ์ฐ ์ซ์ 52๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค.
GREEN์ ๊ฒฝ์ฐ ์ซ์ 73์ ๋ณ๊ฒฝํ์ญ์์ค.
ํ๋์์ ๊ฒฝ์ฐ ์ซ์ 94๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค.
_์ฐธ๊ณ : ๋๋ react native v0.51.0_์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
์๋๋ก์ด๋๋ ์์ง ์๋ฃจ์ ์ด ์๋์?
@otoinsa๋ @neomib์ https://github.com/facebook/react-native/issues/1402#issuecomment -339336380 ์์ ๋ต๋ณ์ https://github.com/crazycodeboy/react-native-splash-screen ๊ณผ ๊ฐ์ด ์ ์๋ํ๋ ๋ค๋ฅธ ์คํ๋์ ํ๋ฉด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ต๋๋ค
LaunchScreen์ผ๋ก ์ฌ์ฉ๋๋ ์คํ ๋ฆฌ๋ณด๋์ ๋ํ ์ ์ ์ฌํญ์ด ์์ต๋๊น?
๋ด ์ ๊ทผ ๋ฐฉ์์ ๋ค์๊ณผ ๊ฐ์์ต๋๋ค(ํ์ง๋ง ์ฑ ์์ ์ ์ถฉ๋)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
[Fabric with:@[[Crashlytics class]]];
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"MyApp"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [UIColor clearColor];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// UIViewController *rootViewController = [UIViewController new];
UIStoryboard *storyboard = self.window.rootViewController.storyboard;
UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"the_storyboard_id"];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
์ฑ์ด ๋ค์ ์ค๋ฅ์ ํจ๊ป ์ถฉ๋ํฉ๋๋ค.
2018-03-30 11:21:04.995601+0530 MyApp[6119:101967] Running application MyApp ({
initialProps = {
};
rootTag = 1;
})
2018-03-30 11:21:05.014109+0530 MyApp[6119:101967] *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.33.6/UIApplication.m:3529
2018-03-30 11:21:05.090174+0530 MyApp[6119:101967] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'
*** First throw call stack:
(
0 CoreFoundation 0x000000011170f12b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000110001f41 objc_exception_throw + 48
2 CoreFoundation 0x00000001117142f2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010faa2d69 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x000000010d838051 -[UIApplication _runWithMainScene:transitionContext:completion:] + 3102
5 UIKit 0x000000010dc016f8 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924
6 UIKit 0x000000010dfd74c8 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
7 UIKit 0x000000010dc012f1 -
๊ฐ์ฌ ํด์.
๊ต์ฒด
UIStoryboard *storyboard = self.window.rootViewController.storyboard;
~์ ํจ๊ป
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
์ด์ ์ฑ์ด ์์๋์ง๋ง ๊ฒ์์ ๋ฐฐ๊ฒฝ์ด ๋ํ๋ฉ๋๋ค.
๋๋ https://github.com/crazycodeboy/react-native-splash-screen์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ํจ์ฌ ์ฝ์ต๋๋ค :)
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ฌ๊ธฐ์ ์ถ๊ฐํ๋ ค๋ฉด...
๋ด๊ฐ ์ฐพ์ ํด๊ฒฐ์ฑ ์
rootView
์ ๋ฐฐ๊ฒฝ์์ ํ ๋นํ์ง๋ง[UIColor colorWithPatternImage:img]
์ ๋๋ค.์์ ํ ๋ก๋๋ ๋๊น์ง ๊ณ์ ํ์๋๋๋ก ํ๊ธฐ ์ํด ์ง์ฐ์ด ํ์ํ์ง ์์ต๋๋ค.
์ฅ์น์ ๋ํด ์ํ๋ LaunchImage๋ฅผ ์ฐพ๋ ์ ์ฒด ์ค๋ํซ(๋ฐ @dvine-multimedia์์ ์ ๊ณตํ ํ ์ฌ์ฉ)์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
์ด์ LaunchImage๋ react-native ๋ฒ๋ค์ด ์์ ํ ๋ก๋๋ ๋๊น์ง ๊ณ์ ํ์๋ฉ๋๋ค.