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

Focus on Macro 100% width #581

Open
melhotiby opened this issue Sep 9, 2023 · 1 comment
Open

Focus on Macro 100% width #581

melhotiby opened this issue Sep 9, 2023 · 1 comment

Comments

@melhotiby
Copy link

melhotiby commented Sep 9, 2023

Describe the bug
I can not get the camera to focus on macro with 💯 width. I am using version v14.0.0-beta12 from #533 (comment)

To Reproduce

import React from 'react';
import {StyleSheet, View, Dimensions} from 'react-native';
import {Camera} from 'react-native-camera-kit';

const {width, height} = Dimensions.get('window');
const cameraHeight = height * 0.25; // Set the camera's height to 25% of the screen's height
const cameraWidth = width; // Set the camera's width to 100% of the screen's width

const styles = StyleSheet.create({
  container: {
    width: cameraWidth,
    height: cameraHeight,
  },
  camera: {
    flex: 1,
    aspectRatio: 16 / 9, // Set the aspect ratio to 16:9 for widescreen
  },
});

export default function AppScan() {
  const scanBarcode = e => {
    console.log({code: e.nativeEvent.codeStringValue});
  };

  return (
    <View>
      <View style={styles.container}>
        <Camera
          focusMode="on"
          scanBarcode={true}
          style={styles.camera}
          showFrame={false}
          onReadCode={scanBarcode}
        />
      </View>
      {/* OTHER CONTENT */}
    </View>
  );
}

Expected behavior
Expecting the aspect ratio to make the camera screen wider. I would like the camera to take 100% of the width and its not doing that. Is the aspect ratio is locked into a square?

Screenshots
IMG_0416

Trying to get the camera to take up 100% of the width on the top 25% of the screen.

@scarlac
Copy link
Collaborator

scarlac commented Oct 16, 2023

The camera maintains the aspect ratio, while staying with the viewport it's given, which is to prevent common mistakes with warping and accidental cropping. (We used to get reports of people saying their camera content was cropped, or the picture bigger than what they were seeing).

If you'd like it to be cropped, you can place the Camera component and size it appropriately, then use a parent View to limit how much of the child is visible (by providing a smaller size). Note that you need to decide on how to crop the camera. I'd assume you want it cropped from the center, in which case you need to center-align the camera component in the smaller container.

We don't currently have an API for changing the aspect ratio or crop behavior as those features caused problems in the past, particularly on Android.

Also please note that cropping the viewport does not change what is saved when capturing a photo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants