Skip to content

Commit

Permalink
Add videos to list.
Browse files Browse the repository at this point in the history
Video icon added on each item.
  • Loading branch information
ghorbani-m committed May 22, 2022
1 parent 084c38c commit 9a38997
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { memo } from "react"
import { StyleSheet, View, Image, NativeSyntheticEvent, ImageErrorEventData } from "react-native"
import { useTheme } from "@rneui/themed"
import { Icon, Text, useTheme } from "@rneui/themed"
import { Asset } from "../../../../types"
import { palette } from "../../../../theme/palette"
import { Checkbox } from "../../../checkbox/checkbox"

import Animated, { useSharedValue, useAnimatedStyle, withTiming } from "react-native-reanimated"
import { SharedElement } from "react-navigation-shared-element"
import { convertDurationToTime } from "../../../../utils/helper"

interface Props {
asset: Asset
Expand Down Expand Up @@ -57,6 +57,11 @@ const AssetItem = (props: Props): JSX.Element => {
/>
</SharedElement>
</Animated.View>
{asset?.mediaType === "video" &&
<View style={styles.videoIconContainer}>
<Text style={styles.videoDurationText}>{convertDurationToTime(asset?.duration)}</Text>
<Icon name="play-circle" type="material-community" size={20} color="gray" />
</View>}
{selectionMode ? <Checkbox value={selected} style={styles.checkbox} /> : null}
</View>
)
Expand Down Expand Up @@ -86,6 +91,20 @@ const styles = StyleSheet.create({
sharedElementContainer: {
flex: 1,
},
videoIconContainer: {
right: 10,
position: "absolute",
top: 10,
zIndex: 99,
flexDirection: "row",
justifyContent: "center",
alignItems: "center"
},
videoDurationText: {
color: "gray",
fontSize: 10,
padding: 1
}
})

const areEqual = (prev: Props, next: Props) => {
Expand Down
2 changes: 2 additions & 0 deletions app/services/asset-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ export const getAssets = async (
first: pageSize,
after: afterAssetId,
sortBy: sortBy,
mediaType: ["photo", "video"],
}
: {
first: pageSize,
sortBy: sortBy,
mediaType: ["photo", "video"],
},
)
return medias
Expand Down
8 changes: 8 additions & 0 deletions app/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export const translateOrigin = (center: number, d: number) => {
return center - d / 2
}
export const convertDurationToTime = (duration: number): string => {
const h = Math.floor(duration / 3600)
const m = Math.floor((duration % 3600) / 60)
const s = Math.floor(duration % 60)
return h
? `${h.toString().padStart(2, "0")}:`
: "" + `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`
}

0 comments on commit 9a38997

Please sign in to comment.