-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
🐛 Camera stretched on Android #2142
Comments
@mrousavy Sponsoring this one as well :) |
Could you check if |
@mrousavy After testing on two devices, this was the result:
|
okok lemme take a look over the weekend or next week, its a race condition |
Hey, I've just started integrating react-native-vision-camera v3 into my project (i'm currently using react-native-camera) and encountered some issues related to aspect ratio on Android (similar to the problem described in this opened issue). UsageI am using the resizeMode='contain' mode to display the entire preview: <Camera
ref={this.cameraRef}
style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}
device={device}
format={format}
isActive={true}
photo={isPhoto}
video={isVideo}
audio={isVideo}
resizeMode='contain'
/> Tested on:
IssuesObserved Issues when I switch from one format to another:
For the first issue, it appears to be a problem related to react-native. Here is the patch to fix the issue:
For the second issue, it occurs when the surface is updated ("PreviewView Surface updated!"). The only solution I found is to restart the entire device configuration. Here is the patch to fix the issue:
However, this is not perfect, and the camera does not load instantly (refer to the 3rd video where you can see the incorrect ratio, and then 1 or 2 seconds later, the correct ratio after reloading the camera configuration). @mrousavy > Do you have any idea where this issue might be coming from? I've tried various approaches but haven't found an alternative fix. I'm available to experiment with other solutions if needed. VideosTo illustrate, here are videos of my application at different stages of the fixes: Without any fix: With the first fix: With the two fixes: |
Hey - thanks for the insights man! I need to take a look at this, probably just a small fix to avoid any race conditions here. Will have some free time soon, maybe in 1-2 weeks |
Has there been any progress on this? Still experiencing the issue |
Not sure if this helps, but when displaying an image taken with the camera, I found that I had to swap the height and width properties returned from the photo object.
|
Here is a (dirty) quickfix that helps me: Add the line:
to the class PreviewView in Then change the methode onMeasure in the same file to:
|
Thanks, it works for me |
It's a race condition, I fixed it on JS side by init the camera dimension at zero, settimeout waiting for the camera launch, and then resizing the camera view. |
i am also have this issue but when i make orientation lock to landscape |
@Jigar2311 I had the same problem in landscape mode and the fix of @JuMaruhn fixed my problem. |
@JuMaruhn's fix partially fixed my issue - it made the preview properly fill its container (I was getting blank bars on the sides), but for me the preview was still distorted. This was on a Samsung Galaxy S22. I too experienced some inconsistency, sometimes it would fix itself by flipping between front/back, minimising app, etc. I was able to workaround this issue by not feeding in function CameraPreview() {
const [isInitialised, setIsInitialised] = useState(false);
return (
<View onLayout={() => setIsInitialised(true)}>
<CameraView
format={
!isInitialised && Platform.OS === "android" ? undefined : format
}
resizeMode={"contain"}
style={{
aspectRatio: 3 / 4,
}}
{...yourOtherProps}
/>
</View>
);
} This is very similar to @j-jonathan's approach except I think it's a little lighter/quicker than reinitialising the entire camera config. |
Sure @Alexis200007, let me see if it works for me |
@Alexis200007 the stretching problem is fixes but i am using custom hight and width of video recording so i am passing the height and width in the format but it's not working for landscape.
|
I have the same problem in the version 3.7.0 I have tried to solve the problem by updating the size in the camera style 250 milliseconds after the component has been mounted
|
Hey! Does this fix your issue maybe? #2377 (still testing) |
Hey! After 8 hours of debugging, I finally found the culprit! I fixed the preview stretching issue in this PR: #2377 If you appreciate my dedication and free support, please consider 💖 sponsoring me on GitHub 💖 so I can keep providing fixes and building out new features for my open-source libraries in my free time. |
I am still experiencing the same with |
The same with |
it works for me. Thanks |
huntfpoly12 Works for me as well as a temp. fix, but not always. |
in my case I'm not specifying the "react-native-vision-camera": "^3.8.2" Edit: |
Yea the issue always existed, it is a race condition which apparently got worse after I made the codebase more predictable with the "persistent capture session" as this was the only part that was not predictable. I spent quite a lot of hours trying to fix this, and thought I fixed it a couple of times since I couldn't reproduce it on my devices anymore, but then had to switch back to other stuff and my main job, as well as the crashing issues on Samsung were higher priority than that. This will definitely be fixed in V4, maybe I can also find a quick solution to fix it in V3 now while V4 is still brewing |
Its a hell of a lot more manageable now for those that do have the issue @mrousavy, so much appreciated. The camera is much quicker as well. |
Thanks for your feedback @JshGrn, building in open-source I normally only hear negative feedback/bug reports - good to hear some positive feedback once in a while ❤️ But yea, overall there's A LOT of effort and thinking and careful design construction that goes into the codebase of VisionCamera, especially on Android, to make it predictable, thread-safe, fast and stable. This is something that's really hard to achieve with Camera2, so I'm really happy about how it works right now, even though the Preview stretching issue is still bugging me. |
Its fixable by simply activating the camera with a 0 width and height and then setting it in a useEffect right away, then onwards its perfect. I was getting crashes a lot when I kept the camera active whilst swapping between react-navigation stacks, but to fix the crash I simply deactivated the camera on blur and reactivated it on focus, that stopped all the crashing. I definitely don't use it for the full features this package offers, but for the ones I do its fantastic, and now I can work around it then its fine for my use-case. Much appreciated |
This is very helpful as I'm experiencing the same issues. Just for reference, what version of vision camera are you using with this workaround @JshGrn ? As @mrousavy mentioned, some of the older versions are unpredictable. Although it seems like I'm getting crashes on any version with slow androids when navigating through the stack so this workaround might be a step in the right direction. Thank you guys for your work. 🚀 |
I am using the latest at the time of writing (3.9.1). The app crashes if the camera stays active whilst navigating to another stack and then back to the camera, not the first time but if I was to scan -> go to stack -> scan -> go to stack, it will eventually crash. What I am now doing is: On the camera component in the camera stack view:
and
isActive is defined on the View which wraps all of the components that is set to true with onLayout:
that function essentially does some logic to deal with the aspect ratio by waiting 250ms and then setting the width and height properly. The fix to stop the crashing is by listening to the listeners of blur and focus, without those I can crash the app every time by quick navigation back and forth from the camera stack. |
I am seeing this issue on |
Adding the suggestion
does not resolve for Android |
What I'm doing instead is the following and it works flawlessly on 3.9.2 by executing right when the camera is ready and won't rely on a fixed time to update the camera preview width:
|
The hack for android is not working for me, still stretched on first mount... downgraded to 3.6.4 |
what is |
this will just be a |
My temporary solution on Android 12 and below |
Still have this issue in 3.9.1, stretched on first camera open |
Same problem here for 3.9.0 |
I posted a work-around earlier in the thread that works flawlessly on 3.9.1, might be worth trying it out. Note that I am using it on 3.9.1 specifically. |
Hey @inzqne, thanks for your reply! The package does not have version 3.9.2 on npm. How do I install it? |
Hey! I just released a new V4 beta (v4.0.0-beta.7) where I fixed a bunch of issues! 💪🚀 Can you test that and see if that fixes the issue for you? 😅
You might need to increase the |
My mistake, I meant 3.9.1 |
Hey @mrousavy ! I just tested the beta version
And it fixed the stretched issue 🎉 I had on my Android when I was testing on For anyone wondering, my Android specs are:
Thanks!! Hopefully the beta can be released sometime soon? |
Hey @mrousavy |
Thanks guys, great to hear that V4 now works perfectly! If you appreciate my work, please consider 💖 sponsoring me on GitHub 💖 so I can keep maintaining this library, fixing bugs and building new features! :)
@orenagiv not sure yet. I got a few other things to do, especially some things for RN MMKV as well to migrate to new arch and other things. |
Thanks @mrousavy 🙏 I can confirm v4.0.0-beta.10 resolved the stretch issue. So we will use this version. |
In this new version beta, i'm facing the problem with two blackBars, I know that is the purpose to avoid the stretch, but any tips to adapt in my code? |
What does two blackBars mean? |
I was having the same issue when I put the camera component inside another component, was showing two black bars, one in the top and another in a bottom. And I switch to version 3.6.4 that was stable and works fine. Now, I tryied to reproduce the same problem, installing the version beta and isn't appering more. But when put the props "photo={true}" on Camera component, the fps drops. |
This bug still appears in the ShadowLens app which should use v4 react-native-vision-csmera. Device: Huawei P10 Lite |
What's happening?
Camera is stretched on Android, behavior is not consistent as sometimes when closing the navbar and reopening the stretch is gone.
.
issue reproduced on these two devices:
Reproduceable Code
Relevant log output
Camera Device
Device
OnePlus 5T, Android version 10
VisionCamera Version
3.6.4
Can you reproduce this issue in the VisionCamera Example app?
I didn't try (⚠️ your issue might get ignored & closed if you don't try this)
Additional information
The text was updated successfully, but these errors were encountered: