Would anyone be able to please assist in converting this class component code to a functional component/hooks
class MarkerTypes extends React.Component {
constructor(props) {
super(props);
this.state = {
mapSnapshot: null,
};
}
takeSnapshot() {
this.map.takeSnapshot(
300,
300,
{
latitude: LATITUDE - SPACE,
longitude: LONGITUDE - SPACE,
latitudeDelta: 0.01,
longitudeDelta: 0.01 * ASPECT_RATIO,
},
(err, data) => {
if (err) {
console.log(err);
}
this.setState({ mapSnapshot: data });
}
);
}
render() {
return (
<View>
<MapView initialRegion={...} ref={map => { this.map = map }}>
<Marker coordinate={this.state.coordinate} />
</MapView>
<Image source={{ uri: this.state.mapSnapshot.uri }} />
<TouchableOpacity onPress={this.takeSnapshot}>
Take Snapshot
</TouchableOpacity>
</View>
);
}
Something like this: I want to tap on a button to take the snapshot
https://github.com/react-native-community/react-native-maps#take-snapshot-of-map
const snapShot = () => {
takeSnapshot({
width: 300, // optional, when omitted the view-width is used
height: 300, // optional, when omitted the view-height is used
format: "png", // image formats: 'png', 'jpg' (default: 'png')
quality: 0.8, // image quality: 0..1 (only relevant for jpg, default: 1)
result: "file", // result types: 'file', 'base64' (default: 'file')
});
snapshot.then((uri) => {
console.log(uri);
});
};
return(
<TouchableOpacity onPress={snapShot}>
<AppText>Get snapshot</AppText>
</TouchableOpacity>
)