Comments (6)
https://facebook.github.io/relay/docs/api-reference-relay-container.html#preparevariables
from emission.
The problem we’re facing with this is that we won’t know the view dimensions until after a layout pass has been performed. This means that we’d have to:
- Fetch initial metadata such as aspect ratio and all other Relay data for the current view.
- Do a layout pass and start rendering views.
- Trigger additional Relay data fetches now that we know the size at which to display the view.
In a situation where there can be many image views, these additional fetches can add up, so this isn’t really an option. We also don’t want to hardcode all sizes for all devices, it needs to be dynamic.
As such, I think that we would need to generate the image variant URL on the client after all, which means that:
- we need metaphysics to return the template URL, we can do that during the initial fetch
- we need code to generate the template URL, which metaphysics already has, so maybe that can be extracted?
/cc @dzucconi
from emission.
Ok, after reading the source for this it actually seems to be really simple. What I understand is:
- We use CloudFront CDN to host our images.
CloudFrontGemini provides an image resizing API that sits behind a CloudFront cache.
Thus, what we should do is:
- During the Relay query we ask for:
- the URL of the
large
version - the aspect ration of the image
- the URL of the
- Based on the aspect ratio we let our image view calculate the dimensions during the React shadow dom layout phase.
- Once the image view has performed its layout, we take those measurements and generate a URL for it by using the Gemini API.
from emission.
#54 makes this work for images that are displayed according to their aspect ratio, but not yet for those that are cropped.
from emission.
For cropped images, what needs to be done is, always get the regular ‘large’ URL of the image, then in the imageview component, if given width/height as style props (i.e. the user of the component wants a fixed size / crop), generate a URL like this, except one that crops.
Here’s an example where you can see that cropped URL basically just uses the large version in its request for a cropped version:
"image": {
"url": "https://d32dm0rphc51dk.cloudfront.net/rHV84MOF6XApp7tAMwTT2A/large.jpg",
"cropped": {
"url": "https://d7hftxdivxxvm.cloudfront.net/?resize_to=fill&width=100&height=100&quality=95&src=https%3A%2F%2Fd32dm0rphc51dk.cloudfront.net%2FrHV84MOF6XApp7tAMwTT2A%2Flarge.jpg"
}
}
from emission.
Oh, and then multiply the explicit styled width and height by the pixel ratio of the screen: https://github.com/artsy/emission/pull/54/files#diff-da61f6f33156049db872499f194f6f79R33
from emission.
Related Issues (20)
- Relay fragment not spreading
- Deployments don't work HOT 11
- Remove -u from `yarn test:ci` command
- Seeing a lot of errors due to shadows
- Recurring query cache error screen
- [RFC] Add react-native-svg HOT 11
- Action Required: Fix Renovate Configuration
- Update Dependencies (Renovate Bot)
- Logo proposal fo emission HOT 1
- [RFC] Add INTUAnimationEngine HOT 5
- [RFC] New dependency: grapheme-splitter HOT 1
- [RFC] Change "Skip New Tests" to #skip_new_tests
- Highest Bid orange looks really light HOT 3
- [RFC] Remove `yarn clean-example` from `yarns start`
- [RFC] Add husky and lint-staged HOT 2
- Add tests for Button component states
- Add event emitter for `view(Will/Did)Appear` events HOT 1
- [RFC] Change `yarn test` to run all types of checks that CI would also run HOT 11
- [Relay] Remove unused imports HOT 1
- [Dev] Deployment doesn't work because of our custom RN source code changes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emission.