-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional embed sources and external-media consent controls #2424
Conversation
…l-app into haileyok-additional-embeds
As a side note, zod experience is fleeting. The way I did the schema (with all the |
No yeah that's the move there. Old objects wont have that key |
…-social#2424) * add apple music embed * add vimeo embed * add logic for tenor and giphy embeds * keep it simple, use playerUri for images too * add gif embed player * lint, fix tests * remove links that can't produce a thumb * Revert "remove links that can't produce a thumb" This reverts commit 985b92b. * Revert "Revert "remove links that can't produce a thumb"" This reverts commit 4895ded. * Revert "Revert "Revert "remove links that can't produce a thumb""" This reverts commit 36d04b5. * properly obtain giphy metadata regardless of used url * test fixes * adjust gif player * add all twitch embed types * support m.youtube links * few logic adjustments * adjust spotify player height * prefetch gif before showing * use memory-disk cache policy on gifs * use `disk` cachePolicy on ios - can't start/stop animation * support pause/play on web * onLoad fix * remove extra pressable, add accessibility, fix scale issues * improve size of embed * add settings * fix(?) settings * add source to embed player params * update tests * better naming and settings options * consent modal * fix test id * why is webstorm adding .tsx * web modal * simplify types * adjust snap points * remove unnecessary yt embed library. just use the webview always * remove now useless WebGifStill 😭 * more type cleanup * more type cleanup * combine parse and prefs check in one memo * improve dimensions of youtube shorts * oops didn't commit the test 🫥 * add shorts as separate embed type * fix up schema * shorts modal * hide gif details * support localized spotify embeds * more cleanup * improve look and accessibility of gif embeds * Update routing for the external embeds settings page * Update and simplify the external embed preferences screen * Update copy in embedconsent modal and add 'allow all' button --------- Co-authored-by: Hailey <[email protected]>
* origin: (45 commits) Fix splash config (#2452) convert prefix to lowercase in actor autocomplete query (#2431) support intl tenor links (#2438) Splash: reduce motion + dark mode (#2448) Bump android app version code Don't use mask for android at all (#2445) Update Korean localization (#2432) Use android mode, fix fallback (#2437) Update for Version 1.63 Português (BR) (#2435) New translations messages.po (Ukrainian) (#2422) Update Japanese localization (addition + language code correction) (#2423) 1.63 Additional embed sources and external-media consent controls (#2424) Reduce web requests (#2420) New user home feed fixes (#2421) E2E runner fixes (#2428) Recompile all locales (#2411) (#2416) Add Ukrainian localization (#2336) Update Portuguese for Português (#2414) Add Portuguese Localization (#2407) ...
Supersedes #2353 by:
Inherited from the original PR:
implements #2314
fixes #2338
fixes #2386
fixes #2357
Fixing:
Adding:
iOS: https://www.youtube.com/watch?v=ediW57z0Yt0
Android: https://www.youtube.com/watch?v=nLG8jTO3bhg
Web Mobile: https://www.youtube.com/watch?v=dVDMGMg3lTU
Web: https://www.youtube.com/watch?v=c2J3voPma5k
Consent:
CleanShot.2024-01-04.at.10.51.39.mp4
CleanShot.2024-01-04.at.10.49.37.mp4
Remove react-native-youtube-iframe
This isn't necessary. We can reliably use the WebView on native, and it's actually better performing. The library was interacting with the YT embed JS api, which we don't need.
Gifs
Displaying
Tenor and Giphy use a different player. Since we can rely on these images to not have audio and not be resource intensive, we do not need to remove them from the view once loaded. They will also maintain aspect ratio so we don't need to worry about jumping as we scroll away from them.
We don't want to load external assets before the user opts to do so. Therefore:
ActivityIndicator
is overlayed on the thumbnailexpo-image
control the playback of the gifIn an effort to keep these as non-intrusive as possible to the view, gifs are capped at a height of 250px
Posting
Usually, tenor or giphy will give a share link that is a direct link to a gif, like so: https://media.giphy.com/media/tXL4FHPSnVJ0A/giphy.gif. This is the link that we want to use to render the image in the
Image
component. However, this link does not let us fetch the metadata and thumbnail.However, we know that the ID for the gif is
tXL4FHPSnVJ0A
. Therefore, we can rewrite the url to behttps://giphy.com/gifs/tXL4FHPSnVJ0A
and giphy will resolve that to the correct link, in this casehttps://giphy.com/gifs/kim-novak-tXL4FHPSnVJ0A
.Therefore, we add a little workaround to
link-meta.ts
when we request the metadata.Unfortunately with Tenor, we cannot (as far as I have been able to tell, and @mozzius supposedly had the same issues) reliably do this with Tenor. Since we must obtain metadata, we only support embedding links to the actual tenor website such as
https://tenor.com/view/thankful-thursday-gif-17785223204185977462
. We can then append.gif
to that url to get the gif for displaying in theImage
component. Note though here that the ID has changed, so we cannot reverse this process to get metadata.On one hand, updating (what I'm assuming you know as CardyB? lmao) to support some sort of gif images thing would be....a possibility. Actually, a very simple one from the looks of it. However, in an effort to still maintain some level of alt text for gifs, I don't think this is the best idea. The meta data serves as a fair form of alt text.
URLs supported (Giphy links can be shared as any of the different file names such as giphy-downsized.gif, giphy.webp, giphy.mp4, etc and we will always use the webp):
Downsizing
Regardless of the type of link provided, we always will use webp when possible. Any giphy type (gif, webp, or mp4) will use the .webp version of the image. These appear to be sub 2MB in almost all cases.
Player
expo-image
supports pausing/playing a gif natively. We can use this functionality easily, and don't need to bother replacing images with thumbnails or anything else.No longer needed canvas hack
On web, things are a bit trickier. There are a few options that we have:
contentFit="contain"
, but we still run into issues with some placeholders and trying to maintain the same dimensions as the gif, but this is still subpar since there are differences sometimes such as background color (not transparent in the thumbnail, instead shows up as white), widths being different, etc.The solution then is to use a
canvas
. I've created a small component,WebGifStill
We leave this still behind the playing image to 1. to act as the "stopped" gif and 2. prevent flickers when rendering/removing the gif from the view (to simulate stop/play). Drawing the image to the canvas renders only the first frame of the image which is just what we want. Additionally, this does not create an additional request for the image.
I've tested this against both WEBP and GIFs on Edge, Chrome, Firefox, and Safari on desktop, Safari and Chrome on iOS, and Chrome and Firefox on Android. All of these browsers support this. See Canvas Browser Compatibility
#2379 blocks this PR right now. I had implemented a canvas hack where we could draw an image, but this will be unnecessary once web thumb resizing is fixed 🎉 Now, all we have to do to "pause" the gif on web is to just replace the gif with the thumb.
Consent
external-embeds-prefs.tsx
useModalControls()
Cleanup 🧹
Tidied up
embed-player.ts
and the types there. It was getting a bit messy and had a bunch of details we didn't actually need.