Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #664 from tryshowtime/feature/show2-289-media
Browse files Browse the repository at this point in the history
Media
  • Loading branch information
axeldelafosse authored Jan 10, 2022
2 parents 6ae0fc2 + 54396bb commit b8568cf
Show file tree
Hide file tree
Showing 21 changed files with 672 additions and 93 deletions.
1 change: 1 addition & 0 deletions apps/expo/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ LogBox.ignoreLogs([
"No native splash screen",
"The provided value 'ms-stream' is not a valid 'responseType'.",
"The provided value 'moz-chunked-arraybuffer' is not a valid 'responseType'.",
"Constants.platform.ios.model has been deprecated in favor of expo-device's Device.modelName property.",
]);

function QRCodeModal(props: RenderQrcodeModalProps): JSX.Element {
Expand Down
1 change: 1 addition & 0 deletions apps/expo/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ config.resolver.nodeModulesPath = [
path.resolve(workspaceRoot, "node_modules"),
];
config.resolver.extraNodeModules = extraNodeModules;
config.resolver.assetExts = ["glb", "png", "jpg"];
// config.transformer.minifierPath = 'metro-minify-esbuild'

module.exports = config;
8 changes: 6 additions & 2 deletions apps/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@react-navigation/native": "^6.0.6",
"@react-navigation/native-stack": "^6.2.5",
"@react-navigation/stack": "^6.0.11",
"@react-three/fiber": "^8.0.0-beta-04",
"@sentry/react-native": "^3.2.3",
"@tradle/react-native-http": "^2.0.0",
"@walletconnect/react-native-dapp": "^1.6.6",
Expand Down Expand Up @@ -69,6 +70,7 @@
"expo-dev-client": "~0.8.0",
"expo-device": "~4.1.0",
"expo-font": "~10.0.4",
"expo-gl": "^11.1.1",
"expo-haptics": "~11.1.0",
"expo-linear-gradient": "^11.0.0",
"expo-linking": "~3.0.0",
Expand All @@ -88,8 +90,8 @@
"process": "^0.11.0",
"punycode": "^2.1.1",
"querystring-es3": "~0.2.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "18.0.0-rc.0",
"react-dom": "18.0.0-rc.0",
"react-hook-form": "^7.20.2",
"react-native": "0.64.3",
"react-native-blurhash": "1.1.5",
Expand All @@ -114,6 +116,7 @@
"sentry-expo": "^4.0.3",
"stream-browserify": "^3.0.0",
"string_decoder": "~1.3.0",
"three": "0.133.1",
"timers-browserify": "^2.0.12",
"tty-browserify": "0.0.1",
"twrnc": "^2.0.7",
Expand All @@ -125,6 +128,7 @@
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@types/three": "0.133.1",
"esbuild": "^0.13.15",
"metro-minify-esbuild": "^0.1.0",
"typescript": "4.5.2"
Expand Down
2 changes: 1 addition & 1 deletion apps/expo/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
assets: ["./assets/fonts/"],
assets: ["./assets/"],
};
4 changes: 2 additions & 2 deletions apps/storybook-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"expo-system-ui": "~1.1.0",
"expo-updates": "~0.11.3",
"expo-web-browser": "~10.1.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react": "18.0.0-rc.0",
"react-dom": "18.0.0-rc.0",
"react-native": "0.64.3",
"react-native-gesture-handler": "^2.1.0",
"react-native-pager-view": "5.4.9",
Expand Down
4 changes: 2 additions & 2 deletions apps/storybook-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"dependencies": {
"design-system": "*",
"next": "12.0.7",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "18.0.0-rc.0",
"react-dom": "18.0.0-rc.0",
"react-native-web": "0.17.5"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
},
"resolutions": {
"babel-preset-expo": "^8.5.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "18.0.0-rc.0",
"react-dom": "18.0.0-rc.0",
"react-native-svg": "^12.1.1",
"expo-linear-gradient": "^11.0.0"
},
Expand Down
5 changes: 1 addition & 4 deletions packages/app/screens/nft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { axios } from "app/lib/axios";
import { Close, MoreHorizontal } from "design-system/icon";
import { useRouter } from "app/navigation/use-router";
import { tw } from "design-system/tailwind";
import { PinchToZoom } from "design-system/pinch-to-zoom";

