react-native-code-push icon indicating copy to clipboard operation
react-native-code-push copied to clipboard

Images not rendering properly on ios after code-push with resizeMode center

Open Ashwin-Mothilal opened this issue 8 years ago • 41 comments

Steps to Reproduce

  1. React Native Image Component local image which matches resizeMode center
  2. Install the app from Xcode Production version
  3. Change the tintColor of the image or change text if you have
  4. Release using "code-push release-react ios "

Expected Behavior

Images should render properly as it is in dev version debug mode

Actual Behavior

Images with resizeMode "center" gets resizeMode "cover". I am mentioning "cover" because it matches with it in dev mode.

SCREENSHOTS

After CodePush to Production App - 1 Improper images

After CodePush to Production App - 1 Some proper images - Images representing Views, Comments, Attachments are looking good.

Expected / Debug Build

Environment

  • react-native-code-push version: 5.2.1
  • react-native version: 0.52.0
  • iOS/Android/Windows version: iOS version 11.2.6
  • Does this reproduce on a debug build or release build? Release

###Notes The App uses this tabbar component in React Navigation For the topbar it uses StackNavigator.

Ashwin-Mothilal avatar Mar 01 '18 15:03 Ashwin-Mothilal

I notice this for resizeMode: "stretch" too. We are using stretch together with capInsets for some shadow assets (on semi transparent views) and it makes the shadow look completely wrong.

adbl avatar Mar 12 '18 09:03 adbl

Aha, actually I see now that resizeMode: "stretch" is respected but it seems like the capInsets are just gone (which makes the shadow look wrong). Maybe a separate issue.

adbl avatar Mar 12 '18 10:03 adbl

+1

syq7970 avatar Mar 15 '18 09:03 syq7970

Hey there!

We haven't forgotten about this issue. We have been doing some internal changes on the way we're executing github support. Are you still having this problem?

Zakeelm avatar Mar 26 '18 21:03 Zakeelm

Hello, the case I mentioned above: yes! On Mon, 26 Mar 2018 at 23:02, Zakeel M. [email protected] wrote:

Hey there!

We haven't forgotten about this issue. We have been doing some internal changes on the way we're executing github support. Are you still having this problem?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/react-native-code-push/issues/1222#issuecomment-376310545, or mute the thread https://github.com/notifications/unsubscribe-auth/AAK22O5xkrsM_c4RwbZgzo4B7BIb_8qWks5tiVdjgaJpZM4SYeGg .

adbl avatar Mar 27 '18 05:03 adbl

Hi guys, Unfortunately I can't reproduce you issue. There is my App.js:

import React, { Component } from 'react';
import { StyleSheet, Text, View, TouchableOpacity, Image } from 'react-native';
import codePush from "react-native-code-push";

class App extends React.Component {
  render() {
    return (
      <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
        <Image
          style={{width: 100, height: 100, margin: 20}}
          source={require('./1.png')}
          resizeMode='cover'
          tintColor='#ff00ff'
        />
        <Image
          style={{width: 100, height: 100, margin: 20}}
          source={require('./1.png')}
          resizeMode='center'
          tintColor='#ff00ff'
        />
        <Image
          style={{width: 100, height: 100, margin: 20}}
          source={require('./1.png')}
          resizeMode='stretch'
          tintColor='#ff00ff'
          capInsets={{left: 15, right: 15, bottom: 15, top: 15}}
        />
        <TouchableOpacity
          style = {{height: 70, width: 200, backgroundColor: 'green'}}
          onPress={() => {
             codePush.sync({
                  updateDialog: true,
                  installMode: codePush.InstallMode.IMMEDIATE
              });
          }}>
        <Text>Current version: 15</Text> 
      </TouchableOpacity>
      </View>
    )
  }
}

let codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };
export default App = codePush(codePushOptions)(App);

After codepush release was installed all looks the same as in a binary version:

Would be great if you can create little project which I can use to reproduce

Thanks!

itoys avatar Mar 28 '18 15:03 itoys

@iTOYS Thanks for the reply. In the case I described above (using a drop shadow image), we use absolute position and unset the width/height like this:

  shadow: {
    position: "absolute",
    top: -18,
    left: -20,
    bottom: -22,
    right: -20,
    width: undefined,
    height: undefined,
  },

