react-native-masonry icon indicating copy to clipboard operation
react-native-masonry copied to clipboard

Invariant Violation [923, "RCTImageView" ... ] is not usable as a native method argument

Open abdul-elah-js opened this issue 6 years ago • 32 comments

Expected Behavior

To Render The Masonry Images

Current Behavior

Breaks Down

Context (Environment)

1- react v16.6.3 2- react-native v0.58.1 react-native-masonry v^0.5.0-alpha.3

All I want to do is to render a simple Masonry but i keep getting this error image

i pass the images array with additional data like this

[ { uri: 'image_url', description: 'txt' }, { uri: 'image_url', description: 'txt' } ]
<Masonry
     sorted
     columns={ 3 }
     bricks={ props.images }
/>

abdul-elah-js avatar Feb 01 '19 20:02 abdul-elah-js

I have same problem! >.<

thang-nm avatar Feb 02 '19 03:02 thang-nm

are you using the same version of react-native ? 0.58.1 ? @Lang-le

abdul-elah-js avatar Feb 02 '19 10:02 abdul-elah-js

@abdul-elah-js I use React Native 0.58.3.

thang-nm avatar Feb 02 '19 10:02 thang-nm

could it be because of the whole .58 version ? i read the changelog but i don't remember finding anything relevant about the RCTImageView 🤔, anyhow i'll try it with 0.57 version just to be sure, if you figured it out, help me out

abdul-elah-js avatar Feb 02 '19 10:02 abdul-elah-js

@abdul-elah-js I suspect the error has to do with the fact that your application is probably having issues getting that image as it's deriving NaN in it's resizing calculations -- it's supposed to log it if it receives a 400/404, so there maybe a bug there.

You might see some logs in the console, or I would try directly creating an image element with that URL and see if there are any issues with it.

brh55 avatar Feb 04 '19 19:02 brh55

@brh55 Yeah. So do i. But use Google logo at Google.com, so it can't be 400/404 (etc..) Images show for the first time and i reload simulator (Command + R), then i got that error!

thang-nm avatar Feb 05 '19 03:02 thang-nm

@abdul-elah-js I created my own masonry layout base on FlatList and height of the image. If you already know image size, you can make your own layout. I think it's better than automatic calculation!

thang-nm avatar Feb 05 '19 03:02 thang-nm

@brh55 I tried giving the image a height, width and resizeMode but still i got the same error without any logs, the weirdest thing though is this error is only triggered after running perfectly for the first time !,

abdul-elah-js avatar Feb 05 '19 10:02 abdul-elah-js

@Lang-le I did the same 👍🏽

abdul-elah-js avatar Feb 05 '19 10:02 abdul-elah-js

Help me I also facing the same error.

    "react": "16.6.3",
    "react-native": "0.58.6",

EdisonDevadoss avatar Mar 01 '19 10:03 EdisonDevadoss

I have same problem! The images success to display at the first time, but It show errors the next time

"react": "16.8.3",
"react-native": "0.59.1",

mingxin-yang avatar Mar 22 '19 09:03 mingxin-yang

Is this android or iOS? @mingxin-yang

brh55 avatar Mar 22 '19 15:03 brh55

android @brh55

mingxin-yang avatar Mar 22 '19 16:03 mingxin-yang

this is solved? i got same error

bamaarintoko avatar Mar 27 '19 08:03 bamaarintoko

Update, error stems from the fact that onLayout in the view doesn't get triggered within Android in some newer versions of React-Native.

Clearly, this is an important basis for calculating appropriate image resizing, hence the NaN. Messing around with potential workarounds for the time being.

brh55 avatar Apr 26 '19 06:04 brh55

Facing the same issue. It has to be something with cache. Coz I am not getting the error on first run or after I clear the cache. Could this be because local images (cached, that become local once cached) need height and width to be passed as props or there's no such thing?

hack-and-backslash avatar May 02 '19 13:05 hack-and-backslash

Facing the same issue. It has to be something with cache. Coz I am not getting the error on first run or after I clear the cache. Could this be because local images (cached, that become local once cached) need height and width to be passed as props or there's no such thing?

I added width and height to my brick object and it seems to have fixed the issue for me.

hack-and-backslash avatar May 02 '19 13:05 hack-and-backslash

@hack-and-backslash Issue comes from the fact onLayout (which is used to get parent dimensions of the layout) for Android is triggered after the masonry layout attempts to render. I've been trying to fix it so that an empty layout is rendered initially until onLayout can provide some details and then render again, but it still doesn't like that.

Adding height and brick will work in theory, but we really don't want users to be doing that as it will result in potential funky behavior :3.

