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

Added zoom control #559

Merged
merged 13 commits into from
Jul 19, 2023
Merged

Added zoom control #559

merged 13 commits into from
Jul 19, 2023

Conversation

scarlac
Copy link
Collaborator

@scarlac scarlac commented Jul 12, 2023

  • Added zoom control
  • Added max zoom control
  • Added onZoom handler
const [zoom, setZoom] = useState(0);
<Camera
  zoomMode="on"
  zoom={zoom}
  maxZoom={15}
  torchMode={torchMode ? 'on' : 'off'}
  onZoom={(e) => {
    console.log('zoom', e.nativeEvent.zoom);
    setZoom(e.nativeEvent.zoom);
  }}
/>

@scarlac
Copy link
Collaborator Author

scarlac commented Jul 12, 2023

@DavidBertet in case you're interested.

Added max zoom control
Added onZoom handler
@DavidBertet
Copy link
Contributor

@DavidBertet in case you're interested.

Looking at it!

@@ -54,6 +55,7 @@ const CameraExample = ({ onBack }: { onBack: () => void }) => {
const onSwitchCameraPressed = () => {
const direction = cameraType === CameraType.Back ? CameraType.Front : CameraType.Back;
setCameraType(direction);
setZoom(0); // When changing camera type, reset to default zoom for that camera
Copy link
Contributor

@DavidBertet DavidBertet Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that be done by the native side / Camera component? Sounds like the expected behavior as a user of the framework. RealCamera probably does it already in update(cameraType

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it uses the declarative API it must fully control the zoom factor. Thus, it must also manually reset the value.
The only alternative to these things are to use an imperative API for zooming which circumvents the issues. It all boils down to the fact that the gesture control and default zoom are only available in native

Comment on lines 25 to 29
<NativeCamera maxZoom={props.maxZoom ?? 20} style={{ minWidth: 100, minHeight: 100 }} ref={nativeRef} {...props} />
);
});

Camera.defaultProps = {
Copy link
Contributor

@DavidBertet DavidBertet Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use defaultProps bellow to set 20 by default. We might want it on Android as well

Suggested change
<NativeCamera maxZoom={props.maxZoom ?? 20} style={{ minWidth: 100, minHeight: 100 }} ref={nativeRef} {...props} />
);
});
Camera.defaultProps = {
<NativeCamera style={{ minWidth: 100, minHeight: 100 }} ref={nativeRef} {...props} />
);
});
Camera.defaultProps = {
maxZoom: 20,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I actually wanted to remove that. maxZoom shouldn't be required in RN, as that means we can't tell if it's undefined (unrestricted) or 20 (restricted).

src/Camera.d.ts Outdated
zoomMode?: ZoomMode;
/**
* **iOS only.**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not "iOS only" anymore

@scarlac scarlac merged commit b2bdc44 into master Jul 19, 2023
4 of 6 checks passed
@scarlac scarlac deleted the feature/zoom branch July 19, 2023 23:33
pinchGestureStartedAt = detector.currentSpan
return true
}
override fun onScale(detector: ScaleGestureDetector?): Boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may have reverted a change made in https://github.com/teslamotors/react-native-camera-kit/pull/551/files?w=1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @elliottkember - This was re-fixed and released in v14.0.0-beta13.

elliottkember added a commit to elliottkember/react-native-camera-kit that referenced this pull request Oct 3, 2023
teslamotors#559 broke a change in teslamotors#551 regarding override types. This restores the fix
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

Successfully merging this pull request may close these issues.

3 participants