-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove konami, segment, clean up Collectible3D (#7131)
- Loading branch information
1 parent
8fa6fd2
commit d94e776
Showing
16 changed files
with
199 additions
and
314 deletions.
There are no files selected for viewing
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
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
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
75 changes: 75 additions & 0 deletions
75
packages/web/src/components/collectibles/components/Collectible3D.tsx
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,75 @@ | ||
import { MutableRefObject, useEffect, useRef } from 'react' | ||
|
||
import type { ModelViewerElement } from '@google/model-viewer' | ||
import '@google/model-viewer/dist//model-viewer.min.js' | ||
|
||
import { getScrollParent } from 'utils/scrollParent' | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
'model-viewer': Partial<ModelViewerElement> & { | ||
ref: MutableRefObject<Partial<ModelViewerElement> | null> | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const Collectible3D = ({ | ||
src, | ||
isMobile | ||
}: { | ||
src: string | ||
isMobile: boolean | ||
}) => { | ||
const ref = useRef<ModelViewerElement>(null) | ||
|
||
useEffect(() => { | ||
const modelViewer = ref.current | ||
if (modelViewer) { | ||
modelViewer.style.minWidth = '50vw' | ||
modelViewer.style.minHeight = '50vh' | ||
|
||
if (isMobile) { | ||
modelViewer.style.width = '100%' | ||
|
||
// for 3d objects, disable parent nft drawer element scrollability if user is on 3d object | ||
const scrollableAncestor = getScrollParent(modelViewer) | ||
let foundDrawerAncestor = false | ||
for (const item of (scrollableAncestor?.classList ?? []).values()) { | ||
if (item.includes('nftDrawer')) { | ||
foundDrawerAncestor = true | ||
break | ||
} | ||
} | ||
if (foundDrawerAncestor) { | ||
const scrollableAncestorElement = scrollableAncestor as HTMLElement | ||
const mouseEnterListener = () => { | ||
scrollableAncestorElement.style.overflowY = 'hidden' | ||
} | ||
const mouseLeaveListener = () => { | ||
scrollableAncestorElement.style.overflowY = 'scroll' | ||
} | ||
modelViewer.addEventListener('mouseenter', mouseEnterListener) | ||
modelViewer.addEventListener('mouseleave', mouseLeaveListener) | ||
|
||
return () => { | ||
modelViewer.removeEventListener('mouseenter', mouseEnterListener) | ||
modelViewer.removeEventListener('mouseleave', mouseLeaveListener) | ||
} | ||
} | ||
} | ||
} | ||
}, [isMobile, ref]) | ||
|
||
return ( | ||
<model-viewer | ||
auto-rotate | ||
camera-controls | ||
ar-status='not-presenting' | ||
ref={ref} | ||
src={src} | ||
/> | ||
) | ||
} |
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
Oops, something went wrong.