Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
docs: add slide-up zoom recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Oct 10, 2018
1 parent 8de827e commit 737a5a2
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions docs/Recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,77 @@ const takePicture = () => {
## How to get a video thumbnail?

Use this package https://github.com/phuochau/react-native-thumbnail


## How to zoom with touch gestures?

Because of different project requirements there is no gesture zoom (like pinch zoom or slide-up zoom) implemented in this package. All implementation should be done in user-land.

However we have some recipies for common zoom behaviours. If you implemented your own solution feel free to add it to the list!

### SlideUp Zoom

```js
import React, { Component } from "react";
import { View, PanResponder, Dimensions } from "react-native";
import { RNCamera } from "react-native-camera";

// ZoomView
class ZoomView extends Component {
constructor(props) {
super(props);
this._panResponder = PanResponder.create({
onPanResponderMove: (e, { dy }) => {
const { height: windowHeight } = Dimensions.get("window");
return this.props.onZoomProgress(
Math.min(Math.max((dy * -1) / windowHeight, 0), 0.5)
);
},
onMoveShouldSetPanResponder: (ev, { dx }) => {
return dx !== 0;
},
onPanResponderGrant: () => {
return this.props.onZoomStart();
},
onPanResponderRelease: () => {
return this.props.onZoomEnd();
}
});
}
render() {
return (
<View
style={{ flex: 1, width: "100%" }}
{...this._panResponder.panHandlers}
>
{this.props.children}
</View>
);
}
}

// Implementation
class CameraView extends Component {
state = {
zoom: 0
};
render() {
return (
<ZoomView
onZoomProgress={progress => {
this.setState({ zoom: progress });
}}
onZoomStart={() => {
console.log("zoom start");
}}
onZoomEnd={() => {
console.log("zoom end");
}}
>
<RNCamera zoom={this.state.zoom} style={{ flex: 1 }} />
</ZoomView>
);
}
}

```

0 comments on commit 737a5a2

Please sign in to comment.