react-native-view-shot icon indicating copy to clipboard operation
react-native-view-shot copied to clipboard

I cannot capture a screenshot of other objects I put on the camera object.

Open aytacabay opened this issue 6 years ago • 6 comments

Question

I have a question ?

  • When the camera is on, I place another object on it. I give the object's style property position: 'absolute'. Then when I take a screenshot, the object is not visible.
  • But when I cancel the camera object and use position: 'absolute' with another object, the screenshot captures it.

How can I solve this problem?

I am making software as a hobby. Sorry if this is logically wrong. How do you think I should do this ?

aytacabay avatar Oct 27 '20 22:10 aytacabay

import React, { useRef, useCallback, useState, useEffect } from 'react'; import { View, Text, TouchableOpacity, Image, ScrollView } from 'react-native';

import { RNCamera } from 'react-native-camera'; import ViewShot from 'react-native-view-shot'; import Draggable from 'react-native-draggable';

export default function CameraFuncScreenShot() {

const [base64ScreenShot, setbase64ScreenShot] = useState(null) const [cameraIsOpen, setCameraIsOpen] = useState(true);

let viewRef = useRef();

let takeAPicture = async () => { if (cameraIsOpen) { await viewRef.current.capture().then(base64 => { setbase64ScreenShot(base64) }) } await setCameraIsOpen(false) } useEffect(() => { }, [cameraIsOpen])

return ( <ViewShot ref={viewRef} options={{ format: 'jpg', quality: 0.9, result: 'base64' }} style={{ width: '100%', height: '100%', flexDirection: 'column', justifyContent: 'flex-start', alignItems: 'center' }} > <Draggable imageSource={require('../assets/imgIcons/1.png')} renderSize={80} x={200} y={300} /> { cameraIsOpen ? <RNCamera options={{ format: 'jpg', quality: 0.9, result: 'base64' }} style={{ width: '100%', height: '100%', flexDirection: 'column', justifyContent: 'flex-end', alignItems: 'center', backgroundColor: 'red', }} type={RNCamera.Constants.Type.back} flashMode={RNCamera.Constants.FlashMode.on} zoom={0} maxZoom={0} androidCameraPermissionOptions={{ title: 'Permission to use camera', message: 'We need your permission to use your camera', buttonPositive: 'Ok', buttonNegative: 'Cancel', }} androidRecordAudioPermissionOptions={{ title: 'Permission to use audio recording', message: 'We need your permission to use your audio', buttonPositive: 'Ok', buttonNegative: 'Cancel', }} > { ({ camera, status, recordAudioPermissionStatus }) => { if (status !== 'READY') { return ( <View style={{ width: '100%', height: '100%', backgroundColor: 'lightgreen', justifyContent: 'center', alignItems: 'center', }} > Waiting ) } else {

                            return (
                                <View style={{ width: '100%', height: '30%', backgroundColor: 'pink' }}>
                                    <View style={{ width: '100%', height: '30%' }}>
                                        <TouchableOpacity style={{ width: 65, alignSelf: 'center', }} onPress={() => { takeAPicture() }}>
                                            <Image style={{ width: 65, height: '100%' }} source={require('../assets/img/dot-2.png')} />
                                        </TouchableOpacity>
                                    </View>

                                    <View style={{ width: '100%', height: '70%', flexDirection: 'column', justifyContent: 'center', }}>

                                        <View style={{ width: '100%', height: '50%', backgroundColor: 'tomato' }}>
                                            <TouchableOpacity>
                                                <Text style={{ color: 'whitesmoke' }}>Icons</Text>
                                            </TouchableOpacity>
                                        </View>

                                        <View style={{ width: '100%', height: '50%' }}>
                                            <TouchableOpacity>
                                                <Text style={{ color: 'whitesmoke' }}>FaceDetaction</Text>
                                            </TouchableOpacity>
                                        </View>
                                    </View>
                                </View>
                            )

                        }

                    }
                }
            </RNCamera>
            :
            base64ScreenShot
                ?
                <View style={{ width: '100%', height: '100%', flexDirection: 'column', justifyContent: 'center', position: 'relative' }}>

                    <Image style={{ width: '100%', height: '100%', backgroundColor: '#EBE8E7' }} source={{ uri: `data:image/jpg;base64,${base64ScreenShot}` }} />

                    <View style={{ width: '100%', position: 'absolute', bottom: 10, flexDirection: 'row', justifyContent: 'space-around' }}>
                        <TouchableOpacity style={{ width: 40, justifyContent: 'center', }} onPress={() => { setTimeout(() => { setCameraIsOpen(true) }, 1000) }}>
                            <Image style={{ width: 40, height: 40 }} source={require('../assets/img/cancel.png')} />
                        </TouchableOpacity>
                        <TouchableOpacity style={{ width: 40, alignSelf: 'center', }} onPress={async () => { console.log('Resim okeylendi..') }}>
                            <Image style={{ width: 40, height: 40 }} source={require('../assets/img/check.png')} />
                        </TouchableOpacity>
                    </View>


                </View>
                :
                <></>
    }
</ViewShot >

) }

aytacabay avatar Oct 28 '20 00:10 aytacabay

same with react-native-maps. any progress?

serbanstef avatar Nov 26 '20 20:11 serbanstef

The main readme have a support table to explain what is technically possible and what is not. There is likely no chance we can fix something in this library if some frame don't allow to get pixels from. For camera I would recommend to look at possible ways offer by camera lib themselves to get an image.

For reactnativemap a workaround is also mentioned in the main readme

gre avatar Nov 27 '20 06:11 gre

@aytacabay did you found any solution or other library. I am also trying to do something like this, but when a screen-shot is taken it only shows the camera image and the nested/overlayed images is not displayed.

mobeendev avatar Mar 03 '21 11:03 mobeendev

@aytacabay did you found any solution or other library.

I am also trying to do something like this, but when a screen-shot is taken it only shows the camera image and the nested/overlayed images is not displayed.

unfortunately no.

aytacabay avatar Mar 03 '21 14:03 aytacabay

@aytacabay did you found any solution or other library. I am also trying to do something like this, but when a screen-shot is taken it only shows the camera image and the nested/overlayed images is not displayed.

In case anyone in the future stumbles upon something like this - this might help. So I had the same issue where I had an overlaying component (position: 'absolute') that did not get included in the screenshot. I basically wrapped the component in a view with style={{ flex:1 }} and it started working.

impu1 avatar Aug 11 '22 01:08 impu1