brh55 avatar May 02 '19 20:05 brh55

still same error

"react-native-masonry": "^0.5.0-alpha.4", "react-native": "0.59.5",

How can I add width and height to the brick data?

dragonStandard123 avatar May 03 '19 08:05 dragonStandard123

still same error

"react-native-masonry": "^0.5.0-alpha.4", "react-native": "0.59.5",

How can I add width and height to the brick data?

Just like you add other stuff like uri, onPress etc.

uri: 'http://pic.com/3424343.jpg', width: 1080, height: 1920, onPress: () => {}

But again, as @brh55 says, it might result in potential funky behavior. I haven't found anything funny yet though.

hack-and-backslash avatar May 03 '19 14:05 hack-and-backslash

The odd behavior is the first "brick" will render with incorrect resize dimension, but it should promptly fix itself with the correct dimensions on the second re-render. Ironically, this might be a hotfix solution by giving the parent default dimensions.

brh55 avatar May 04 '19 01:05 brh55

Yeah thought that may have worked, but causing this odd behavior: test

brh55 avatar May 06 '19 02:05 brh55

I tried severally, but failed.

-If I use the normal image views, the red screen is shown as followed

uri: 'http://192.168.43.236:8088/assets/img/imageUpload/1532657517567.JPEG',
width: 1080, 
height: 1920, 
onPress: () => {}

Uploading Untitled1.png…

-When I use the FastImages, the result.... Only first time, it shows 'normally', but on next reload, the red screen is appeared.

          uri: 'http://192.168.43.236:8088/assets/img/imageUpload/1532657517567.JPEG'
          
          <Masonry
                        sorted
                        bricks={this.state.data}
                        customImageComponent={FastImage}
                        // customImageProps={{width:300, height:500,}}
                    />

Untitled

How can I handle masonry?

dragonStandard123 avatar May 06 '19 14:05 dragonStandard123

same error

"react": "16.6.3", "react-native": "0.58.4",

pmella16 avatar May 23 '19 00:05 pmella16

give the node_modules\react-native-masonry\components\Masonry.js 's dimentsions a default value like this: this.state = { dataSource: this.ds.cloneWithRows([]), dimensions: { width: Dimensions.get('window').width, height: 0, gutter: Dimensions.get('window').width / 100 * this.props.spacing }, initialOrientation: true, _sortedData: [], _resolvedData: [], _columnHeights: columnHeights, _uniqueCount: props.bricks.length }; In general, you only need 'width' whitch almost is the window`s width. 'gutter ' you can give what ever you want

and edit node_modules\react-native-masonry\components\Column.js line:64 let { height, width } = parentDimensions;

this works for me

hejun041 avatar May 29 '19 03:05 hejun041

@brh55 Did you try what @hejun041 said. Can this be a potential fix?

hack-and-backslash avatar May 30 '19 09:05 hack-and-backslash

give the node_modules\react-native-masonry\components\Masonry.js 's dimentsions a default value like this: this.state = { dataSource: this.ds.cloneWithRows([]), dimensions: { width: Dimensions.get('window').width, height: 0, gutter: Dimensions.get('window').width / 100 * this.props.spacing }, initialOrientation: true, _sortedData: [], _resolvedData: [], _columnHeights: columnHeights, _uniqueCount: props.bricks.length }; In general, you only need 'width' whitch almost is the window`s width. 'gutter ' you can give what ever you want

and edit node_modules\react-native-masonry\components\Column.js line:64 let { height, width } = parentDimensions;

this works for me

This works for me

traxx10 avatar Jun 02 '19 08:06 traxx10

@brh55 Did you try what @hejun041 said. Can this be a potential fix?

This does work as long as the parent element has no padding around your Masonry. I'll take this as PR fix if anyone wants to submit.

I've been struggling to come up with a clean fix to support the masonry being placed anywhere since the changes to onLoad.

I appreciate all the eyes and support on this! 💃

brh55 avatar Jun 03 '19 17:06 brh55

Same here (RN by expo sdk33 : 0.59.8 , react 16.8.3), if you can send width/height in bricks it passes the first time...

lc3t35 avatar Jul 07 '19 13:07 lc3t35

In my case, I had an error : "RCTView", in this line: <View style={{alignItems: 'center', position:'relative', left: (window.width/2), top:50, flexDirection: 'column'}}> in my file. I deleted "left: (window.width/2)" and it works I use react-native: 0.60.5 react:16.8.6 react-native-cli: 2.0.1

erick4556 avatar Aug 30 '19 16:08 erick4556