Image min_width
calculated based on device screen size, not window inner width
#320
-
When utilizing the variable
This means that when opening a floorplan in a browser, the screen size of the device is the deciding factor, not the actual size of the browser window. I'm not sure if this is intended behavior or not, which is why I would like to discuss it here before creating an issue or pull-request. Example:type: custom:floorplan-card
full_height: false
config:
console_log_level: debug
defaults:
hover_action: hover-info
tap_action: more-info
image:
sizes:
- min_width: 0 # Width referenced based on device screen size, not window size
location: /local/floorplans/Billings/glow/desktop.450.conv.svg
- min_width: 600 # Width referenced based on device screen size, not window size
location: /local/floorplans/Billings/glow/desktop.600.conv.svg Code Refrerence:getBestImage(config: FloorplanConfig): { location: string; cache: boolean } {
let imageUrl = '';
let cache = true;
if (typeof config.image === 'string') {
// Device detection
if (Utils.isMobile && typeof config.image_mobile === 'string') {
imageUrl = config.image_mobile;
} else {
imageUrl = config.image;
}
} else {
if (config.image?.sizes) {
config.image.sizes.sort((a, b) => b.min_width - a.min_width); // sort descending
for (const pageSize of config.image.sizes) {
// window.innerWidth or screen.width?
if (screen.width >= pageSize.min_width) {
imageUrl = pageSize.location;
cache = pageSize.cache === true;
break;
}
}
} else {
// Device detection
if (Utils.isMobile && config.image_mobile) {
imageUrl = (config.image_mobile as FloorplanImageConfig).location;
cache = (config.image_mobile as FloorplanImageConfig).cache === true;
} else {
imageUrl = config.image.location;
cache = config.image.cache === true;
}
}
}
return { location: imageUrl, cache: cache };
} |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 14 replies
-
I am not sure if @petarkozul meant for this behaviour but it seems reasonable to me that it would look that way. Most people seem to use panel view full screen? |
Beta Was this translation helpful? Give feedback.
-
I'm sorry that I've not touched this. I fully understand your thoughts. I guess we should consider to use |
Beta Was this translation helpful? Give feedback.
-
Has this already been dealt with? |
Beta Was this translation helpful? Give feedback.
-
For now, I have a solution. Wrap the HA-Floorplan card in a HA conditional card with the corresponding mediaquery's To avoid having the same rules in multiple cards, put them in a separate yaml file and include that in the rules.
in a separate file the rules.
This code is not complete, but you'll get the idea. |
Beta Was this translation helpful? Give feedback.
-
Is there any downside of converting this to using the bower width instead of screen width? As in, will this break any user's implementations that currently exist? If so, perhaps this could be implemented as a non-default setting. |
Beta Was this translation helpful? Give feedback.
-
Perhaps it’s possible to add, Instead of change into. |
Beta Was this translation helpful? Give feedback.
-
Hi @knicholson32 , @remmob and @OzGav I've made a small change, where we're moving to use But I'd kindy ask you both to test it: Please do me a favor, and test both scenarios:
Let me know how it goes. On basis of your inputs, I'll release it in a few days, and make a note on the possible breaking change, but mention the work-around, and link to a release-discussion for people to point out why they need window.innerWidth. If there's even no inputs in that discussion after some time, I'll remove the legacy way of doing it. Also! While having you guys: If one of you have a great MVP of the "min_width" logics in actions, I'd be happy to accept a PR, so that can be part of the live examples in the future. Please provide the feedback in the PR, by adding a comment in it 👍. |
Beta Was this translation helpful? Give feedback.
-
Sorry, was not able to test it. But will as soon as possible. |
Beta Was this translation helpful? Give feedback.
The primary request of this discussion is now merged into the master branch, and will soon be released: #470