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

[Android] makeImageFromView does not respect scroll on Android #2171

Closed
PeKne opened this issue Jan 25, 2024 · 1 comment · Fixed by #2306
Closed

[Android] makeImageFromView does not respect scroll on Android #2171

PeKne opened this issue Jan 25, 2024 · 1 comment · Fixed by #2306
Labels
bug Something isn't working

Comments

@PeKne
Copy link

PeKne commented Jan 25, 2024

Description

I am trying to create a screen overlay that is displayed when the user puts the app in the background. The overlay should be a blurred screenshot of the current app screen layout. While everything works fine on iOS, I am encountering a problem on Android. The issue arises when the screen contains a ScrollView and I use makeImageFromView to capture a screenshot. On Android, it always captures the top of the ScrollView, even if it is scrolled.

Expected Behavior

makeImageFromView function should capture the currently visible part of the ScrollView on Android, similar to how it works on iOS.

Current Behavior

On Android, the captured screenshot always shows the top of the ScrollView, even if it is scrolled.

Version

0.1.236

Steps to reproduce

  1. Create an app with a ScrollView that contains a long content.
  2. Scroll down.
  3. Take screenshot with makeImageFromView.
  4. Check that the captured screenshot does not represent currently visible part of the screen.

Code example:

import { ScrollView, StyleSheet, View, Button } from 'react-native';
import { Canvas, makeImageFromView, SkImage, Image } from '@shopify/react-native-skia';


export default function App() {
  // Create a ref for the view you'd like to take a snapshot of
  const ref = useRef<View>(null);
  // Create a state variable to store the snapshot
  const [image, setImage] = useState<SkImage | null>(null);
  // Create a function to take the snapshot
  const onPress = async () => {
      // Take the snapshot of the view
      const snapshot = await makeImageFromView(ref);
      setImage(snapshot);
  };


  return (
    <>
      <ScrollView style={{ flex: 1 }} ref={ref}>
          <View>
              <View
                  style={{
                      backgroundColor: 'cyan',
                      flex: 1,
                      minHeight: 200,
                      borderWidth: 5,
                  }}
              />
              <View
                  style={{
                      backgroundColor: 'red',
                      flex: 1,
                      minHeight: 500,
                      borderWidth: 5,
                  }}
              />
              <View
                  style={{
                      backgroundColor: 'green',
                      flex: 1,
                      minHeight: 1000,
                      borderWidth: 5,
                  }}
              />
          </View>
      </ScrollView>
      <Button title="Take screenshot" onPress={onPress} />
      {image && (
          <Canvas style={StyleSheet.absoluteFill}>
              <Image
                  image={image}
                  x={0}
                  y={0}
                  width={image.width() / 2 / pd}
                  height={image.height() / 2 / pd}
              />
          </Canvas>
      )}
  </>
  );
}

Demo

Screen.Recording.2024-01-25.at.11.40.23.mov
@wcandillon
Copy link
Contributor

this is fixed :) and will ship this week
Thanks again @Nodonisko

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants