motorinc-gallery-picker-pro 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,6 +58,7 @@ public class ImagePickerModule extends ReactContextBaseJavaModule {
58
58
  private static final String TAG = "ImagePickerModule";
59
59
  private static final int CAMERA_REQUEST_CODE = 1001;
60
60
  private static final int GALLERY_REQUEST_CODE = 1002;
61
+ private static final int PHOTO_PICKER_REQUEST_CODE = 1003;
61
62
  private static final int CAMERA_PERMISSION_REQUEST_CODE = 2001;
62
63
  private static final int STORAGE_PERMISSION_REQUEST_CODE = 2002;
63
64
 
@@ -163,15 +164,36 @@ public class ImagePickerModule extends ReactContextBaseJavaModule {
163
164
 
164
165
  @ReactMethod
165
166
  public void managePhotoSelection(Promise promise) {
166
- // This method allows users to update their selected photos in limited access mode
167
- if (Build.VERSION.SDK_INT >= 34 && isLimitedAccessMode()) {
168
- Log.d(TAG, "Opening photo selection management for limited access mode");
169
- // Re-request permissions to trigger the photo selection picker
170
- requestStoragePermissionInternal();
171
- promise.resolve(true);
167
+ Activity activity = getCurrentActivity();
168
+ if (activity == null) {
169
+ promise.reject("ACTIVITY_ERROR", "Activity is null");
170
+ return;
171
+ }
172
+
173
+ // Android 13+ (API 33+) supports the Photo Picker
174
+ if (Build.VERSION.SDK_INT >= 33) {
175
+ try {
176
+ Log.d(TAG, "Launching Android Photo Picker for photo selection management");
177
+
178
+ // Create intent to launch the system Photo Picker
179
+ Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
180
+
181
+ // Set multi-select mode with maximum limit
182
+ intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit());
183
+
184
+ // Store the promise to resolve after selection
185
+ currentPromise = promise;
186
+
187
+ // Launch the photo picker
188
+ activity.startActivityForResult(intent, PHOTO_PICKER_REQUEST_CODE);
189
+
190
+ } catch (Exception e) {
191
+ Log.e(TAG, "Error launching Photo Picker: " + e.getMessage());
192
+ promise.reject("PHOTO_PICKER_ERROR", "Failed to launch photo picker: " + e.getMessage());
193
+ }
172
194
  } else {
173
- Log.d(TAG, "Not in limited access mode or not Android 14+, opening app settings");
174
- // For non-limited mode or older Android, open app permission settings
195
+ // Android 12 and below - open app settings for permission management
196
+ Log.d(TAG, "Not Android 13+, opening app settings");
175
197
  try {
176
198
  Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
177
199
  intent.setData(android.net.Uri.parse("package:" + getReactApplicationContext().getPackageName()));
@@ -1098,6 +1120,9 @@ public class ImagePickerModule extends ReactContextBaseJavaModule {
1098
1120
  case GALLERY_REQUEST_CODE:
1099
1121
  handleGalleryResult(data);
1100
1122
  break;
1123
+ case PHOTO_PICKER_REQUEST_CODE:
1124
+ handlePhotoPickerResult(data);
1125
+ break;
1101
1126
  }
1102
1127
  } catch (Exception e) {
1103
1128
  rejectPromise("PROCESSING_ERROR", e.getMessage());
@@ -1139,6 +1164,34 @@ public class ImagePickerModule extends ReactContextBaseJavaModule {
1139
1164
  sendEvent("PhotoLibraryChanged");
1140
1165
  }
1141
1166
 
1167
+ private void handlePhotoPickerResult(Intent data) {
1168
+ try {
1169
+ Log.d(TAG, "Processing Photo Picker result");
1170
+
1171
+ // The Photo Picker was used to allow users to select additional photos
1172
+ // We don't need to return the selected URIs, just notify that the selection changed
1173
+ // and resolve the promise successfully
1174
+
1175
+ // Send event to notify React Native that photo library changed
1176
+ sendEvent("PhotoLibraryChanged");
1177
+
1178
+ // Resolve the promise
1179
+ if (currentPromise != null) {
1180
+ currentPromise.resolve(true);
1181
+ currentPromise = null;
1182
+ }
1183
+
1184
+ Log.d(TAG, "Photo Picker result processed successfully");
1185
+
1186
+ } catch (Exception e) {
1187
+ Log.e(TAG, "Error processing Photo Picker result: " + e.getMessage());
1188
+ if (currentPromise != null) {
1189
+ currentPromise.reject("PROCESSING_ERROR", "Error processing photo picker result: " + e.getMessage());
1190
+ currentPromise = null;
1191
+ }
1192
+ }
1193
+ }
1194
+
1142
1195
  private void copyUriToFile(Uri uri, File file) throws IOException {
1143
1196
  try (InputStream inputStream = getReactApplicationContext().getContentResolver().openInputStream(uri);
1144
1197
  FileOutputStream outputStream = new FileOutputStream(file)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motorinc-gallery-picker-pro",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "A comprehensive React Native media gallery picker with smooth animations, multi-select, single-select, crop functionality, and native iOS/Android support",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -35,6 +35,7 @@
35
35
  "react-native-view-shot": ">=4.0.0"
36
36
  },
37
37
  "dependencies": {
38
+ "motorinc-gallery-picker-pro": "^1.0.8",
38
39
  "motorinc-global-components": "^3.9.5",
39
40
  "react-native-worklets": "^0.4.1"
40
41
  },
@@ -651,7 +651,11 @@ const MainPhotoGallery = React.forwardRef<MainPhotoGalleryRef, props>(
651
651
  });
652
652
 
653
653
  if (reset) {
654
- setAssets(result.assets || []);
654
+ // When resetting, preserve picker assets by prepending them
655
+ const currentPickerAssets = assets.filter(asset =>
656
+ pickerAssetIds.has(asset.id)
657
+ );
658
+ setAssets([...currentPickerAssets, ...(result.assets || [])]);
655
659
  } else {
656
660
  setAssets(prev => [...prev, ...(result.assets || [])]);
657
661
  }
@@ -840,8 +844,7 @@ const MainPhotoGallery = React.forwardRef<MainPhotoGalleryRef, props>(
840
844
  console.log('📊 Total count:', totalCount);
841
845
 
842
846
  if (Platform.OS === 'ios') {
843
- // Check current permission status first
844
-
847
+ // iOS: Use the limited photo library picker
845
848
  const currentStatus =
846
849
  await ImagePickerModule.getPhotoLibraryPermissionStatus();
847
850
 
@@ -861,21 +864,21 @@ const MainPhotoGallery = React.forwardRef<MainPhotoGalleryRef, props>(
861
864
  const res = await ImagePickerModule.openPhotoLibraryLimitedPicker();
862
865
 
863
866
  console.log('✅ Limited photo picker opened successfully:', res);
867
+
868
+ // Refresh gallery after potential selection changes
869
+ setTimeout(() => {
870
+ console.log('� Refreshing gallery after photo selection changes');
871
+ handleRefresh();
872
+ }, 2000);
864
873
  } else {
865
- // Use the universal managePhotoSelection method available on both platforms
866
- console.log('🚀 Attempting to call managePhotoSelection...');
867
- const res = await ImagePickerModule.managePhotoSelection();
868
- console.log(
869
- '✅ Photo selection management opened successfully:',
870
- res,
871
- );
874
+ // Android: Use the multi-select image picker instead
875
+ console.log('🚀 Opening Android photo picker...');
876
+ await handleOpenImagePicker();
877
+ console.log('✅ Android photo picker flow completed');
878
+ // Note: handleOpenImagePicker already handles the selection and callback
879
+ // No need to refresh gallery as selected images are passed to onSelectedAssetsChange
880
+ return;
872
881
  }
873
-
874
- // Refresh gallery after potential selection changes
875
- setTimeout(() => {
876
- console.log('🔄 Refreshing gallery after photo selection changes');
877
- handleRefresh();
878
- }, 2000);
879
882
  } catch (error) {
880
883
  console.error('❌ Error managing photo selection:', error);
881
884