Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In android it does nothing and not showing any error logs. Works fine in iOS #529

Open
kuldipopenxcell opened this issue May 2, 2024 · 4 comments

Comments

@kuldipopenxcell
Copy link

bug report

In react native latest version (0.73.6) snapshot is not capturing in Android device. It works fine in IOS.

Version & Platform

npm ls react-native react-native-view-shot #
├─┬ @react-native-async-storage/async-storage@1.23.1
│ └── react-native@0.73.6 deduped
├─┬ @react-native-google-signin/google-signin@11.0.1
│ └── react-native@0.73.6 deduped
├─┬ @react-navigation/bottom-tabs@6.5.20
│ ├─┬ @react-navigation/elements@1.3.30
│ │ └── react-native@0.73.6 deduped
│ └── react-native@0.73.6 deduped
├─┬ @react-navigation/native-stack@6.9.26
│ └── react-native@0.73.6 deduped
├─┬ @react-navigation/native@6.1.17
│ └── react-native@0.73.6 deduped
├─┬ agora-react-native-rtm@1.5.1
│ └── react-native@0.73.6 deduped
├─┬ agora-rn-uikit@5.0.2
│ └── react-native@0.73.6 deduped
├─┬ react-native-agora@4.3.0-build.1 invalid: "^4.1.0" from node_modules/agora-rn-uikit
│ └── react-native@0.73.6 deduped
├─┬ react-native-element-dropdown@2.10.4
│ └── react-native@0.73.6 deduped
├─┬ react-native-fbsdk-next@12.1.4
│ └── react-native@0.73.6 deduped
├─┬ react-native-image-picker@7.1.2
│ └── react-native@0.73.6 deduped
├─┬ react-native-iphone-x-helper@1.3.1
│ └── react-native@0.73.6 deduped
├─┬ react-native-keyboard-aware-scroll-view@0.9.5
│ └── react-native@0.73.6 deduped
├─┬ react-native-linear-gradient@3.0.0-alpha.1
│ └── react-native@0.73.6 deduped
├─┬ react-native-maps@1.14.0
│ └── react-native@0.73.6 deduped
├─┬ react-native-modal-datetime-picker@17.1.0
│ └── react-native@0.73.6 deduped
├─┬ react-native-modal@13.0.1
│ └── react-native@0.73.6 deduped
├─┬ react-native-responsive-screen@1.4.2
│ └── react-native@0.73.6 deduped
├─┬ react-native-safe-area-context@4.9.0
│ └── react-native@0.73.6 deduped
├─┬ react-native-screens@3.30.1
│ └── react-native@0.73.6 deduped
├─┬ react-native-simple-toast@3.3.1
│ └── react-native@0.73.6 deduped
├─┬ react-native-splash-screen@3.3.0
│ └── react-native@0.73.6 deduped
├─┬ react-native-view-shot@3.8.0
│ └── react-native@0.73.6 deduped
├─┬ react-native@0.73.6
│ └─┬ @react-native/virtualized-lists@0.73.4
│   └── react-native@0.73.6 deduped
├─┬ react-redux@9.1.0
│ └── react-native@0.73.6 deduped
└─┬ toggle-switch-react-native@3.3.0
  └── react-native@0.73.6 deduped

Platform: Android

Expected behavior

It should return with URI of the image

Actual behavior

It returns nothing

Sample Code


const MapPage = () => {
  const mapRef = useRef();
  const viewRef = useRef();
  const captureMap = async () => {
    try {
      // Capture map as image
      const uri = await viewRef.current.capture();
      console.log('uri', uri);
    } catch (error) {
      console.error('Error:', error);
      Alert.alert('Error', 'Failed to save PDF.');
    }
  };
  
  return(
    <View style={styles.container}>
          <ViewShot ref={viewRef} style={{flex: 1}}>
            <MapView
              ref={mapRef}
              style={{flex: 1}}
              scrollEnabled={false}
              provider={PROVIDER_GOOGLE}
              initialRegion={{
                latitude: 55.8622166,
                longitude: 12.388021,
                latitudeDelta: 0.0922,
                longitudeDelta: 0.0421,
              }}
              onTouchStart={handleTouchStart}
              onPanDrag={handlePanDrag}
              onTouchEnd={handleTouchEnd}>
              {lines.map((line, index) => (
                <Polyline
                  key={index}
                  coordinates={line}
                  strokeColor="#FF0000"
                  strokeWidth={3}
                />
              ))}
            </MapView>
          </ViewShot>
          <Button label="Capture screenshot" onPress={captureMap} />
        </View>
    )
}

@devethan
Copy link

devethan commented May 2, 2024

In my case, always stuck in these code only in Android

      const uri = await viewRef.current.capture();

there's no error, just still going on. But iOS is working fine.

@kuldipopenxcell
Copy link
Author

I tried with this code also but there is no error logs and no clue to fix this.

  const captureSnapshot = async () => {
    try {
      const uri = await captureRef(viewRef, {
        format: 'png', // You can change the format if needed
        quality: 1, // Quality of the image, from 0 to 1
      });

      // Do something with the captured image URI (e.g., save it to disk or display it)
      console.log('Snapshot URI:', uri);
    } catch (error) {
      console.error('Error capturing snapshot:', error);
    }
  };

@adaerodriguez
Copy link

Hi guys, any advance with this issue? I have the same problem with react-native 0.73.6, on ios works great, but with Android, nothing happens

Thanks!!

@kuldipopenxcell
Copy link
Author

Hi guys, I have found the alternative for this. since this is not working well for Android.
Here you can use React Native Skia: Snapshot Views | React Native

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants