bug(camera): chooseFromGallery blocks the main thread on iOS while the photo grid opens

Đang mở
#2,603 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 29 ngày

@masimplo đang làm issue này rồi.

Từ ngày 24/9/2026.

  • #22 của @masimplo — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ios, swift
Lĩnh vực
mobile-dev, performance

Hướng nghiên cứu

Start with Sources/IONCameraLib/Interfaces/PhotoLibrary/IONCAMRPhotoLibraryView.swift, especially lines 82-114, and reproduce on an iOS device with a large photo library. Inspect the grid construction, scrollTo behavior, and selectedAssetArray checks while measuring main-thread work. Done means chooseFromGallery opens without a library-size-dependent freeze.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

platform: ios

Bug Report

Plugin(s)

@capacitor/camera 8.2.0 (iOS, via IONCameraLib 1.0.4). The affected code is unchanged in IONCameraLib 1.0.5 and 2.0.0.

Capacitor Version
@capacitor/core: 8.4.1
@capacitor/ios: 8.4.1
@capacitor/cli: 8.4.1
@capacitor/camera: 8.2.0
Platform(s)

iOS

Current Behavior

When Camera.chooseFromGallery() opens the photo grid, the main thread can freeze for several seconds. Our production app reported an App Hang of 2.4–3.2 s on an iPhone 15 Pro running iOS 26.6.1.

The main-thread stack is inside IONCAMRPhotoLibraryView.body, building grid cells:

swift_retain
IONCAMRPhotoLibraryView.selectedAssetArray.getter
closure in IONCAMRPhotoLibraryView.body.getter (IONCAMRPhotoLibraryView.swift:98)
Button.init
closure in IONCAMRPhotoLibraryView.body.getter (IONCAMRPhotoLibraryView.swift:86)
ZStack.init
closure in IONCAMRPhotoLibraryView.body.getter (IONCAMRPhotoLibraryView.swift:83)
closure in ForEachState.item
... (SwiftUI layout frames)
closure in IONCAMRPhotoLibraryView.body.getter (IONCAMRPhotoLibraryView.swift:114)
... 
main
Expected Behavior

The gallery opens without blocking the main thread, however many assets are in the library.

Code Reproduction

We don't have a standalone sample app yet. The call is:

await Camera.chooseFromGallery({
  mediaType: MediaTypeSelection.Photo,
  allowMultipleSelection: false,
  quality: 90,
  targetWidth: 1200,
  targetHeight: 1200,
  correctOrientation: true,
});

Steps:

  1. Use an iOS device with a large photo library (thousands of assets) and full photo access.
  2. Call Camera.chooseFromGallery() as above.
  3. The UI freezes while the grid appears. The freeze should get longer as the library grows.
Other Technical Details
  • Seen in production on iPhone 15 Pro, iOS 26.6.1 (23G83). The device's thermal state was "serious", so it was probably throttled.
Additional Context

The likely cause, from reading IONCAMRPhotoLibraryView.swift:

ForEach(photoLibraryService.results, id: \.self) { asset in ... }   // line 82: every asset in the library
...
.onAppear {
    value.scrollTo(photoLibraryService.results.startElement, anchor: .bottom)   // line 114
}
  • scrollTo on appear jumps to the far end of a LazyVGrid that holds the whole library. Our stack shows that line 114 makes SwiftUI build ForEach cells on the main thread, so the work likely grows with library size.
  • Each cell also calls selectedAssetArray.contains(asset) twice (lines 98 and 101). That's a linear search per cell, run on every body evaluation.
Ngôn ngữ chính
Java
Star
688
Fork
692
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ionic-team/capacitor-plugins

Tất cả issue của ionic-team/capacitor-plugins

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.