Calculating height of item
See original GitHub issueThis is probably related to #70;
I still have an issue with calculating heights of my items using data,
I used this approach where I tried to use getDataForIndex
but nothing rendered on the screen:
this._layoutProvider = new LayoutProvider(
index => {
return "DEFAULT";
},
(type, dim, index) => {
const item = this._dataProvider.getDataForIndex(index);
if (item.media) {
if (item.media.length > 0) {
if (item.media.length === 1) {
dim.width = TabletWidth;
dim.height = 106 + (TabletWidth * (item.media.height / item.media.width));
} else if (item.media.length === 2) {
dim.width = TabletWidth;
dim.height = 106 + (((TabletWidth - 20) / 2) + 8);
} else if (item.media.length === 3) {
dim.width = TabletWidth;
dim.height = 106 + (((TabletWidth - 20) / 2) + (TabletWidth / 2.2) + 8);
} else {
dim.width = TabletWidth;
dim.height = 106 + ((((TabletWidth - 20) / 2) + 8) * 2);
}
}
}
});
then I used this approach and it didn’t work like before:
this._layoutProvider = new LayoutProvider(
index => {
return "DEFAULT";
},
(type, dim, item) => {
if (item.media) {
if (item.media.length > 0) {
if (item.media.length === 1) {
dim.width = TabletWidth;
dim.height = 106 + (TabletWidth * (item.media.height / item.media.width));
}
else if (item.media.length === 2) {
dim.width = TabletWidth;
dim.height = 106 + (((TabletWidth - 20) / 2) + 8);
}
else if (item.media.length === 3) {
dim.width = TabletWidth;
dim.height = 106 + (((TabletWidth - 20) / 2) + (TabletWidth / 2.2) + 8);
}
else {
dim.width = TabletWidth;
dim.height = 106 + ((((TabletWidth - 20) / 2) + 8) * 2);
}
}
}
});
I also tested this:
this._layoutProvider = new LayoutProvider(()=>{return "DEFAULT"}, (data, dim)=>{
dim.width = TabletWidth;
dim.height = 106 + (
data.media ?
data.media.length > 0 ?
data.media.length === 1 ?
TabletWidth * (data.media.height / data.media.width)
: data.media.length === 2 ?
((TabletWidth - 20) / 2) + 8
: data.media.length === 3 ?
((TabletWidth - 20) / 2) + (TabletWidth / 2.2) + 8
:
(((TabletWidth - 20) / 2) + 8) * 2
: null : null
)
});
this code only calculates 106 as the height of all items! and ignores all the conditions!
am I missing something here, how can I calculate item height based on item data?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9
Top Results From Across the Web
how to calculate the height of a div with some text inside and a ...
There isn't really a way to calculate height of an element that is not in the dom. You can add it somewhere in...
Read more >How to Calculate Height - Sciencing
Calculate the height of the object of interest by calculating "D * tan (theta)," where "*" indicates multiplication and "tan" is the tangent ......
Read more >Length, Width & Height to Volume Calculator - SensorsONE
Use this length x width x height calculator to determine the volume in the following applications: Volume of package to be dispatched to...
Read more >How to Calculate the Image Height of an Object for a Lens
The equation for the magnification of a lens is simply the height of the image divided by the height of the object. M=h ......
Read more >Height and Distance Calculation with Formula & Example
The calculation of the height of an object is achieved by the measurement of its distance from the object. This includes the angle...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Few things I found wrong with the code:
rowRenderer
choose a component instead. You have some components with just text and if you use the same to render an image the text component will get unmounted ideally you must avoid unnecessary unmounts and promote reuse. That is the point of recycling.setState
which I don’t think are necessary, remember they will slow things down. Also, changing things likeimageLoaded1
will not re-render a component being reused incase the previous use case also had the same value. That’s how recycling works.More that than you are getting dimensions upfront in your data source. I see thing being too complicated. Can you just try rendering a use case where only one photo is being shown? It’ll be easier for me to go through and for you to understand. Just render images, from my side I can assure you that this is a solved use case and we’ve done it before.
Your page can be much better. Reduce
setState
calls and break into components and add more types toLayoutProvider
@Komeyl94 For some reason snack is not working for me. I checked multiple devices. I can look into the repo, no problem. Happy to help 😃