-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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,26 @@ | ||
/** | ||
* Simple workarounf to apply styles to a list | ||
* when user scrolls to the bottom of the list. | ||
*/ | ||
|
||
import React from "react"; | ||
import { useRef } from "react"; | ||
import { useOnScreen } from "../lib/useOnScreen"; | ||
|
||
type ListProps = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
export const List = ({ children }: ListProps) => { | ||
const ref = useRef(null); | ||
const { isOnScreen } = useOnScreen({ ref, margin: "100px" }); | ||
|
||
return ( | ||
<ul className={isOnScreen ? "some-effects" : "regular-list"}> | ||
{children} | ||
<li ref={ref} className="hidden-dummy" aria-hidden /> | ||
</ul> | ||
); | ||
}; | ||
|
||
export default List; |
This file contains 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,37 @@ | ||
/** | ||
* Simple workaround to pause the video | ||
* when the player is not on the screen | ||
* and play it when it is. | ||
* It is not supposed to be in your production code, only for demo purposes. | ||
*/ | ||
|
||
import React from "react"; | ||
import { useRef } from "react"; | ||
import { useOnScreen } from "../lib/useOnScreen"; | ||
|
||
type VideoProps = { | ||
src: string; | ||
}; | ||
|
||
export const Video = ({ src }: VideoProps) => { | ||
const ref = useRef<HTMLVideoElement>(null); | ||
const { isOnScreen } = useOnScreen({ ref, threshold: 0.5 }); | ||
|
||
const stopVideo = React.useCallback(() => { | ||
ref.current && ref.current.pause(); | ||
}, [ref]); | ||
|
||
const playVideo = React.useCallback(() => { | ||
ref.current && ref.current.play(); | ||
}, [ref]); | ||
|
||
React.useEffect(() => { | ||
if (isOnScreen) { | ||
playVideo(); | ||
} else { | ||
stopVideo(); | ||
} | ||
}, [isOnScreen, stopVideo, playVideo]); | ||
|
||
return <video ref={ref} src={src} autoPlay loop />; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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