[React-Native] ์ธ๋ก ๋ชจ๋ ๊ณ ์ (ํ๋ฉด ํ์ ๋ง๊ธฐ, ๊ฐ๋ก ๋ชจ๋ ๋ง๊ธฐ)
๐ก ํ๋ฉด ํ์ ์ด ์๋๊ฒ ํ๊ณ ์ถ์ด์!
์๋น์คํ๊ณ ์ถ์ ์ดํ์ด ์ธ๋ก ๋ชจ๋๋ง ๋๊ฒ ๊ฐ๋ฐํ๋๋ฐ, ํ๋ฉด ํ์ ์ ํ๋ฉด์ UI๊ฐ ๊นจ์ง๊ฑฐ๋ ๋ฒ๊ทธ๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค.
์ด๋ฅผ ๋ง๊ธฐ ์ํด์, RN ๊ธฐ์ค์ผ๋ก ํ๋ฉด ํ์ ์ ๋ง๋ ๋ฐฉ๋ฒ์ ๊ณต์ ํ๋ ค๊ณ ํฉ๋๋ค.
๐ก IOS๐ฑ
1. ios/.../Info.plist ํ์ผ ์คํ
2. ์๋์ ๊ฐ์ด ์ค์ ์ ์ถ๊ฐ
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
๐ก Android ๐ค
1. android/app/src/main/AndroidManifest.xml ํ์ผ ์คํ
2. ์๋์ ๊ฐ์ด ์ค์ ์ ์ถ๊ฐ
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
...>
...
</activity>
์ ์ฝ๋๋ค์ ์์ ํด ์ฃผ๊ณ , ์ดํ์ ์ฌ์์ํ๋ฉด ํ๋ฉด ํ์ ์ด ๊ณ ์ ๋ฉ๋๋ค.
๐ก ๋ง์ฝ ์ ํํ๊ฒฝ์์๋ ํ๋ฉด ํ์ ์ ๋ง์ง๋ง, ๋๋ฒ๊ทธ ๋ชจ๋์์๋ ํ๋ฉด ํ์ ์ ํ๊ณ ์ถ๋ค๋ฉด?
๐ฃ IOS
1. Info.plist ํ์ผ์ ์์์ ์ถ๊ฐํ ์ฝ๋ ์ญ์ ํ๊ธฐ
2. AppDelegate.m ํ์ผ ์คํ ํ ์ฝ๋ ์ถ๊ฐ
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
#ifdef DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"YourAppName"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
#ifdef DEBUG
return UIInterfaceOrientationMaskAll;
#else
return UIInterfaceOrientationMaskPortrait;
#endif
}
@end
๐ฃ Android
1. AndroidManifest.xml ํ์ผ์ ์์์ ์ถ๊ฐํ ์ฝ๋ ์ญ์
2. MainActivity.java ์คํ ํ ์์
package com.yourapp;
import com.facebook.react.ReactActivity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
public class MainActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "YourAppName";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (BuildConfig.DEBUG) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
}
๐ ์ ๋ฆฌ
1. ์ธ๋ก ๋ชจ๋๋ก ๊ณ ์ ํ๊ณ ์ถ์ผ๋ฉด ์๋ ์ฝ๋๋ฅผ ์์
2. ios -> Info.plist ์์
3. android -> AndroidManifest.xml ์์
4. ๋๋ฒ๊ทธ ๋ชจ๋์ ์ค์ ๋ชจ๋๋ฅผ ๋๋ ์ ์ปจํธ๋กคํ ๊ฒฝ์ฐ ์์ ํด์ผ ํ ๊ณณ์ด ๋ค๋ฆ
๊ธ ์ฝ์ด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค :)
ํ๋ฆฐ ๋ด์ฉ์ด ์๊ฑฐ๋, ๋ง๋ถ์ผ ๋ด์ฉ์ด ์๋ค๋ฉด ์ธ์ ๋ ์ง ๋๊ธ ๋ฌ์์ฃผ์ธ์!
์ ๊ธ์ด ์กฐ๊ธ์ด๋๋ง ์ฝ์ผ์ ๋ถ๋ค์๊ฒ ๋์์ด ๋๋๋ก ๋
ธ๋ ฅํ๊ฒ ์ต๋๋ค
๋ค์ ํธ์ ๋ดฌ์~