Skip to content

Uplift 1.28.x - Triggers Brave News card view event for small window sizes #9599

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 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const LargeArticle = React.forwardRef<HTMLElement, ArticleProps>(function (props

const innerRef = React.useRef<HTMLElement>(null)

const onItemViewedRef = React.useRef(props.onItemViewed)
onItemViewedRef.current = props.onItemViewed

React.useEffect(() => {
if (!innerRef.current) {
return
Expand All @@ -72,15 +75,20 @@ const LargeArticle = React.forwardRef<HTMLElement, ArticleProps>(function (props
if (!props.onItemViewed) {
return
}
let onItemViewed = props.onItemViewed

const observer = new VisibilityTimer(() => {
onItemViewed(item)
const onItemViewed = onItemViewedRef.current
if (onItemViewed) {
onItemViewed(item)
}
}, 100, innerRef.current)

observer.startTracking()

return () => {
observer.stopTracking()
}
}, [innerRef.current, props.onItemViewed])
}, [innerRef.current, Boolean(props.onItemViewed)])

// TODO(petemill): Avoid nested links
// `ref as any` due to https://github.com/DefinitelyTyped/DefinitelyTyped/issues/28884
Expand Down
2 changes: 1 addition & 1 deletion components/brave_new_tab_ui/helpers/visibilityTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class VisibilityTimer {
this.isIntersecting = entries.some(entry => entry.isIntersecting)
this.handleVisibility()
}, {
threshold: 1.0
threshold: 0.5
})
}
}
Expand Down