hhunaid / react-native-image-crop-tools

Native-ish Image Crop Tools for react native
171 stars 58 forks source link

`onImageCrop` is not returning anything in Android. #63

Open shahanshah87 opened 2 years ago

shahanshah87 commented 2 years ago

I am trying after copying the example code and it is working fine in iOS but not working in Android. I am using this to pick image.

`import React, { useState, useRef } from 'react'; import { Button, StatusBar, StyleSheet, View, Image } from 'react-native'; import { CropView } from 'react-native-image-crop-tools'; import { launchCamera, launchImageLibrary } from 'react-native-image-picker';

const App = () => { const [uri, setUri] = useState(); const cropViewRef = useRef(); return ( <>

        <View style={styles.container}>
            <View style={{ backgroundColor: "red" }}>
                <Button
                    title={'Pick Image'}
                    onPress={() => {
                        const options = {
                            mediaType: "photo"
                        }
                        launchImageLibrary(options, (response) => {
                            setUri(response.uri);
                        })
                    }}
                />
            </View>
            {uri !== undefined && <CropView
                sourceUrl={uri}
                style={styles.cropView}
                ref={cropViewRef}
                onImageCrop={(res) => alert(JSON.stringify(res))}
                keepAspectRatio
                aspectRatio={{ width: 16, height: 9 }}
            />}
            <View style={{ backgroundColor: "red4" }}>

                <Button
                    title={'Get Cropped View'}
                    onPress={() => {
                        cropViewRef.current.saveImage(90);
                    }}
                />
            </View>
        </View>
    </>
);

};

const styles = StyleSheet.create({ container: { flex: 1, marginTop: 40 }, cropView: { flex: 1, backgroundColor: 'red' }, });

export default App;`

geakk commented 2 years ago

got the same problem...

jonmajorc commented 2 years ago

Hey! When you usesaveImage make sure to pass both arguments saveImage(true, 90);