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

Aperta
#72 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
android, typescript
Ambito
mobile

Direzione di ricerca

Individua IONCAMROpenPhotoPickerActivity e la relativa dichiarazione nel manifest della libreria, quindi esamina come onCreate utilizza savedInstanceState prima di avviare il picker. Riproduci il flusso di rotazione su Android con il selettore di foto aperto. Il lavoro è completato quando la rotazione conserva il picker esistente senza sovrapporre un'altra istanza; verifica se l'editor di immagini e le attività di caricamento dichiarati in modo simile mostrano lo stesso schema.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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" />
Lingua principale
TypeScript
Stelle
6
Fork
3
Merge medio
2g 18h
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ionic-team/capacitor-camera

Tutte le issue di ionic-team/capacitor-camera

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.