-
Notifications
You must be signed in to change notification settings - Fork 589
feat: support video headers in editorial #12853
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
412da4f
first pass at video header
brainbicycle 3cd445a
feat: overlay article hero text on video with gradient and shadows
brainbicycle efd459c
needs adjustment, style tweaks, hardcoded height
brainbicycle 3499386
account for safe area
brainbicycle f7767b0
fix: implement FULLSCREEN layout video height calculation
brainbicycle 517aa66
test: add global LinearGradient mock and fix ArticleHero tests
brainbicycle 7f5021d
make media explicitly null to avoid video codepath
brainbicycle 757adfd
make media explicitly null to avoid video codepath
brainbicycle 2e6c0e4
tweaks to flags on android
brainbicycle 26c4cfc
minor cleanup
brainbicycle c565e18
feat: optimize video loading and add video test
brainbicycle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { Flex, useColor } from "@artsy/palette-mobile" | ||
| import { useMemo } from "react" | ||
| import { Platform } from "react-native" | ||
| import { WebView } from "react-native-webview" | ||
|
|
||
| interface ArticleHeroVideoProps { | ||
| videoUrl: string | ||
| width: number | ||
| height: number | ||
| } | ||
|
|
||
| export const ArticleHeroVideo: React.FC<ArticleHeroVideoProps> = ({ videoUrl, width, height }) => { | ||
| const color = useColor() | ||
| const backgroundColor = color("mono30") | ||
|
|
||
| // Memoize HTML to prevent re-renders | ||
| const html = useMemo( | ||
| () => ` | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
| <style> | ||
| * { | ||
| margin: 0; | ||
| padding: 0; | ||
| box-sizing: border-box; | ||
| } | ||
| body { | ||
| background-color: ${backgroundColor}; | ||
| overflow: hidden; | ||
| position: fixed; | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
| video { | ||
| width: 100%; | ||
| height: 100%; | ||
| object-fit: cover; | ||
| display: block; | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <video | ||
| autoplay | ||
| loop | ||
| muted | ||
| playsinline | ||
| preload="auto" | ||
| webkit-playsinline | ||
| > | ||
| <source src="${videoUrl}" type="video/mp4"> | ||
| </video> | ||
| </body> | ||
| </html> | ||
| `, | ||
| [videoUrl, backgroundColor] | ||
| ) | ||
|
|
||
| return ( | ||
| <Flex width={width} height={height} backgroundColor="mono30" testID="ArticleHeroVideo"> | ||
| <WebView | ||
| source={{ html }} | ||
| style={{ flex: 1, backgroundColor }} | ||
| allowsInlineMediaPlayback | ||
| mediaPlaybackRequiresUserAction={false} | ||
| scrollEnabled={false} | ||
| bounces={false} | ||
| // Prevent zooming | ||
| scalesPageToFit={Platform.OS === "android"} | ||
| // Performance optimizations | ||
| androidLayerType="hardware" | ||
| androidHardwareAccelerationDisabled={false} | ||
| cacheEnabled={true} | ||
| cacheMode="LOAD_DEFAULT" | ||
| // Faster initial load | ||
| startInLoadingState={false} | ||
| // Prevent unnecessary re-renders | ||
| setSupportMultipleWindows={false} | ||
| // Allow mixed content for better Android network performance | ||
| mixedContentMode="always" | ||
| /> | ||
| </Flex> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,14 +167,23 @@ jest.mock("react-native-webview", () => { | |
| const React = require("react") | ||
| const { View } = require("react-native") | ||
|
|
||
| const MockWebView = React.forwardRef((props: any, ref: any) => { | ||
| return <View ref={ref} {...props} /> | ||
| }) | ||
|
|
||
| return { | ||
| __esModule: true, | ||
| default: React.forwardRef((props: any, ref: any) => { | ||
| return <View ref={ref} {...props} /> | ||
| }), | ||
| default: MockWebView, | ||
| WebView: MockWebView, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing named export mock was causing test failures |
||
| } | ||
| }) | ||
|
|
||
| jest.mock("react-native-linear-gradient", () => { | ||
| const React = require("react") | ||
| const { View } = require("react-native") | ||
| return React.forwardRef((props: any, ref: any) => <View {...props} ref={ref} />) | ||
| }) | ||
|
|
||
| jest.mock("react-native-share", () => ({ | ||
| open: jest.fn(), | ||
| })) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using embedded html and webviews built in video playback capabilities, customization is limited and performance specifically on Android is not great (at least on my old test device), but is what we are currently using for embedded videos, if we find it is not up to the task we should explore video libraries like react-native-video