Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.56k stars 2.9k forks source link

iOS Chat - Downloaded share code is blank #49868

Closed lanitochka17 closed 1 month ago

lanitochka17 commented 1 month ago

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.41-1 Reproducible in staging?: Y Reproducible in production?: N/A unable to check If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Issue reported by: Applause - Internal Team

Action Performed:

  1. Launch New Expensify app
  2. Open workspace chat
  3. Tap on the chat header
  4. Tap Share
  5. Tap Download
  6. Download the share code
  7. View the downloaded code on device gallery

Expected Result:

The downloaded share code is not blank

Actual Result:

The downloaded share code is blank

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/user-attachments/assets/20ef42f6-94b7-461b-ba6c-4b98204c622a

View all open jobs on GitHub

melvin-bot[bot] commented 1 month ago

Triggered auto assignment to @thienlnam (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

github-actions[bot] commented 1 month ago

:wave: Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.
Nodebrute commented 1 month ago

I am on latest main. I am unable to reproduce this issue

Screenshot 2024-09-28 at 2 38 29 AM
bernhardoj commented 1 month ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Downloaded QR Code is blank in iOS.

What is the root cause of that problem?

This happened after we upgraded the react-native-view-shot in https://github.com/Expensify/App/pull/49595. The upstream issue started in version 4.0.0-alpha.2. Someone reported the issue upstream here too.

After knowing the issue is from the react-native-view-shot, now we need to understand what is the issue there. The issue happens after this upstream PR which replaces the iOS deprecated function.

Previously, it used UIGraphicsBeginImageContextWithOptions and UIGraphicsGetImageFromCurrentImageContext and "draw" the image between the active context:

UIGraphicsBeginImageContextWithOptions(size, NO, 0);

if (renderInContext) {
  [rendered.layer renderInContext: UIGraphicsGetCurrentContext()];
  success = YES;
}
else {
  success = [rendered drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

But now, it looks like this:

UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];

if (renderInContext) {
  [rendered.layer renderInContext: UIGraphicsGetCurrentContext()];
  success = YES;
}
else {
  success = [rendered drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
}

UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {}];

A renderer is created and the context is now available from the imageWithActions. So, the "drawing" between them does nothing.

What changes do you think we should make in order to solve the problem?

There is a solution here but it's incomplete since it doesn't respect the renderInContext params and always use renderInContext.

So, to solve this, we need to move the rendering/"drawing" inside imageWithActions.

UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
  if (renderInContext) {
    [rendered.layer renderInContext: rendererContext.CGContext];
    success = YES;
  }
  else {
    success = [rendered drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
  }
}];

The context now is coming from rendererContext.

Last, we need to update this success variable with a __block modifier, so it's updatable from the imageWithActions block.

__block BOOL success;
s77rt commented 1 month ago

If we don't have to stick with react-native-view-shot we can use @s77rt/react-native-viewshot which provides a similar API and it seems to line up with @bernhardoj's proposed solution

roryabraham commented 1 month ago

@lakchote wdyt? Should we just revert https://github.com/Expensify/App/pull/49595?

lakchote commented 1 month ago

@lakchote wdyt? Should we just revert #49595?

Yes, we should just revert and wait for the library to offer a new stable version. Once that's done, we'll reconsider adding it.

thienlnam commented 1 month ago

This has been CPEd