Skip to content

Commit

Permalink
refactor: iOS Gallery refresh files change (#2298)
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal87 authored Nov 9, 2023
1 parent e7ec23e commit 512f9af
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
17 changes: 0 additions & 17 deletions package/expo-package/src/handlers/iOS14RefreshGallerySelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ import * as MediaLibrary from 'expo-media-library';

const isAboveIOS14 = Platform.OS === 'ios' && parseInt(Platform.Version as string, 10) >= 14;

export function oniOS14GalleryLibrarySelectionChange(callback: () => void): {
unsubscribe: () => void;
} {
if (isAboveIOS14) {
const subscription = MediaLibrary.addListener(callback);
return {
unsubscribe: () => {
subscription.remove();
},
};
}
return {
// eslint-disable-next-line @typescript-eslint/no-empty-function
unsubscribe: () => {},
};
}

export const iOS14RefreshGallerySelection = (): Promise<void> => {
if (isAboveIOS14) {
return MediaLibrary.presentPermissionsPickerAsync();
Expand Down
1 change: 1 addition & 0 deletions package/expo-package/src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './getLocalAssetUri';
export * from './getPhotos';
export * from './iOS14RefreshGallerySelection';
export * from './NetInfo';
export * from './oniOS14GalleryLibrarySelectionChange';
export * from './saveFile';
export * from './Sound';
export * from './takePhoto';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Platform } from 'react-native';

import * as MediaLibrary from 'expo-media-library';

const isAboveIOS14 = Platform.OS === 'ios' && parseInt(Platform.Version as string, 10) >= 14;

export function oniOS14GalleryLibrarySelectionChange(callback: () => void): {
unsubscribe: () => void;
} {
if (isAboveIOS14) {
const subscription = MediaLibrary.addListener(callback);
return {
unsubscribe: () => {
subscription.remove();
},
};
}
return {
// eslint-disable-next-line @typescript-eslint/no-empty-function
unsubscribe: () => {},
};
}

0 comments on commit 512f9af

Please sign in to comment.