enebin / Aespa

From camera to album, in just 2 lines
https://enebin.github.io/Aespa/documentation/aespa/
MIT License
106 stars 20 forks source link

Enhance orientation handling in InteractivePreview and Preview classes #43

Closed subelsky closed 5 months ago

subelsky commented 5 months ago

Summary

Improved the handling of orientation changes in the InteractivePreview and Preview classes to ensure proper resizing and layout adjustments of the AVCaptureVideoPreviewLayer during device rotation. These changes address issues where the preview layer would not correctly adapt to new geometry sizes, leading to misalignment.

Details

  1. InteractivePreview:

    • Added an onChange modifier to observe changes in the geometry size.
    • Updated the layer frame on the main dispatch queue to ensure proper resizing.
  2. Preview:

    • Removed the direct assignment of previewLayer.frame in updateUIViewController.
    • Ensured the previewLayer is added to the view controller’s layer only if it hasn’t been added already.
    • Updated the previewLayer.frame on the main dispatch queue to ensure it resizes correctly when the view bounds change.

Note

This will not affect the orientation of the session. To do that, application code must wrap the preview layer with handlers that call aespaSession.common(.orientation(orientation: ...)). I have some code that demonstrates this, but it's very specific to my app, so I couldn't cleanly extract a good example for the README. I can try to tackle that in a future commit.

enebin commented 5 months ago

Hi @subelsky. Awesome code! I’ve reviewed the code and tested it on the device and it looks good to me 👍. I'll be merge this into the latest version for release.

The issue you mentioned in your note is something I've been thinking about for a while too, but I haven't been able to crack it yet 😅. If you have some time later, I’d love for you to share some of your works. Maybe we can brainstorm and work through it together!

Thanks again for your contribution!