Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance orientation handling in InteractivePreview and Preview classes #43

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

subelsky
Copy link
Contributor

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.

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 enebin changed the base branch from main to release/0.5.3 June 3, 2024 08:26
@enebin
Copy link
Owner

enebin commented Jun 3, 2024

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!

@enebin enebin added the enhancement New feature or request label Jun 3, 2024
@enebin enebin merged commit bde72fc into enebin:release/0.5.3 Jun 3, 2024
@subelsky subelsky deleted the add_orientation_awareness branch June 3, 2024 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants