This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
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
4 changed files
with
152 additions
and
144 deletions.
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
packages/app/components/creator-channels/components/image-preview.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,121 @@ | ||
import { useMemo, memo } from "react"; | ||
import { Platform, StyleSheet, Dimensions } from "react-native"; | ||
|
||
import { Image } from "@showtime-xyz/universal.image"; | ||
import { LightBox } from "@showtime-xyz/universal.light-box"; | ||
|
||
import { ChannelMessageAttachment } from "../types"; | ||
import { LeanView } from "./lean-text"; | ||
|
||
const width = Dimensions.get("window").width; | ||
const height = Dimensions.get("window").height; | ||
|
||
const getImageAttachmentWidth = (attachment: ChannelMessageAttachment) => { | ||
if (!attachment || !attachment.height || !attachment.width) { | ||
return 0; | ||
} | ||
if (attachment?.height > attachment?.width) { | ||
return 160; | ||
} else if (attachment?.height < attachment?.width) { | ||
return 320; | ||
} else { | ||
return 320; | ||
} | ||
}; | ||
|
||
const getImageAttachmentHeight = (attachment: ChannelMessageAttachment) => { | ||
if (!attachment || !attachment.height || !attachment.width) { | ||
return 0; | ||
} | ||
if (attachment.height > attachment.width) { | ||
return 284; | ||
} else if (attachment.height < attachment.width) { | ||
return 180; | ||
} else { | ||
return 320; | ||
} | ||
}; | ||
|
||
export const ImagePreview = memo( | ||
({ attachment }: { attachment: ChannelMessageAttachment }) => { | ||
const imageAttachmentWidth = useMemo( | ||
() => getImageAttachmentWidth(attachment), | ||
[attachment] | ||
); | ||
|
||
const imageAttachmentHeight = useMemo( | ||
() => getImageAttachmentHeight(attachment), | ||
[attachment] | ||
); | ||
const isLandscape = | ||
attachment.width && attachment.height | ||
? attachment.width > attachment.height | ||
: false; | ||
|
||
const imageWidth = isLandscape | ||
? Math.max(380, Math.min(width, height * 0.7)) | ||
: Math.min(width, height * 0.7); | ||
|
||
const imageHeight = | ||
attachment.height && attachment?.width | ||
? isLandscape | ||
? imageWidth * (attachment.height / attachment.width) | ||
: Math.min( | ||
height, | ||
imageWidth * (attachment.height / attachment.width) | ||
) | ||
: 320; | ||
|
||
return ( | ||
<LeanView | ||
tw="overflow-hidden rounded-xl bg-gray-600" | ||
style={{ | ||
width: imageAttachmentWidth, | ||
height: imageAttachmentHeight, | ||
}} | ||
> | ||
<LightBox | ||
width={imageAttachmentWidth} | ||
height={imageAttachmentHeight} | ||
imgLayout={{ | ||
width: "100%", | ||
height: | ||
Platform.OS === "web" | ||
? imageAttachmentHeight | ||
: width * | ||
(attachment.height && attachment?.width | ||
? attachment?.height / attachment.width | ||
: 320), | ||
}} | ||
tapToClose | ||
borderRadius={12} | ||
containerStyle={ | ||
Platform.OS === "web" | ||
? { | ||
width: imageWidth, | ||
height: imageHeight, | ||
} | ||
: null | ||
} | ||
> | ||
<Image | ||
transition={100} | ||
recyclingKey={attachment?.media_upload} | ||
source={ | ||
attachment?.url | ||
? `${attachment?.url}?optimizer=image&width=600` | ||
: undefined | ||
} | ||
alt="" | ||
resizeMode="cover" | ||
style={{ | ||
...StyleSheet.absoluteFillObject, | ||
}} | ||
/> | ||
</LightBox> | ||
</LeanView> | ||
); | ||
} | ||
); | ||
|
||
ImagePreview.displayName = "ImagePreview"; |
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
26 changes: 26 additions & 0 deletions
26
packages/app/components/creator-channels/components/message-skeleton.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,26 @@ | ||
import { Skeleton } from "@showtime-xyz/universal.skeleton"; | ||
|
||
import { LeanView } from "./lean-text"; | ||
|
||
export const MessageSkeleton = () => { | ||
return ( | ||
<LeanView tw="web:pb-4 h-full w-full flex-1 pb-14"> | ||
<LeanView tw="h-full flex-1 justify-end px-4"> | ||
{new Array(8).fill(0).map((_, i) => { | ||
return ( | ||
<LeanView tw="flex-row pt-4" key={`${i}`}> | ||
<LeanView tw="mr-2 overflow-hidden rounded-full"> | ||
<Skeleton width={28} height={28} show /> | ||
</LeanView> | ||
<LeanView> | ||
<Skeleton width={140} height={10} show /> | ||
<LeanView tw="h-1" /> | ||
<Skeleton width={90} height={10} show /> | ||
</LeanView> | ||
</LeanView> | ||
); | ||
})} | ||
</LeanView> | ||
</LeanView> | ||
); | ||
}; |
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