🔃

Expo (CNG)でiPadのときに縦画面に固定する

2025/01/15に公開

Expoで作っているiOSアプリケーションで、iPadの場合に縦画面に固定する方法について知らなかったので備忘録として。

app.json(app.config.js)にrequireFullScreenUISupportedInterfaceOrientations~ipad を設定します。

{
  "expo": {
    // 縦画面固定
    "orientation": "portrait",
    "ios": {
      // iPadでSlide Over/Split Viewを無効化
      "requireFullScreen": true,
      "infoPlist": {
        // Info.plistでiPadの場合のサポートするOrientationを指定
        "UISupportedInterfaceOrientations~ipad": [
          "UIInterfaceOrientationPortrait",
          "UIInterfaceOrientationPortraitUpsideDown"
        ]
      }
    },
}

設定後、expo prebuild でネイティブのコードを生成して、Info.plistに "UISupportedInterfaceOrientations~ipad" が反映されていればOK!
これでiPadの画面固定ができました!

なぜ`requireFullScreen`が必要だったのか

最初は"infoPlist""UISupportedInterfaceOrientations~ipad"を指定したらら固定されるかな?と思いましたが、@expo/config-pluginsで requireFullScreen=falseのときは値を上書きするようになっていました。このあたりはドキュメントに書かれていたら嬉しいですね😓
https://github.com/expo/expo/blob/sdk-52/packages/%40expo/config-plugins/src/ios/RequiresFullScreen.ts#L83-L93

テラーノベル テックブログ

Discussion