bug: rotating the device while the photo picker is open relaunches it, stacking a second picker over the preview

オープン
#72 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
android, typescript
領域
mobile

調査の方向性

IONCAMROpenPhotoPickerActivity とそのライブラリマニフェスト宣言を見つけ、picker を起動する前に onCreate が savedInstanceState をどのように使用しているかを確認します。フォトピッカーを開いた状態で、Android 上で回転フローを再現します。回転によって別のインスタンスが積み重ならず、既存の picker が維持されれば完了です。同様に宣言されている画像エディターと読み込みアクティビティでも同じパターンが見られるか確認します。

索引モデルが issue の本文から書いたものです。

説明

Bug Report

Plugin version: @capacitor/camera 8.2.0 — also reproduced against ioncamera-android 1.0.2 (shipped in 8.2.2)
Capacitor version: 8.4.0
Platform: Android 13, Samsung Galaxy Tab Active3 (SM-T570), com.google.android.photopicker versionName 17

Current behavior

Rotating the device while the system photo picker is open launches a second picker instance on top of the first one. It is most visible when the user has opened the picker's preview screen: after rotating, the selection grid reappears over the preview.

Expected behavior

A configuration change should not relaunch the picker. The already-open picker should simply handle the rotation itself.

Steps to reproduce
  1. Call Camera.chooseFromGallery({ allowMultipleSelection: true }).
  2. In the system photo picker, select a photo and open the preview.
  3. Rotate the device to landscape.
  4. A second picker opens on top.

The picker options are irrelevant — the same happens with default options and with allowMultipleSelection: false.

Root cause

IONCAMROpenPhotoPickerActivity is declared in the library manifest without android:configChanges:

<activity
    android:name="io.ionic.libs.ioncameralib.view.IONCAMROpenPhotoPickerActivity"
    android:exported="false"
    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />

So a rotation destroys and recreates it. Its onCreate then passes savedInstanceState to super and never reads it again, calling launchSinglePicker / launchMultiplePicker unconditionally:

protected void onCreate(android.os.Bundle);
   0: aload_0
   1: aload_1
   2: invokespecial  // ComponentActivity.onCreate
   ...                // reads intent extras only — savedInstanceState is never tested
 110: invokespecial  // launchMultiplePicker
 119: invokespecial  // launchSinglePicker

Every recreation therefore launches another picker. This is visible in the activity stack, captured while the bug was on screen:

#3  com.google.android.photopicker/MainActivity          <- resumed, the one "on top"
#2  com.google.android.photopicker/MainActivity          <- first instance, showing the preview
#1  <app>/io.ionic.libs.ioncameralib.view.IONCAMROpenPhotoPickerActivity
#0  <app>/MainActivity

Both picker instances have resultTo=IONCAMROpenPhotoPickerActivity.

Note that the host app's own MainActivity declares android:configChanges="orientation|screenSize|…" (the Capacitor default), which is why the rest of the app absorbs rotation without issue — the library's proxy activity does not inherit that.

Suggested fix

Either guard the launch in onCreate:

if (savedInstanceState == null) {
    // launchSinglePicker / launchMultiplePicker
}

or declare android:configChanges on the activity in the library manifest.

IONCAMRImageEditorActivity and IONCAMRLoadingActivity are declared the same way and may be affected by the same pattern.

Workaround

Overriding the declaration in the app manifest stops the relaunch:

<activity
    android:name="io.ionic.libs.ioncameralib.view.IONCAMROpenPhotoPickerActivity"
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"
    tools:node="merge" />
主要言語
TypeScript
スター
6
フォーク
3
平均マージ
2日 18時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ionic-team/capacitor-camera のほかの issue

ionic-team/capacitor-camera の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。