Shopify / Shopify/react-native-skia

makeImageFromView doesn’t work properly on Android when the status bar is translucent

Open
#2,773 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
8.6k
Forks
647
Avg merge
1d 17h
Merged PRs (30d)
35

Description

I need to take a screenshot of the whole screen. The screen includes a header from React Navigation. When I take a screenshot using makeImageFromView, it pushes the header down.

Deps:
"@react-navigation/elements": "^2.1.5",
"@react-navigation/native": "^7.0.6",
"@react-navigation/native-stack": "^7.1.7",
"@shopify/react-native-skia": "^1.5.10",
"react-native": "0.76.3",

Representation on the emulator Screenshot
Image Image

App.tsx

import React, {useRef} from 'react';

import {Navigation} from './navigation';
import {Pressable, StatusBar, Text, View} from 'react-native';
import {ImageFormat, makeImageFromView} from '@shopify/react-native-skia';

const base64Start = 'data:image/png;base64,';

export const App = () => {
  const viewRef = useRef<View>(null);

  const onPress = async () => {
    try {
      const res = await makeImageFromView(viewRef);
      console.log(res, 'RES');
      if (res) {
        const resBase = base64Start + res.encodeToBase64(ImageFormat.PNG, 100);

        console.log({resBase}, 'RES');
      }
    } catch (error) {
      console.log(error, 'ERROR');
    }
  };

  return (
    <View ref={viewRef} style={{flex: 1}} collapsable={false}>
      <StatusBar
        translucent
        backgroundColor={'transparent'}
        barStyle={'dark-content'}
      />
      <Navigation />
      <Pressable
        style={{
          position: 'absolute',
          top: 100,
          right: 16,
          backgroundColor: 'lightblue',
          paddingHorizontal: 16,
          paddingVertical: 8,
          borderRadius: 8,
        }}
        onPressIn={onPress}>
        <Text>Shot</Text>
      </Pressable>
    </View>
  );
};

navigation.ts

import {createStaticNavigation} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {FirstScreen} from './FirstScreen';

const RootStack = createNativeStackNavigator({
  screens: {
    FirstScreen: FirstScreen,
  },
});

export const Navigation = createStaticNavigation(RootStack);

FirstScreen.tsx

import React, {FC} from 'react';
import {View} from 'react-native';

export const FirstScreen: FC = () => {
  return (
    <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}} />
  );
};

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the App.tsx reproduction and the makeImageFromView entry point, focusing on the translucent Android StatusBar and the React Navigation header. Reproduce the screenshot behavior, then verify that capturing the whole screen no longer pushes the header down while preserving the existing layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, react-native, typescript
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.