Skip to content

Commit 0fa3d94

Browse files
fix: incorrect typing of getPhotos between expo and native (#2146)
* fix: align types of getPhotos between expo and native * chore: align types * chore: remove playableDuration * Update package/src/types/types.ts Co-authored-by: Khushal Agarwal <[email protected]> * chore: fix the ascending order --------- Co-authored-by: Khushal Agarwal <[email protected]>
1 parent fccca0e commit 0fa3d94

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

package/expo-package/src/handlers/getPhotos.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import * as MediaLibrary from 'expo-media-library';
2+
import type { Asset } from 'stream-chat-react-native-core';
23

3-
export const getPhotos = async ({ after, first }: MediaLibrary.AssetsOptions) => {
4+
type ReturnType = {
5+
assets: Array<Omit<Asset, 'source'> & { source: 'picker' }>;
6+
endCursor: string | undefined;
7+
hasNextPage: boolean;
8+
};
9+
10+
export const getPhotos = async ({
11+
after,
12+
first,
13+
}: MediaLibrary.AssetsOptions): Promise<ReturnType> => {
414
try {
515
const { status } = await MediaLibrary.requestPermissionsAsync();
616
if (status !== 'granted') {
@@ -17,7 +27,7 @@ export const getPhotos = async ({ after, first }: MediaLibrary.AssetsOptions) =>
1727
filename: asset.filename,
1828
height: asset.height,
1929
id: asset.id,
20-
source: 'picker',
30+
source: 'picker' as const,
2131
type: asset.mediaType,
2232
uri: asset.uri,
2333
width: asset.width,

package/native-package/src/handlers/getPhotos.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { PermissionsAndroid, Platform } from 'react-native';
22

33
import { CameraRoll, GetPhotosParams } from '@react-native-camera-roll/camera-roll';
4+
import type { Asset } from 'stream-chat-react-native-core';
5+
6+
type ReturnType = {
7+
assets: Array<Omit<Asset, 'source'> & { source: 'picker' }>;
8+
endCursor: string | undefined;
9+
hasNextPage: boolean;
10+
};
411

512
const verifyAndroidPermissions = async () => {
613
const isRN71orAbove = Platform.constants.reactNativeVersion?.minor >= 71;
@@ -49,7 +56,10 @@ const verifyAndroidPermissions = async () => {
4956
return true;
5057
};
5158

52-
export const getPhotos = async ({ after, first }: Pick<GetPhotosParams, 'after' | 'first'>) => {
59+
export const getPhotos = async ({
60+
after,
61+
first,
62+
}: Pick<GetPhotosParams, 'after' | 'first'>): Promise<ReturnType> => {
5363
try {
5464
if (Platform.OS === 'android') {
5565
const granted = await verifyAndroidPermissions();
@@ -65,7 +75,12 @@ export const getPhotos = async ({ after, first }: Pick<GetPhotosParams, 'after'
6575
});
6676
const assets = results.edges.map((edge) => ({
6777
...edge.node.image,
68-
source: 'picker',
78+
duration: edge.node.image.playableDuration,
79+
// since we include filename, fileSize in the query, we can safely assume it will be defined
80+
filename: edge.node.image.filename as string,
81+
fileSize: edge.node.image.fileSize as number,
82+
source: 'picker' as const,
83+
type: edge.node.type,
6984
}));
7085
const hasNextPage = results.page_info.has_next_page;
7186
const endCursor = results.page_info.end_cursor;

package/src/components/AttachmentPicker/components/AttachmentPickerItem.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
4444
},
4545
} = useTheme();
4646

47-
const { duration, playableDuration, uri } = asset;
48-
49-
const videoDuration = duration ? duration : playableDuration;
47+
const { duration: videoDuration, uri } = asset;
5048

5149
const ONE_HOUR_IN_SECONDS = 3600;
5250

package/src/types/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import type { ExtendableGenerics, LiteralStringForUnion } from 'stream-chat';
33
export type Asset = {
44
duration: number | null;
55
filename: string;
6-
fileSize: string;
76
height: number;
8-
playableDuration: number | null;
97
source: 'camera' | 'picker';
108
type: string;
119
uri: string;
1210
width: number;
11+
fileSize?: number;
1312
id?: string;
1413
size?: number | string;
1514
};

0 commit comments

Comments
 (0)