gre / react-native-view-shot

Snapshot a React Native view and save it to an image
https://github.com/gre/react-native-view-shot-example
MIT License
2.67k stars 346 forks source link

Background transparent not work! #293

Open juanm4 opened 4 years ago

juanm4 commented 4 years ago

Background transparent not work.

Version & Platform

 react-native@0.61.5 
 react-native-view-shot@3.1.2 

Platform: Android

Expected behavior

If ViewShot has a transparent background, it should get the background color/image on screenshot.

Actual behavior

Always shot an image with white background.

Steps to reproduce the behavior

If you try this code you can see that the background of image is white instead of gray. What is happening?

    <View style={{backgroundColor: 'gray', flex: 1}}>
            <Animated.View
                {...this.panResponder.panHandlers}
                style={[panStyle, styles.circle]}>
                <ViewShot ref="viewShot" options={{ format: 'png', result: 'base64' }} style={{backgroundColor: 'transparent', justifyContent: 'center', alignContent: 'center', alignItems: 'center'}}>
                    <Text>I</Text>
                </ViewShot>
            </Animated.View>
        </View>

The result of base64 images is that:

iVBORw0KGgoAAAANSUhEUgAAAPAAAABMCAYAAABTXTqcAAAABHNCSVQICAgIfAhkiAAAANBJREFUeJzt07ENwlAQBcHDRVEbfVGL64EGnGDZfK00I11y0Ut2BgAAAAAAAAAAAAAAAAAAAAAAANZ6rB7Abd4Hv9fM7P8eAvzuc3DPpYu43LZ6AHCegCFMwBAmYAgTMIQJGMIEDGEChjABQ5iAIUzAECZgCBMwhAkYwgQMYQKGMAFDmIAhTMAQJmAIEzCECRjCBAxhAoYwAUOYgCFMwBAmYAgTMIQJGMIEDGEChjABQ5iAIUzAECZgCBMwhAkYAAAAAAAAAAAAAAAAAAAAbvAFd+EHf8FsvtEAAAAASUVORK5CYII=

As you can see it must has a gray background, but it is white. What Am I doing wrong?

Thanks!

tarouboy commented 4 years ago

I am ok with format: "png", quality: 1, result: "base64".

dev-apps-code commented 3 years ago

did you happen to solve it? same issue

AdnanAshraf-gol commented 1 year ago

can we get both base64 and png?

Pietro-Putelli commented 1 year ago

Does someone solve the issue?

AdnanAshraf-gol commented 1 year ago

@Pietro-Putelli try giving background in the styles of viewshot wrapper

Pietro-Putelli commented 1 year ago

Here's an example of code, that doesn't work. https://snack.expo.dev/@pietroputelli/react-native-view-shot

RGkevin commented 1 year ago

same here, any update?

michal4511 commented 8 months ago

The same problem, any update?