with capInsets:

{
  top: 22,
  left: 24,
  bottom: 26,
  right: 24,
}

This is probably relevant to the issue, especially unsetting width/height, I should have mentioned it before.

adbl avatar Mar 28 '18 18:03 adbl

Sorry guys, I doesn't see difference between binary version and codepush. Example project would be helpful!

itoys avatar Mar 29 '18 12:03 itoys

Sorry, was busy in other projects. I am still facing this issue. @iTOYS It's not possible for me to create a example project for some days. The only difference I see in Code push code is, I am not doing it manually, its done by Default option which is OnAppResume I think. I have updated the screenshots and text also, feel free to ask questions!

Ashwin-Mothilal avatar Apr 02 '18 08:04 Ashwin-Mothilal

Hi @Ashwin-Mothilal I don't have access to new images. CodePush options which i use don't have any affects to styles. I'm waiting project from you :)

Thanks!

itoys avatar Apr 02 '18 08:04 itoys

I have changed the permissions for the images, you can check it now. Just have a look at it. I will try to give project after this week, working on other production issues.

Ashwin-Mothilal avatar Apr 02 '18 09:04 Ashwin-Mothilal

Noticing this as well. Changing to resizeMode={'contain'} seems to fix it. Most of these were absolutely positioned images. Maybe some data stripped from assets in the bundling/distribution process?

tomauty avatar Apr 05 '18 02:04 tomauty

CodePush and plugins doesn't change your code and assets. Could you please download your bundle and compare props values?

https://codepush.azurewebsites.net/updateCheck?deploymentKey=[your-key]&appVersion=[app-version]

itoys avatar Apr 05 '18 13:04 itoys

Closing this issue for now! I recommend you to wrap all your props values with {}

Thanks!

itoys avatar Apr 25 '18 10:04 itoys

Hi, I am attaching the sample project for you here

Please find the image after code push Update img_0054

Ashwin-Mothilal avatar Apr 26 '18 11:04 Ashwin-Mothilal

What if we are not using it as props but using it within the Image style object? Same problem? Also would it not make sense to have the code-push build mimic the behaviour of a normal production build? Production builds work and look just fine with no errors whatsoever.

stueynet avatar May 03 '18 17:05 stueynet

Same here. I have two separate issueses.

First is a background image for a chat. It had transparency (by mistake) and for some reason it was resized incorrectly. It was zoomed and very low res. iOS had this bug, but android works well.

Second case is a simple png images with capInsets. It looks like it just ignores cap insets at all.

UPD: I actually tried to dig deeper to investigate problem with capInsets and found that in binary build image is not resized before applying capInsets (as it should be), but in codepush version RCTImageView resizes an image for some reason.

UPD2: Ah, i found the source of issue. Image was loaded without respect to screen dencity (x3 on iPhone X) when is loaded from codepush. Loading from local bundle works just fine. Still trying to figure out work-around...

ex3ndr avatar Aug 19 '18 07:08 ex3ndr

Ok, i figured out the root cause of the issue. When loading images from CodePush bundle it doesn't respect scale factor of the resource. It works well for built-in resources since UIImage can load with right scale factor automatically.

Unfortunately, the only (and dirty) solution is to patch react-native implementation.

In react-native/React/Base/RTCUtils.m patch RCTImageFromLocalAssetURL:

image = [UIImage imageWithData:fileData];

with

CGFloat scale = 1.0;
if ([[imageURL absoluteString] hasSuffix: @"@3x.png"]) {
  scale = 3.0;
} else if ([[imageURL absoluteString] hasSuffix: @"@2x.png"]) {
  scale = 2.0;
}
image = [UIImage imageWithData:fileData scale: scale];

This will work only for png files.

ex3ndr avatar Aug 19 '18 10:08 ex3ndr

@itoys should we open this back up?

stueynet avatar Aug 19 '18 11:08 stueynet

For sure it should be opened back. Also after digging around image loading it turns out that there are no image caching at all for built-in images on iOS. For example, if app will show series of messages with bubble decorations then build with codepush will load each image again and again. That's really creepy for performance.

ex3ndr avatar Aug 19 '18 17:08 ex3ndr