type Query = {
id: string;
Expand Down Expand Up @@ -68,9 +67,7 @@ function NftScreen() {
</View>
</View>

<PinchToZoom>
<Media nfts={[nft]} />
</PinchToZoom>
<Media nfts={[nft]} />
</View>
);
}
Expand Down
140 changes: 89 additions & 51 deletions packages/design-system/card/media.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useCallback } from "react";
import { FlatList, useWindowDimensions } from "react-native";
import { Video } from "expo-av";
import { Pressable, FlatList, useWindowDimensions } from "react-native";
import Router from "next/router";

import { View, Image } from "design-system";
import { Pressable } from "react-native";
import { useRouter } from "app/navigation/use-router";
import { mixpanel } from "app/lib/mixpanel";

import { View, Image } from "design-system";
import { Video } from "design-system/video";
import { Model } from "design-system/model";
import { PinchToZoom } from "design-system/pinch-to-zoom";

const getImageUrl = (imgUrl: string, tokenAspectRatio: number) => {
if (imgUrl && imgUrl.includes("https://lh3.googleusercontent.com")) {
Expand Down Expand Up @@ -60,50 +63,87 @@ function Media({ nfts }: Props) {
if (!item) return null;

return (
<Pressable onPress={() => openNFT(item.nft_id?.toString())}>
{item.mime_type?.startsWith("image") && (
<Image
source={{
uri:
count === 1
? getImageUrlLarge(
item.still_preview_url
? item.still_preview_url
: item.token_img_url,
item.token_aspect_ratio
)
: getImageUrl(
item.still_preview_url
? item.still_preview_url
: item.token_img_url,
item.token_aspect_ratio
),
}}
tw={count > 1 ? "w-[50vw] h-[50vw]" : "w-[100vw] h-[100vw]"}
blurhash={item.blurhash}
resizeMode="cover"
/>
)}

{item.mime_type?.startsWith("video") && (
<Video
// ref={video}
// style={styles.video}
source={{
uri: item.animation_preview_url
? item.animation_preview_url
: item?.source_url
? item?.source_url
: item?.token_animation_url,
}}
useNativeControls
resizeMode="contain"
isLooping
isMuted
// onPlaybackStatusUpdate={status => setStatus(() => status)}
/>
)}
</Pressable>
<View
tw={[
count >= 2 ? "m-[2px]" : "",
item.token_background_color
? `bg-[#${item.token_background_color}]`
: "bg-black",
]}
>
<Pressable
onPress={() => {
openNFT(item.nft_id?.toString());
mixpanel.track("Activity - Click on NFT image, open modal");
}}
>
{item.mime_type === "image/svg+xml" && (
<>
{
// TODO: implement SVG rendering
}
</>
)}

{item.mime_type?.startsWith("image") &&
item.mime_type !== "image/svg+xml" && (
<PinchToZoom>
<Image
source={{
uri:
count === 1
? getImageUrlLarge(
item.still_preview_url
? item.still_preview_url
: item.token_img_url,
item.token_aspect_ratio
)
: getImageUrl(
item.still_preview_url
? item.still_preview_url
: item.token_img_url,
item.token_aspect_ratio
),
}}
tw={count > 1 ? "w-[50vw] h-[50vw]" : "w-[100vw] h-[100vw]"}
blurhash={item.blurhash}
resizeMode="cover"
/>
</PinchToZoom>
)}

{item.mime_type?.startsWith("video") && (
<Video
source={{
uri: item.animation_preview_url
? item.animation_preview_url
: item?.source_url
? item?.source_url
: item?.token_animation_url,
}}
posterSource={{
uri: item.still_preview_url,
}}
tw={count > 1 ? "w-[50vw] h-[50vw]" : "w-[100vw] h-[100vw]"}
resizeMode="cover"
useNativeControls={count === 1}
/>
)}

{item.mime_type?.startsWith("model") && (
<View
tw={count > 1 ? "w-[50vw] h-[50vw]" : "w-[100vw] h-[100vw]"}
>
<Model
url={item.source_url}
fallbackUrl={item.still_preview_url}
count={count}
blurhash={item.blurhash}
/>
</View>
)}
</Pressable>
</View>
);
},
[count]
Expand All @@ -122,20 +162,18 @@ function Media({ nfts }: Props) {
[width]
);

const ItemSeparatorComponent = useCallback(() => <View />, []);

if (count === 1) {
return renderItem({ item: nfts[0] });
}

return (
<FlatList
style={count >= 2 ? { marginHorizontal: -2 } : {}}
data={nfts}
keyExtractor={keyExtractor}
numColumns={2}
renderItem={renderItem}
getItemLayout={getItemLayout}
ItemSeparatorComponent={ItemSeparatorComponent}
initialNumToRender={count}
// @ts-ignore
listKey={keyExtractor}
Expand Down
4 changes: 2 additions & 2 deletions packages/design-system/icon/Showtime.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 9 additions & 11 deletions packages/design-system/icon/Showtime.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import * as React from "react";
import Svg, { SvgProps, Path } from "react-native-svg";

function SvgShare(props: SvgProps) {
return (
<Svg width="24" height="24" viewBox="0 0 24 24" fill="none" {...props}>
<Path
d="M12.1014 1.71846C12.0726 1.62 11.9275 1.62 11.8987 1.71846C10.4677 6.61088 6.61091 10.4677 1.71848 11.8987C1.62002 11.9275 1.62002 12.0725 1.71848 12.1013C6.61092 13.5323 10.4677 17.3891 11.8987 22.2815C11.9275 22.38 12.0726 22.38 12.1014 22.2815C13.5324 17.3891 17.3891 13.5324 22.2815 12.1013C22.38 12.0725 22.38 11.9275 22.2815 11.8987C17.3891 10.4677 13.5323 6.61088 12.1014 1.71846Z"
fill={props.color}
/>
</Svg>
);
}
const SvgShowtime = (props: SvgProps) => (
<Svg width={24} height={24} viewBox="0 0 80 80" fill="none" {...props}>
<Path
d="M75.71 41.838c1.617-.692 1.617-2.984 0-3.676l-10.842-4.647a35 35 0 0 1-18.383-18.383L41.838 4.289c-.692-1.616-2.984-1.616-3.676 0l-4.647 10.843a35 35 0 0 1-18.383 18.383L4.289 38.162c-1.616.692-1.616 2.984 0 3.676l10.843 4.647a35 35 0 0 1 18.383 18.383l4.647 10.843c.692 1.616 2.984 1.616 3.676 0l4.647-10.843a35 35 0 0 1 18.383-18.383l10.843-4.647Z"
fill={props.color}
/>
</Svg>
);

export default SvgShare;
export default SvgShowtime;
1 change: 1 addition & 0 deletions packages/design-system/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function StyledImage({ tw, style, blurhash, ...props }: ImageProps) {

// <View sx={{ borderRadius, overflow: 'hidden' }}>

// TODO: fix Blurhash on Android
if (blurhash && Platform.OS === "ios") {
return (
<Blurhash
Expand Down
51 changes: 51 additions & 0 deletions packages/design-system/model/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { Suspense } from "react";

// import { Canvas, useFrame } from "./react-three-fiber";
import { useGLTF } from "./use-gltf";
import { Image } from "design-system/image";

type Props = {
url: string;
fallbackUrl: string;
blurhash: string;
count: number;
};

function Model({ url }: { url: string }) {
const { scene } = useGLTF(url);
// useFrame(() => (scene.rotation.y += 0.01));

return <primitive object={scene} />;
}

// TODO: implement touch events à la `OrbitControls`
// Event (prop) Description Implementation
// onPointerOver called when mouse hover starts onHoverIn
// onPointerOut called when mouse hover ends onHoverOut
// onClick called when press triggers onPress
// onPointerDown called when press starts onPressIn
// onPointerUp called when press ends onPressOut
// onPointerMove called when press moves onPressMove

function ModelViewer({ url, fallbackUrl, blurhash, count }: Props) {
return (
<Image
source={{
uri: fallbackUrl,
}}
tw={count > 1 ? "w-[50vw] h-[50vw]" : "w-[100vw] h-[100vw]"}
blurhash={blurhash}
resizeMode="cover"
/>
);

// return (
// <Canvas gl={{ physicallyCorrectLights: true }}>
// <Suspense fallback={null}>
// <Model url={url} />
// </Suspense>
// </Canvas>
// );
}

export { ModelViewer as Model };
1 change: 1 addition & 0 deletions packages/design-system/model/react-three-fiber/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Canvas, useLoader, useFrame } from "@react-three/fiber/native";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Canvas, useLoader, useFrame } from "@react-three/fiber";
Loading

0 comments on commit b8568cf

Please sign in to comment.