Fix Android focus not using correct focus point#958
Merged
mrousavy merged 1 commit intomrousavy:mainfrom Mar 31, 2022
Merged
Conversation
This commit fixes mrousavy#758. I was having the same issue and looked into it a bit. I found [this StackOverflow answer](https://stackoverflow.com/a/60585382) which described a solution to the same problem. Rather than manually calculate the focus point, we can get the PreviewView to do it for us. This fixes the issue because the PreviewView factors in any scaling or resizing of the view on the screen, which we weren't doing before. The only potential issue is that this needs to run on the UI thread (which is what the `withContext` is doing), but I've tested it with frame processors enabled and disabled, and have found no issues in either case.
Owner
|
Hey, thanks so much for your PR! I think everything looks good, LGTM! |
Contributor
Author
|
Thanks for the quick review! 😄 |
isaaccolson
pushed a commit
to isaaccolson/deliveries-mobile
that referenced
this pull request
Oct 30, 2024
This commit fixes mrousavy#758. I was having the same issue and looked into it a bit. I found [this StackOverflow answer](https://stackoverflow.com/a/60585382) which described a solution to the same problem. Rather than manually calculate the focus point, we can get the PreviewView to do it for us. This fixes the issue because the PreviewView factors in any scaling or resizing of the view on the screen, which we weren't doing before. The only potential issue is that this needs to run on the UI thread (which is what the `withContext` is doing), but I've tested it with frame processors enabled and disabled, and have found no issues in either case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This PR fixes the
focusfunction on Android not focusing on the given point (#758). The issue is that when calculating the focus point withSurfaceOrientedMeteringPointFactory, it does not factor in any scaling or cropping that has been done to the camera's view (thanks to this StackOverflow answer for pointing me in the right direction!). I think it's possible this issue is not obvious unless you're resizing the camera view significantly in some way.Changes
Rather than manually calculate the focus point, we can get the PreviewView to do it for us. This fixes the issue because the PreviewView factors in any scaling or resizing of the view on the screen. The only potential issue is that this needs to run on the UI thread (which is what the
withContextis doing), but I've tested it with frame processors enabled and disabled, and have found no issues in either case.Tested on
Tested on Pixel 3a running Android 12
Related issues
Fixes #758